Skip to content

Instantly share code, notes, and snippets.

@CharlieHess
Created October 4, 2019 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlieHess/010f152702104c8edf5db49bd5de516e to your computer and use it in GitHub Desktop.
Save CharlieHess/010f152702104c8edf5db49bd5de516e to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
<!-- Empty -->
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
nativeWindowOpen: true,
preload: require.resolve('./renderer.js')
}
})
// and load the index.html of the app.
mainWindow.loadURL('https://app.slack.com')
// Open the DevTools.
mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
app.quit()
})
let picker
window.addEventListener('message', (evt) => {
if (evt.origin !== 'https://www.dropbox.com') return
if (!evt.data) return
console.log(evt.data)
const parsedData = JSON.parse(evt.data)
switch (parsedData.method) {
case 'files_selected':
case 'close_dialog':
picker.close()
}
})
window.addEventListener('DOMContentLoaded', () => {
picker = window.open('https://www.dropbox.com/chooser?origin=https%3A%2F%2Fapp.slack.com&app_key=hz986p4r827h6kt&link_type=preview&trigger=js&multiselect=true&extensions=&folderselect=false&iframe=false&version=2')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment