mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-30 12:43:59 -06:00
Merge pull request #238 from VishwasShashidhar/electron-205
Electron 205 - Allow user to set Downloads folder through Menu dropdown
This commit is contained in:
commit
59658c819c
@ -65,7 +65,23 @@ const template = [{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Open Crashes Directory',
|
label: 'Set Downloads Directory',
|
||||||
|
click() {
|
||||||
|
electron.dialog.showOpenDialog({
|
||||||
|
title: 'Select Downloads Directory',
|
||||||
|
buttonLabel: 'Select',
|
||||||
|
properties: ['openDirectory', 'createDirectory']
|
||||||
|
}, (filePaths) => {
|
||||||
|
if (!filePaths || !Array.isArray(filePaths) || filePaths.length < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateConfigField('downloadsDirectory', filePaths[0]);
|
||||||
|
eventEmitter.emit('setDownloadsDirectory', filePaths[0]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Open Crashes Directory',
|
||||||
click() {
|
click() {
|
||||||
const crashesDirectory = electron.crashReporter.getCrashesDirectory() + '/completed';
|
const crashesDirectory = electron.crashReporter.getCrashesDirectory() + '/completed';
|
||||||
electron.shell.showItemInFolder(crashesDirectory);
|
electron.shell.showItemInFolder(crashesDirectory);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
const crashReporter = electron.crashReporter;
|
const crashReporter = electron.crashReporter;
|
||||||
@ -36,6 +37,7 @@ let alwaysOnTop = false;
|
|||||||
let position = 'lower-right';
|
let position = 'lower-right';
|
||||||
let display;
|
let display;
|
||||||
let sandboxed = false;
|
let sandboxed = false;
|
||||||
|
let downloadsDirectory;
|
||||||
|
|
||||||
// note: this file is built using browserify in prebuild step.
|
// note: this file is built using browserify in prebuild step.
|
||||||
const preloadMainScript = path.join(__dirname, 'preload/_preloadMain.js');
|
const preloadMainScript = path.join(__dirname, 'preload/_preloadMain.js');
|
||||||
@ -236,12 +238,37 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.on('closed', destroyAllWindows);
|
mainWindow.on('closed', destroyAllWindows);
|
||||||
|
|
||||||
|
// if an user has set a custom downloads directory,
|
||||||
|
// we get that data from the user config file
|
||||||
|
getConfigField('downloadsDirectory')
|
||||||
|
.then((value) => {
|
||||||
|
downloadsDirectory = value;
|
||||||
|
// if the directory has been deleted, try creating it.
|
||||||
|
if (!fs.existsSync(downloadsDirectory)) {
|
||||||
|
const directoryCreated = fs.mkdirSync(downloadsDirectory);
|
||||||
|
// If the directory creation failed, we use the default downloads directory
|
||||||
|
if (!directoryCreated) {
|
||||||
|
downloadsDirectory = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
log.send(logLevels.ERROR, 'Could not find the downloads directory config -> ' + error);
|
||||||
|
});
|
||||||
|
|
||||||
// Manage File Downloads
|
// Manage File Downloads
|
||||||
mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
|
mainWindow.webContents.session.on('will-download', (event, item, webContents) => {
|
||||||
|
|
||||||
// When download is in progress, send necessary data to indicate the same
|
// When download is in progress, send necessary data to indicate the same
|
||||||
webContents.send('downloadProgress');
|
webContents.send('downloadProgress');
|
||||||
|
|
||||||
|
// if the user has set a custom downloads directory, save file to that directory
|
||||||
|
// if otherwise, we save it to the operating system's default downloads directory
|
||||||
|
if (downloadsDirectory) {
|
||||||
|
item.setSavePath(downloadsDirectory + "/" + item.getFilename());
|
||||||
|
}
|
||||||
|
|
||||||
// Send file path when download is complete
|
// Send file path when download is complete
|
||||||
item.once('done', (e, state) => {
|
item.once('done', (e, state) => {
|
||||||
if (state === 'completed') {
|
if (state === 'completed') {
|
||||||
@ -605,6 +632,11 @@ eventEmitter.on('isAlwaysOnTop', (boolean) => {
|
|||||||
isAlwaysOnTop(boolean);
|
isAlwaysOnTop(boolean);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// set downloads directory
|
||||||
|
eventEmitter.on('setDownloadsDirectory', (newDirectory) => {
|
||||||
|
downloadsDirectory = newDirectory;
|
||||||
|
});
|
||||||
|
|
||||||
// node event emitter for notification settings
|
// node event emitter for notification settings
|
||||||
eventEmitter.on('notificationSettings', (notificationSettings) => {
|
eventEmitter.on('notificationSettings', (notificationSettings) => {
|
||||||
position = notificationSettings.position;
|
position = notificationSettings.position;
|
||||||
|
Loading…
Reference in New Issue
Block a user