Fix for #302
On Mac, a download in desktop app defaulted to Macintosh HD instead of the download folder
This commit is contained in:
parent
dc870ba125
commit
26689f0a51
19
src/main.js
19
src/main.js
|
@ -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,22 @@ 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.');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue