fix crash on invalid download paths (#1662)

Co-authored-by: = <=>
This commit is contained in:
Guillermo Vayá
2021-07-19 17:26:37 +02:00
committed by GitHub
parent e71c4ff9f0
commit ccd515e50c
2 changed files with 10 additions and 10 deletions

View File

@@ -2,6 +2,9 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import path from 'path';
import os from 'os';
/** /**
* Default user preferences. End-users can change these parameters by editing config.json * Default user preferences. End-users can change these parameters by editing config.json
* @param {number} version - Scheme version. (Not application version) * @param {number} version - Scheme version. (Not application version)
@@ -9,15 +12,8 @@
import {ConfigV2} from 'types/config'; import {ConfigV2} from 'types/config';
export const getDefaultDownloadLocation = () => { export const getDefaultDownloadLocation = (): string => {
switch (process.platform) { return path.join(os.homedir(), 'Downloads');
case 'darwin':
return `/Users/${process.env.USER || process.env.USERNAME}/Downloads`;
case 'win32':
return `C:\\Users\\${process.env.USER || process.env.USERNAME}\\Downloads`;
default:
return `/home/${process.env.USER || process.env.USERNAME}/Downloads`;
}
}; };
const defaultPreferences: ConfigV2 = { const defaultPreferences: ConfigV2 = {

View File

@@ -282,7 +282,11 @@ function handleConfigSynchronize() {
WindowManager.setConfig(config.data); WindowManager.setConfig(config.data);
setUnreadBadgeSetting(config.data.showUnreadBadge); setUnreadBadgeSetting(config.data.showUnreadBadge);
if (config.data.downloadLocation) { if (config.data.downloadLocation) {
try {
app.setPath('downloads', config.data.downloadLocation); app.setPath('downloads', config.data.downloadLocation);
} catch (e) {
log.error(`There was a problem trying to set the default download path: ${e}`);
}
} }
if (app.isReady()) { if (app.isReady()) {
WindowManager.sendToRenderer(RELOAD_CONFIGURATION); WindowManager.sendToRenderer(RELOAD_CONFIGURATION);