[MM-38275] Use browser history push for deeplinking and other inter-tab navigation when using a v6.0 server (#1726)
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
|||||||
|
|
||||||
import {TabView} from 'common/tabs/TabView';
|
import {TabView} from 'common/tabs/TabView';
|
||||||
|
|
||||||
|
import {ServerInfo} from 'main/server/serverInfo';
|
||||||
import ContextMenu from '../contextMenu';
|
import ContextMenu from '../contextMenu';
|
||||||
import {getWindowBoundaries, getLocalPreload, composeUserAgent} from '../utils';
|
import {getWindowBoundaries, getLocalPreload, composeUserAgent} from '../utils';
|
||||||
import * as WindowManager from '../windows/windowManager';
|
import * as WindowManager from '../windows/windowManager';
|
||||||
@@ -31,7 +32,7 @@ import * as appState from '../appState';
|
|||||||
|
|
||||||
import {removeWebContentsListeners} from './webContentEvents';
|
import {removeWebContentsListeners} from './webContentEvents';
|
||||||
|
|
||||||
enum Status {
|
export enum Status {
|
||||||
LOADING,
|
LOADING,
|
||||||
READY,
|
READY,
|
||||||
WAITING_MM,
|
WAITING_MM,
|
||||||
@@ -47,6 +48,7 @@ export class MattermostView extends EventEmitter {
|
|||||||
view: BrowserView;
|
view: BrowserView;
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
options: BrowserViewConstructorOptions;
|
options: BrowserViewConstructorOptions;
|
||||||
|
serverInfo: ServerInfo;
|
||||||
|
|
||||||
removeLoading?: number;
|
removeLoading?: number;
|
||||||
|
|
||||||
@@ -65,10 +67,11 @@ export class MattermostView extends EventEmitter {
|
|||||||
retryLoad?: NodeJS.Timeout;
|
retryLoad?: NodeJS.Timeout;
|
||||||
maxRetries: number;
|
maxRetries: number;
|
||||||
|
|
||||||
constructor(tab: TabView, win: BrowserWindow, options: BrowserViewConstructorOptions) {
|
constructor(tab: TabView, serverInfo: ServerInfo, win: BrowserWindow, options: BrowserViewConstructorOptions) {
|
||||||
super();
|
super();
|
||||||
this.tab = tab;
|
this.tab = tab;
|
||||||
this.window = win;
|
this.window = win;
|
||||||
|
this.serverInfo = serverInfo;
|
||||||
|
|
||||||
const preload = getLocalPreload('preload.js');
|
const preload = getLocalPreload('preload.js');
|
||||||
this.options = Object.assign({}, options);
|
this.options = Object.assign({}, options);
|
||||||
|
@@ -16,16 +16,19 @@ import {
|
|||||||
LOADSCREEN_END,
|
LOADSCREEN_END,
|
||||||
SET_ACTIVE_VIEW,
|
SET_ACTIVE_VIEW,
|
||||||
OPEN_TAB,
|
OPEN_TAB,
|
||||||
|
BROWSER_HISTORY_PUSH,
|
||||||
UPDATE_LAST_ACTIVE,
|
UPDATE_LAST_ACTIVE,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
import urlUtils from 'common/utils/url';
|
import urlUtils from 'common/utils/url';
|
||||||
|
import {isServerVersionGreaterThanOrEqualTo} from 'common/utils/util';
|
||||||
|
|
||||||
import {getServerView, getTabViewName} from 'common/tabs/TabView';
|
import {getServerView, getTabViewName} from 'common/tabs/TabView';
|
||||||
|
|
||||||
|
import {ServerInfo} from 'main/server/serverInfo';
|
||||||
import {MattermostServer} from '../../common/servers/MattermostServer';
|
import {MattermostServer} from '../../common/servers/MattermostServer';
|
||||||
import {getLocalURLString, getLocalPreload, getWindowBoundaries} from '../utils';
|
import {getLocalURLString, getLocalPreload, getWindowBoundaries} from '../utils';
|
||||||
|
|
||||||
import {MattermostView} from './MattermostView';
|
import {MattermostView, Status} from './MattermostView';
|
||||||
import {showModal, isModalDisplayed, focusCurrentModal} from './modalManager';
|
import {showModal, isModalDisplayed, focusCurrentModal} from './modalManager';
|
||||||
import {addWebContentsEventListeners} from './webContentEvents';
|
import {addWebContentsEventListeners} from './webContentEvents';
|
||||||
|
|
||||||
@@ -63,16 +66,17 @@ export class ViewManager {
|
|||||||
|
|
||||||
loadServer = (server: TeamWithTabs) => {
|
loadServer = (server: TeamWithTabs) => {
|
||||||
const srv = new MattermostServer(server.name, server.url);
|
const srv = new MattermostServer(server.name, server.url);
|
||||||
server.tabs.forEach((tab) => this.loadView(srv, tab));
|
const serverInfo = new ServerInfo(srv);
|
||||||
|
server.tabs.forEach((tab) => this.loadView(srv, serverInfo, tab));
|
||||||
}
|
}
|
||||||
|
|
||||||
loadView = (srv: MattermostServer, tab: Tab, url?: string) => {
|
loadView = (srv: MattermostServer, serverInfo: ServerInfo, tab: Tab, url?: string) => {
|
||||||
const tabView = getServerView(srv, tab);
|
const tabView = getServerView(srv, tab);
|
||||||
if (tab.isClosed) {
|
if (tab.isClosed) {
|
||||||
this.closedViews.set(tabView.name, {srv, tab});
|
this.closedViews.set(tabView.name, {srv, tab});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const view = new MattermostView(tabView, this.mainWindow, this.viewOptions);
|
const view = new MattermostView(tabView, serverInfo, this.mainWindow, this.viewOptions);
|
||||||
this.views.set(tabView.name, view);
|
this.views.set(tabView.name, view);
|
||||||
if (!this.loadingScreen) {
|
if (!this.loadingScreen) {
|
||||||
this.createLoadingScreen();
|
this.createLoadingScreen();
|
||||||
@@ -96,6 +100,7 @@ export class ViewManager {
|
|||||||
let setFocus;
|
let setFocus;
|
||||||
sorted.forEach((server) => {
|
sorted.forEach((server) => {
|
||||||
const srv = new MattermostServer(server.name, server.url);
|
const srv = new MattermostServer(server.name, server.url);
|
||||||
|
const serverInfo = new ServerInfo(srv);
|
||||||
server.tabs.forEach((tab) => {
|
server.tabs.forEach((tab) => {
|
||||||
const tabView = getServerView(srv, tab);
|
const tabView = getServerView(srv, tab);
|
||||||
const recycle = oldviews.get(tabView.name);
|
const recycle = oldviews.get(tabView.name);
|
||||||
@@ -108,7 +113,7 @@ export class ViewManager {
|
|||||||
oldviews.delete(recycle.name);
|
oldviews.delete(recycle.name);
|
||||||
this.views.set(recycle.name, recycle);
|
this.views.set(recycle.name, recycle);
|
||||||
} else {
|
} else {
|
||||||
this.loadView(srv, tab);
|
this.loadView(srv, serverInfo, tab);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -217,7 +222,7 @@ export class ViewManager {
|
|||||||
const {srv, tab} = this.closedViews.get(name)!;
|
const {srv, tab} = this.closedViews.get(name)!;
|
||||||
tab.isClosed = false;
|
tab.isClosed = false;
|
||||||
this.closedViews.delete(name);
|
this.closedViews.delete(name);
|
||||||
this.loadView(srv, tab, url);
|
this.loadView(srv, new ServerInfo(srv), tab, url);
|
||||||
this.showByName(name);
|
this.showByName(name);
|
||||||
const view = this.views.get(name)!;
|
const view = this.views.get(name)!;
|
||||||
view.isVisible = true;
|
view.isVisible = true;
|
||||||
@@ -402,11 +407,17 @@ export class ViewManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempting to change parsedURL protocol results in it not being modified.
|
if (view.status === Status.READY && view.serverInfo.remoteInfo.serverVersion && isServerVersionGreaterThanOrEqualTo(view.serverInfo.remoteInfo.serverVersion, '6.0.0')) {
|
||||||
view.resetLoadingStatus();
|
const pathName = `/${urlWithSchema.replace(view.tab.server.url.toString(), '')}`;
|
||||||
view.load(urlWithSchema);
|
view.view.webContents.send(BROWSER_HISTORY_PUSH, pathName);
|
||||||
view.once(LOAD_SUCCESS, this.deeplinkSuccess);
|
this.deeplinkSuccess(view.name);
|
||||||
view.once(LOAD_FAILED, this.deeplinkFailed);
|
} else {
|
||||||
|
// attempting to change parsedURL protocol results in it not being modified.
|
||||||
|
view.resetLoadingStatus();
|
||||||
|
view.load(urlWithSchema);
|
||||||
|
view.once(LOAD_SUCCESS, this.deeplinkSuccess);
|
||||||
|
view.once(LOAD_FAILED, this.deeplinkFailed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dialog.showErrorBox('No matching server', `there is no configured server in the app that matches the requested url: ${parsedURL.toString()}`);
|
dialog.showErrorBox('No matching server', `there is no configured server in the app that matches the requested url: ${parsedURL.toString()}`);
|
||||||
|
Reference in New Issue
Block a user