[MM-40406] Add more singletons, refactor main.ts into pieces, add tests and some cleanup + tests for additional coverage (#1890)
* Refactor main.ts dependencies into singleton pattern * Split main.ts into testable pieces, some other refactoring for singleton pattern * Unit tests for main/app/app * Unit tests for main/app/config * Unit tests for main/app/initialize * Unit tests for main/app/intercom * Unit tests for main/app/utils * Add some more tests to get to 70% coverage * Fix for linux * Fix for alternate data dir paths * Fix E2E test
This commit is contained in:
75
src/main/app/config.ts
Normal file
75
src/main/app/config.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {app, ipcMain} from 'electron';
|
||||
import log from 'electron-log';
|
||||
|
||||
import {CombinedConfig} from 'types/config';
|
||||
|
||||
import {DARK_MODE_CHANGE, EMIT_CONFIGURATION, RELOAD_CONFIGURATION} from 'common/communication';
|
||||
import Config from 'common/config';
|
||||
|
||||
import AutoLauncher from 'main/AutoLauncher';
|
||||
import {setUnreadBadgeSetting} from 'main/badge';
|
||||
import {refreshTrayImages} from 'main/tray/tray';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
|
||||
import {handleNewServerModal} from './intercom';
|
||||
import {handleUpdateMenuEvent, updateServerInfos, updateSpellCheckerLocales} from './utils';
|
||||
|
||||
let didCheckForAddServerModal = false;
|
||||
|
||||
//
|
||||
// config event handlers
|
||||
//
|
||||
|
||||
export function handleConfigUpdate(newConfig: CombinedConfig) {
|
||||
if (!newConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
WindowManager.handleUpdateConfig();
|
||||
if (app.isReady()) {
|
||||
WindowManager.sendToRenderer(RELOAD_CONFIGURATION);
|
||||
}
|
||||
|
||||
setUnreadBadgeSetting(newConfig && newConfig.showUnreadBadge);
|
||||
updateSpellCheckerLocales();
|
||||
|
||||
if (newConfig.downloadLocation) {
|
||||
try {
|
||||
app.setPath('downloads', newConfig.downloadLocation);
|
||||
} catch (e) {
|
||||
log.error(`There was a problem trying to set the default download path: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
const autoStartTask = newConfig.autostart ? AutoLauncher.enable() : AutoLauncher.disable();
|
||||
autoStartTask.then(() => {
|
||||
log.info('config.autostart has been configured:', newConfig.autostart);
|
||||
}).catch((err) => {
|
||||
log.error('error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' && !didCheckForAddServerModal && typeof Config.registryConfigData !== 'undefined') {
|
||||
didCheckForAddServerModal = true;
|
||||
updateServerInfos(newConfig.teams);
|
||||
WindowManager.initializeCurrentServerName();
|
||||
if (newConfig.teams.length === 0) {
|
||||
handleNewServerModal();
|
||||
}
|
||||
}
|
||||
|
||||
handleUpdateMenuEvent();
|
||||
ipcMain.emit(EMIT_CONFIGURATION, true, newConfig);
|
||||
}
|
||||
|
||||
export function handleDarkModeChange(darkMode: boolean) {
|
||||
refreshTrayImages(Config.trayIconTheme);
|
||||
WindowManager.sendToRenderer(DARK_MODE_CHANGE, darkMode);
|
||||
WindowManager.updateLoadingScreenDarkMode(darkMode);
|
||||
|
||||
ipcMain.emit(EMIT_CONFIGURATION, true, Config.data);
|
||||
}
|
Reference in New Issue
Block a user