mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
electron-205: implemented logic to support setting downloads directory
This commit is contained in:
parent
afbb37ea95
commit
b9f53f3e8f
@ -74,7 +74,8 @@ const template = [{
|
||||
properties: ['openDirectory', 'createDirectory']
|
||||
}, (filePaths) => {
|
||||
updateConfigField('downloadsDirectory', filePaths[0]);
|
||||
})
|
||||
eventEmitter.emit('setDownloadsDirectory', filePaths[0]);
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const electron = require('electron');
|
||||
const app = electron.app;
|
||||
const crashReporter = electron.crashReporter;
|
||||
@ -37,6 +38,19 @@ let position = 'lower-right';
|
||||
let display;
|
||||
let sandboxed = false;
|
||||
|
||||
let downloadsDirectory;
|
||||
|
||||
getConfigField('downloadsDirectory')
|
||||
.then((value) => {
|
||||
downloadsDirectory = value;
|
||||
if (!fs.existsSync(downloadsDirectory)) {
|
||||
fs.mkdirSync(downloadsDirectory);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
log.send(logLevels.ERROR, 'Could not find the downloads directory config -> ' + error);
|
||||
});
|
||||
|
||||
// note: this file is built using browserify in prebuild step.
|
||||
const preloadMainScript = path.join(__dirname, 'preload/_preloadMain.js');
|
||||
|
||||
@ -241,7 +255,11 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
||||
mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
|
||||
// When download is in progress, send necessary data to indicate the same
|
||||
webContents.send('downloadProgress');
|
||||
|
||||
|
||||
if (downloadsDirectory) {
|
||||
item.setSavePath(downloadsDirectory + "/" + item.getFilename());
|
||||
}
|
||||
|
||||
// Send file path when download is complete
|
||||
item.once('done', (e, state) => {
|
||||
if (state === 'completed') {
|
||||
@ -598,6 +616,11 @@ eventEmitter.on('isAlwaysOnTop', (boolean) => {
|
||||
isAlwaysOnTop(boolean);
|
||||
});
|
||||
|
||||
// set downloads directory
|
||||
eventEmitter.on('setDownloadsDirectory', (newDirectory) => {
|
||||
downloadsDirectory = newDirectory;
|
||||
});
|
||||
|
||||
// node event emitter for notification settings
|
||||
eventEmitter.on('notificationSettings', (notificationSettings) => {
|
||||
position = notificationSettings.position;
|
||||
|
Loading…
Reference in New Issue
Block a user