[MM-53847] Expose isDev API to allow webapp to check if the app is in dev mode (#2800)

* [MM-53847] Expose isDev API to allow webapp to check if the app is in dev mode

* Fix test
This commit is contained in:
Devin Binnie
2023-08-29 10:07:33 -04:00
committed by GitHub
parent f581f439df
commit 9c3febd4c9
6 changed files with 16 additions and 2 deletions

View File

@@ -173,3 +173,5 @@ export const MAIN_WINDOW_RESIZED = 'main-window-resized';
export const MAIN_WINDOW_FOCUSED = 'main-window-focused';
export const VALIDATE_SERVER_URL = 'validate-server-url';
export const GET_IS_DEV_MODE = 'get-is-dev-mode';

View File

@@ -235,7 +235,7 @@ function initializeBeforeAppReady() {
AllowProtocolDialog.init();
if (isDev && process.env.NODE_ENV !== 'test') {
log.info('In development mode, deeplinking is disabled');
app.setAsDefaultProtocolClient('mattermost-dev');
} else if (mainProtocol) {
app.setAsDefaultProtocolClient(mainProtocol);
}

View File

@@ -35,6 +35,8 @@ jest.mock('electron', () => ({
},
}));
jest.mock('electron-is-dev', () => false);
jest.mock('common/config', () => ({
setServers: jest.fn(),
}));

View File

@@ -6,6 +6,7 @@ import path from 'path';
import fs from 'fs-extra';
import {app, BrowserWindow, Menu, Rectangle, Session, session, dialog, nativeImage, screen} from 'electron';
import isDev from 'electron-is-dev';
import {MigrationInfo} from 'types/config';
import {RemoteInfo} from 'types/server';
@@ -72,7 +73,8 @@ export function getDeeplinkingURL(args: string[]) {
if (Array.isArray(args) && args.length) {
// deeplink urls should always be the last argument, but may not be the first (i.e. Windows with the app already running)
const url = args[args.length - 1];
if (url && mainProtocol && url.startsWith(mainProtocol) && isValidURI(url)) {
const protocol = isDev ? 'mattermost-dev' : mainProtocol;
if (url && protocol && url.startsWith(protocol) && isValidURI(url)) {
return url;
}
}

View File

@@ -37,6 +37,7 @@ import {
CLOSE_DOWNLOADS_DROPDOWN,
CALLS_ERROR,
CALLS_JOIN_REQUEST,
GET_IS_DEV_MODE,
} from 'common/communication';
const UNREAD_COUNT_INTERVAL = 1000;
@@ -56,6 +57,10 @@ if (process.env.NODE_ENV === 'test') {
});
}
contextBridge.exposeInMainWorld('desktopAPI', {
isDev: () => ipcRenderer.invoke(GET_IS_DEV_MODE),
});
ipcRenderer.invoke('get-app-version').then(({name, version}) => {
appVersion = version;
appName = name;

View File

@@ -2,6 +2,7 @@
// See LICENSE.txt for license information.
import {BrowserView, dialog, ipcMain, IpcMainEvent, IpcMainInvokeEvent, Event} from 'electron';
import isDev from 'electron-is-dev';
import ServerViewState from 'app/serverViewState';
@@ -30,6 +31,7 @@ import {
MAIN_WINDOW_RESIZED,
MAIN_WINDOW_FOCUSED,
SWITCH_TAB,
GET_IS_DEV_MODE,
} from 'common/communication';
import Config from 'common/config';
import {Logger} from 'common/log';
@@ -67,6 +69,7 @@ export class ViewManager {
MainWindow.on(MAIN_WINDOW_RESIZED, this.handleSetCurrentViewBounds);
MainWindow.on(MAIN_WINDOW_FOCUSED, this.focusCurrentView);
ipcMain.handle(GET_VIEW_INFO_FOR_TEST, this.handleGetViewInfoForTest);
ipcMain.handle(GET_IS_DEV_MODE, () => isDev);
ipcMain.on(HISTORY, this.handleHistory);
ipcMain.on(REACT_APP_INITIALIZED, this.handleReactAppInitialized);
ipcMain.on(BROWSER_HISTORY_PUSH, this.handleBrowserHistoryPush);