Skip to content

Instantly share code, notes, and snippets.

@CharlieHess
Created September 30, 2019 19:41
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/89f240d79bef664ea61e47b3885cc601 to your computer and use it in GitHub Desktop.
Save CharlieHess/89f240d79bef664ea61e47b3885cc601 to your computer and use it in GitHub Desktop.
nativeWindowOpen + Dropbox chooser
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
app.allowRendererProcessReuse = true
// 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.loadFile('index.html')
// 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()
})
window.addEventListener('message', (evt) => {
console.log(evt.data)
})
window.addEventListener('DOMContentLoaded', () => {
if (document.location.href.startsWith('file:')) {
const button = document.createElement("input")
button.type = "button"
button.value = "Open Picker"
button.onclick = () => window.open('https://www.dropbox.com/chooser?&link_type=preview&trigger=js&multiselect=true&extensions=&folderselect=false&iframe=false&version=2')
document.body.appendChild(button)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment