Merge pull request #330 from magicmonty/issue_302
Issue 302: Download desktop app download folder, instead of defaulting to Macintosh HD Close #302
This commit is contained in:
commit
a55bbf48fb
20
src/main.js
20
src/main.js
|
@ -8,7 +8,8 @@ const {
|
|||
ipcMain,
|
||||
nativeImage,
|
||||
dialog,
|
||||
systemPreferences
|
||||
systemPreferences,
|
||||
session
|
||||
} = require('electron');
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
|
@ -375,6 +376,23 @@ app.on('ready', function() {
|
|||
window_options.title = app.getName();
|
||||
mainWindow = new BrowserWindow(window_options);
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
session.defaultSession.on('will-download', (event, item, webContents) => {
|
||||
var filename = item.getFilename();
|
||||
var savePath = dialog.showSaveDialog({
|
||||
title: filename,
|
||||
defaultPath: require('os').homedir() + '/Downloads/' + filename
|
||||
});
|
||||
|
||||
if (savePath) {
|
||||
item.setSavePath(savePath);
|
||||
}
|
||||
else {
|
||||
item.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mainWindow.webContents.on('crashed', () => {
|
||||
console.log('The application has crashed.');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue