[MM-23452][MM-36861] Fixed some configuration issues (#1725)
* [MM-23452] Show last used server and tab correctly when restarting the app * [MM-36861] Ensure handleConfigUpdate runs
This commit is contained in:
@@ -122,6 +122,7 @@ const configDataSchemaV3 = Joi.object<ConfigV3>({
|
||||
spellCheckerURL: Joi.string().allow(null),
|
||||
darkMode: Joi.boolean().default(false),
|
||||
downloadLocation: Joi.string(),
|
||||
lastActiveTeam: Joi.number().integer().min(0).default(0),
|
||||
});
|
||||
|
||||
// eg. data['community.mattermost.com'] = { data: 'certificate data', issuerName: 'COMODO RSA Domain Validation Secure Server CA'};
|
||||
|
@@ -13,7 +13,7 @@ import installExtension, {REACT_DEVELOPER_TOOLS} from 'electron-devtools-install
|
||||
import log from 'electron-log';
|
||||
import 'airbnb-js-shims/target/es2015';
|
||||
|
||||
import {Team, TeamWithTabs} from 'types/config';
|
||||
import {CombinedConfig, Team, TeamWithTabs} from 'types/config';
|
||||
import {MentionData} from 'types/notification';
|
||||
import {RemoteInfo} from 'types/server';
|
||||
import {Boundaries} from 'types/utils';
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
SHOW_REMOVE_SERVER_MODAL,
|
||||
UPDATE_SHORTCUT_MENU,
|
||||
OPEN_TEAMS_DROPDOWN,
|
||||
SET_ACTIVE_VIEW,
|
||||
UPDATE_LAST_ACTIVE,
|
||||
} from 'common/communication';
|
||||
import Config from 'common/config';
|
||||
import {MattermostServer} from 'common/servers/MattermostServer';
|
||||
@@ -242,7 +242,7 @@ function initializeInterCommunicationEventListeners() {
|
||||
ipcMain.on('update-menu', handleUpdateMenuEvent);
|
||||
ipcMain.on(UPDATE_SHORTCUT_MENU, handleUpdateShortcutMenuEvent);
|
||||
ipcMain.on(FOCUS_BROWSERVIEW, WindowManager.focusBrowserView);
|
||||
ipcMain.on(SET_ACTIVE_VIEW, handleUpdateLastActiveTab);
|
||||
ipcMain.on(UPDATE_LAST_ACTIVE, handleUpdateLastActive);
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
ipcMain.on('open-app-menu', handleOpenAppMenu);
|
||||
@@ -272,8 +272,8 @@ function initializeInterCommunicationEventListeners() {
|
||||
// config event handlers
|
||||
//
|
||||
|
||||
function handleConfigUpdate(newConfig: Config) {
|
||||
if (!newConfig.data) {
|
||||
function handleConfigUpdate(newConfig: CombinedConfig) {
|
||||
if (!newConfig) {
|
||||
return;
|
||||
}
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
@@ -284,13 +284,15 @@ function handleConfigUpdate(newConfig: Config) {
|
||||
}).catch((err) => {
|
||||
log.error('error:', err);
|
||||
});
|
||||
WindowManager.setConfig(newConfig.data);
|
||||
authManager.handleConfigUpdate(newConfig.data);
|
||||
setUnreadBadgeSetting(newConfig.data && newConfig.data.showUnreadBadge);
|
||||
WindowManager.setConfig(newConfig);
|
||||
if (authManager) {
|
||||
authManager.handleConfigUpdate(newConfig);
|
||||
}
|
||||
setUnreadBadgeSetting(newConfig && newConfig.showUnreadBadge);
|
||||
}
|
||||
|
||||
ipcMain.emit('update-menu', true, config);
|
||||
ipcMain.emit(EMIT_CONFIGURATION, true, newConfig.data);
|
||||
ipcMain.emit(EMIT_CONFIGURATION, true, newConfig);
|
||||
}
|
||||
|
||||
function handleConfigSynchronize() {
|
||||
@@ -318,9 +320,6 @@ function handleConfigSynchronize() {
|
||||
handleNewServerModal();
|
||||
}
|
||||
}
|
||||
|
||||
ipcMain.emit('update-menu', true, config);
|
||||
ipcMain.emit(EMIT_CONFIGURATION, true, config.data);
|
||||
}
|
||||
|
||||
function handleReloadConfig() {
|
||||
@@ -950,14 +949,15 @@ function resizeScreen(browserWindow: BrowserWindow) {
|
||||
browserWindow.on('restore', handle);
|
||||
handle();
|
||||
}
|
||||
function handleUpdateLastActiveTab(event: IpcMainEvent, serverName: string, viewName: string) {
|
||||
function handleUpdateLastActive(event: IpcMainEvent, serverName: string, viewName: string) {
|
||||
const teams = config.teams;
|
||||
teams.forEach((team) => {
|
||||
if (team.name === serverName) {
|
||||
const viewIndex = team?.tabs.findIndex((tab) => tab.name === viewName);
|
||||
team.lastActiveTab = viewIndex;
|
||||
const viewOrder = team?.tabs.find((tab) => tab.name === viewName)?.order || 0;
|
||||
team.lastActiveTab = viewOrder;
|
||||
}
|
||||
});
|
||||
config.set('teams', teams);
|
||||
config.set('lastActiveTeam', teams.find((team) => team.name === serverName)?.order || 0);
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,7 @@ import {
|
||||
LOADSCREEN_END,
|
||||
SET_ACTIVE_VIEW,
|
||||
OPEN_TAB,
|
||||
UPDATE_LAST_ACTIVE,
|
||||
} from 'common/communication';
|
||||
import urlUtils from 'common/utils/url';
|
||||
|
||||
@@ -33,6 +34,7 @@ const URL_VIEW_HEIGHT = 36;
|
||||
|
||||
export class ViewManager {
|
||||
configServers: TeamWithTabs[];
|
||||
lastActiveServer?: number;
|
||||
viewOptions: BrowserViewConstructorOptions;
|
||||
closedViews: Map<string, {srv: MattermostServer; tab: Tab}>;
|
||||
views: Map<string, MattermostView>;
|
||||
@@ -44,6 +46,7 @@ export class ViewManager {
|
||||
|
||||
constructor(config: CombinedConfig, mainWindow: BrowserWindow) {
|
||||
this.configServers = config.teams;
|
||||
this.lastActiveServer = config.lastActiveTeam;
|
||||
this.viewOptions = {webPreferences: {spellcheck: config.useSpellChecker}};
|
||||
this.views = new Map(); // keep in mind that this doesn't need to hold server order, only tabs on the renderer need that.
|
||||
this.mainWindow = mainWindow;
|
||||
@@ -121,10 +124,13 @@ export class ViewManager {
|
||||
|
||||
showInitial = () => {
|
||||
if (this.configServers.length) {
|
||||
const element = this.configServers.find((e) => e.order === 0);
|
||||
if (element) {
|
||||
const openTabs = element.tabs.filter((tab) => !tab.isClosed);
|
||||
const tab = openTabs.find((e) => e.order === 0) || openTabs[0];
|
||||
const element = this.configServers.find((e) => e.order === this.lastActiveServer || 0);
|
||||
if (element && element.tabs.length) {
|
||||
let tab = element.tabs.find((tab) => tab.order === element.lastActiveTab || 0);
|
||||
if (tab?.isClosed) {
|
||||
const openTabs = element.tabs.filter((tab) => !tab.isClosed);
|
||||
tab = openTabs.find((e) => e.order === 0) || openTabs[0];
|
||||
}
|
||||
if (tab) {
|
||||
const tabView = getTabViewName(element.name, tab.name);
|
||||
this.showByName(tabView);
|
||||
@@ -155,6 +161,7 @@ export class ViewManager {
|
||||
if (newView.isReady()) {
|
||||
// if view is not ready, the renderer will have something to display instead.
|
||||
newView.show();
|
||||
ipcMain.emit(UPDATE_LAST_ACTIVE, true, newView.tab.server.name, newView.tab.type);
|
||||
if (newView.needsLoadingScreen()) {
|
||||
this.showLoadingScreen();
|
||||
} else {
|
||||
|
@@ -363,7 +363,7 @@ export function switchServer(serverName: string) {
|
||||
return;
|
||||
}
|
||||
status.currentServerName = serverName;
|
||||
const lastActiveTab = server.tabs[server.lastActiveTab || 0];
|
||||
const lastActiveTab = server.tabs.find((tab) => !tab.isClosed && tab.order === (server.lastActiveTab || 0)) || server.tabs[0];
|
||||
const tabViewName = getTabViewName(serverName, lastActiveTab.name);
|
||||
status.viewManager?.showByName(tabViewName);
|
||||
ipcMain.emit(UPDATE_SHORTCUT_MENU);
|
||||
@@ -544,7 +544,7 @@ function handleBrowserHistoryPush(e: IpcMainEvent, viewName: string, pathName: s
|
||||
status.viewManager.openClosedTab(redirectedViewName, `${currentView?.tab.server.url}${pathName}`);
|
||||
}
|
||||
const redirectedView = status.viewManager?.views.get(redirectedViewName) || currentView;
|
||||
if (redirectedView !== currentView) {
|
||||
if (redirectedView !== currentView && redirectedView?.tab.server.name === status.currentServerName) {
|
||||
log.info('redirecting to a new view', redirectedView?.name || viewName);
|
||||
status.viewManager?.showByName(redirectedView?.name || viewName);
|
||||
}
|
||||
|
Reference in New Issue
Block a user