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:
Yuya Ochiai 2016-10-07 20:25:30 +09:00 committed by GitHub
commit a55bbf48fb

View file

@ -8,7 +8,8 @@ const {
ipcMain, ipcMain,
nativeImage, nativeImage,
dialog, dialog,
systemPreferences systemPreferences,
session
} = require('electron'); } = require('electron');
process.on('uncaughtException', (error) => { process.on('uncaughtException', (error) => {
@ -375,6 +376,23 @@ app.on('ready', function() {
window_options.title = app.getName(); window_options.title = app.getName();
mainWindow = new BrowserWindow(window_options); 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', () => { mainWindow.webContents.on('crashed', () => {
console.log('The application has crashed.'); console.log('The application has crashed.');
}); });