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.
// 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
* @param {number} version - Scheme version. (Not application version)
@@ -9,15 +12,8 @@
import {ConfigV2} from 'types/config';
export const getDefaultDownloadLocation = () => {
switch (process.platform) {
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`;
}
export const getDefaultDownloadLocation = (): string => {
return path.join(os.homedir(), 'Downloads');
};
const defaultPreferences: ConfigV2 = {

View File

@@ -282,7 +282,11 @@ function handleConfigSynchronize() {
WindowManager.setConfig(config.data);
setUnreadBadgeSetting(config.data.showUnreadBadge);
if (config.data.downloadLocation) {
try {
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()) {
WindowManager.sendToRenderer(RELOAD_CONFIGURATION);