From 37fe523e8c1787a2913a3ba6fda7444063dd28b8 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Thu, 26 May 2022 14:17:44 -0400 Subject: [PATCH] Fix issue with changing servers and tabs (#2126) --- src/common/tabs/BaseTabView.ts | 2 +- src/main/views/MattermostView.ts | 8 +++++++- src/main/views/viewManager.test.js | 8 ++++++-- src/main/views/viewManager.ts | 12 +++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/common/tabs/BaseTabView.ts b/src/common/tabs/BaseTabView.ts index fc06da41..84a2b5dd 100644 --- a/src/common/tabs/BaseTabView.ts +++ b/src/common/tabs/BaseTabView.ts @@ -17,7 +17,7 @@ export default abstract class BaseTabView implements TabView { return getTabViewName(this.server.name, this.type); } get urlTypeTuple(): TabTuple { - return tuple(this.url.href, this.type) as TabTuple; + return tuple(this.server.url.href, this.type) as TabTuple; } get url(): URL { throw new Error('Not implemented'); diff --git a/src/main/views/MattermostView.ts b/src/main/views/MattermostView.ts index 929b11d7..c8e27b9a 100644 --- a/src/main/views/MattermostView.ts +++ b/src/main/views/MattermostView.ts @@ -21,7 +21,7 @@ import { SET_VIEW_OPTIONS, LOADSCREEN_END, } from 'common/communication'; - +import {MattermostServer} from 'common/servers/MattermostServer'; import {TabView, TabTuple} from 'common/tabs/TabView'; import {ServerInfo} from 'main/server/serverInfo'; @@ -140,6 +140,12 @@ export class MattermostView extends EventEmitter { return this.tab.urlTypeTuple; } + updateServerInfo = (srv: MattermostServer) => { + this.tab.server = srv; + this.serverInfo = new ServerInfo(srv); + this.view.webContents.send(SET_VIEW_OPTIONS, this.tab.name, this.tab.shouldNotify); + } + resetLoadingStatus = () => { if (this.status !== Status.LOADING) { // if it's already loading, don't touch anything delete this.retryLoad; diff --git a/src/main/views/viewManager.test.js b/src/main/views/viewManager.test.js index 9bd03d54..ce3c5dbf 100644 --- a/src/main/views/viewManager.test.js +++ b/src/main/views/viewManager.test.js @@ -199,6 +199,7 @@ describe('main/views/viewManager', () => { destroy: destroyFn, name: tab.name, urlTypeTuple: tab.urlTypeTuple, + updateServerInfo: jest.fn(), tab, })); }); @@ -288,11 +289,15 @@ describe('main/views/viewManager', () => { const view = { name: 'server1-tab1', tab: { + server: { + name: 'server-1', + }, name: 'server1-tab1', url: new URL('http://server1.com'), }, urlTypeTuple: tuple('http://server1.com/', 'tab1'), destroy: jest.fn(), + updateServerInfo: jest.fn(), }; viewManager.currentView = 'server1-tab1'; viewManager.views.set('server1-tab1', view); @@ -310,7 +315,6 @@ describe('main/views/viewManager', () => { }, ]); expect(viewManager.showByName).toHaveBeenCalledWith('server1-tab1'); - expect(viewManager.mainWindow.webContents.send).not.toHaveBeenCalled(); }); it('should show initial if currentView has been removed', () => { @@ -322,6 +326,7 @@ describe('main/views/viewManager', () => { }, urlTypeTuple: ['http://server.com/', 'tab1'], destroy: jest.fn(), + updateServerInfo: jest.fn(), }; viewManager.currentView = 'server1-tab1'; viewManager.views.set('server1-tab1', view); @@ -338,7 +343,6 @@ describe('main/views/viewManager', () => { ], }, ]); - expect(viewManager.currentView).toBeUndefined(); expect(viewManager.showInitial).toBeCalled(); }); diff --git a/src/main/views/viewManager.ts b/src/main/views/viewManager.ts index 2ce193ae..630935f0 100644 --- a/src/main/views/viewManager.ts +++ b/src/main/views/viewManager.ts @@ -150,8 +150,7 @@ export class ViewManager { if (!tab.isOpen) { closed.set(tabTuple, {srv, tab, name: view.name}); } else if (recycle) { - recycle.serverInfo = info; - recycle.tab.server = srv; + recycle.updateServerInfo(srv); views.set(tabTuple, recycle); } else { views.set(tabTuple, this.makeView(srv, info, tab, tabTuple[0])); @@ -177,7 +176,7 @@ export class ViewManager { this.closedViews.set(x.name, {srv: x.srv, tab: x.tab}); } - if (focusedTuple && (current.has(focusedTuple) || closed.has(focusedTuple))) { + if ((focusedTuple && closed.has(focusedTuple)) || (this.currentView && this.closedViews.has(this.currentView))) { if (configServers.length) { delete this.currentView; this.showInitial(); @@ -189,8 +188,11 @@ export class ViewManager { // show the focused tab (or initial) if (focusedTuple && views.has(focusedTuple)) { const view = views.get(focusedTuple); - this.currentView = view!.name; - this.showByName(view!.name); + if (view) { + this.currentView = view.name; + this.showByName(view.name); + this.mainWindow.webContents.send(SET_ACTIVE_VIEW, view.tab.server.name, view.tab.type); + } } else { this.showInitial(); }