Skip to content

Instantly share code, notes, and snippets.

@ngehlert ngehlert/electron.js
Last active Nov 9, 2019

Embed
What would you like to do?
Show open dialog with security scoped bookmarks and access them
const settings = require('electron-settings');
dialog
.showOpenDialog(mainWindow, {
properties: ['openDirectory'],
securityScopedBookmarks: true,
})
.then(({ canceled, filePaths, bookmarks }) => {
// If the dialog was canceled or no directory/file selected we don't want to do anything
if (canceled || filePaths.length === 0) {
return;
}
if (bookmarks && bookmarks.length) {
// store the bookmark key
settings.set('security-scoped-bookmark', bookmarks[0]);
}
// do something with the file path, e.g. send to your application
const [directory] = filePaths;
mainWindow.webContents.send('new-directory', directory);
})
///////////////////
// access security scope bookmark
const { app } = require('electron');
const settings = require('electron-settings');
const securityBookmark = settings.get('security-scoped-bookmark');
if (securityBookmark) {
app.startAccessingSecurityScopedResource(securityBookmark);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.