SDA-3577 - Remove isNodeEnv usage (#1341)

This commit is contained in:
Kiran Niranjan 2022-02-08 08:53:36 +05:30 committed by GitHub
parent f01312cea7
commit 2c3a7c21d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 34 deletions

View File

@ -1,7 +1,7 @@
import { app, crashReporter } from 'electron'; import { app, crashReporter } from 'electron';
import * as path from 'path'; import * as path from 'path';
import { isDevEnv, isNodeEnv } from '../common/env'; import { isDevEnv } from '../common/env';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { getCommandLineArgs } from '../common/utils'; import { getCommandLineArgs } from '../common/utils';
import { appStats } from './stats'; import { appStats } from './stats';
@ -18,10 +18,8 @@ const userDataPath =
// If we are running in production, sandbox the entire app // If we are running in production, sandbox the entire app
// and set the app user model id for windows native notifications // and set the app user model id for windows native notifications
if (!isNodeEnv) { app.enableSandbox();
app.enableSandbox(); app.setAppUserModelId('symphony_exe');
app.setAppUserModelId('symphony_exe');
}
// need to set this explicitly if using Squirrel // need to set this explicitly if using Squirrel
// https://www.electron.build/configuration/configuration#Configuration-squirrelWindows // https://www.electron.build/configuration/configuration#Configuration-squirrelWindows

View File

@ -20,13 +20,7 @@ import * as path from 'path';
import { format, parse } from 'url'; import { format, parse } from 'url';
import { apiName, Themes, WindowTypes } from '../common/api-interface'; import { apiName, Themes, WindowTypes } from '../common/api-interface';
import { import { isDevEnv, isLinux, isMac, isWindowsOS } from '../common/env';
isDevEnv,
isLinux,
isMac,
isNodeEnv,
isWindowsOS,
} from '../common/env';
import { i18n, LocaleType } from '../common/i18n'; import { i18n, LocaleType } from '../common/i18n';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { import {
@ -112,6 +106,8 @@ export const DEFAULT_HEIGHT: number = 900;
export const DEFAULT_WELCOME_SCREEN_WIDTH: number = 542; export const DEFAULT_WELCOME_SCREEN_WIDTH: number = 542;
export const DEFAULT_WELCOME_SCREEN_HEIGHT: number = 333; export const DEFAULT_WELCOME_SCREEN_HEIGHT: number = 333;
export const TITLE_BAR_HEIGHT: number = 32; export const TITLE_BAR_HEIGHT: number = 32;
export const IS_SAND_BOXED: boolean = true;
export const IS_NODE_INTEGRATION_ENABLED: boolean = false;
// Timeout on restarting SDA in case it's stuck // Timeout on restarting SDA in case it's stuck
const LISTEN_TIMEOUT: number = 25 * 1000; const LISTEN_TIMEOUT: number = 25 * 1000;
@ -263,7 +259,6 @@ export class WindowHandler {
logger.info(`window handler: env details`, { logger.info(`window handler: env details`, {
contextIsolation: this.contextIsolation, contextIsolation: this.contextIsolation,
isNodeEnv,
isDevEnv, isDevEnv,
isMac, isMac,
isWindowsOS, isWindowsOS,
@ -736,8 +731,8 @@ export class WindowHandler {
) { ) {
const titleBarView = new BrowserView({ const titleBarView = new BrowserView({
webPreferences: { webPreferences: {
sandbox: !isNodeEnv, sandbox: IS_SAND_BOXED,
nodeIntegration: isNodeEnv, nodeIntegration: IS_NODE_INTEGRATION_ENABLED,
preload: path.join(__dirname, '../renderer/_preload-component.js'), preload: path.join(__dirname, '../renderer/_preload-component.js'),
devTools: isDevEnv, devTools: isDevEnv,
}, },
@ -2189,9 +2184,9 @@ export class WindowHandler {
): ICustomBrowserWindowConstructorOpts { ): ICustomBrowserWindowConstructorOpts {
const defaultPreferencesOpts = { const defaultPreferencesOpts = {
...{ ...{
sandbox: !isNodeEnv, sandbox: IS_SAND_BOXED,
nodeIntegration: isNodeEnv, nodeIntegration: IS_NODE_INTEGRATION_ENABLED,
contextIsolation: isNodeEnv ? false : this.contextIsolation, contextIsolation: this.contextIsolation,
backgroundThrottling: this.backgroundThrottling, backgroundThrottling: this.backgroundThrottling,
enableRemoteModule: true, enableRemoteModule: true,
}, },

View File

@ -16,13 +16,7 @@ import * as path from 'path';
import { format, parse } from 'url'; import { format, parse } from 'url';
import { apiName } from '../common/api-interface'; import { apiName } from '../common/api-interface';
import { import { isDevEnv, isLinux, isMac, isWindowsOS } from '../common/env';
isDevEnv,
isLinux,
isMac,
isNodeEnv,
isWindowsOS,
} from '../common/env';
import { i18n, LocaleType } from '../common/i18n'; import { i18n, LocaleType } from '../common/i18n';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { getGuid } from '../common/utils'; import { getGuid } from '../common/utils';
@ -43,6 +37,8 @@ import {
DEFAULT_WIDTH, DEFAULT_WIDTH,
ICustomBrowserView, ICustomBrowserView,
ICustomBrowserWindow, ICustomBrowserWindow,
IS_NODE_INTEGRATION_ENABLED,
IS_SAND_BOXED,
TITLE_BAR_HEIGHT, TITLE_BAR_HEIGHT,
windowHandler, windowHandler,
} from './window-handler'; } from './window-handler';
@ -187,8 +183,8 @@ export const createComponentWindow = (
width: 300, width: 300,
...opts, ...opts,
webPreferences: { webPreferences: {
sandbox: !isNodeEnv, sandbox: IS_SAND_BOXED,
nodeIntegration: isNodeEnv, nodeIntegration: IS_NODE_INTEGRATION_ENABLED,
preload: path.join(__dirname, '../renderer/_preload-component.js'), preload: path.join(__dirname, '../renderer/_preload-component.js'),
devTools: isDevEnv, devTools: isDevEnv,
}, },
@ -1046,8 +1042,8 @@ export const loadBrowserViews = async (
const titleBarView = new BrowserView({ const titleBarView = new BrowserView({
webPreferences: { webPreferences: {
sandbox: !isNodeEnv, sandbox: IS_SAND_BOXED,
nodeIntegration: isNodeEnv, nodeIntegration: IS_NODE_INTEGRATION_ENABLED,
preload: path.join(__dirname, '../renderer/_preload-component.js'), preload: path.join(__dirname, '../renderer/_preload-component.js'),
devTools: isDevEnv, devTools: isDevEnv,
}, },

View File

@ -6,5 +6,3 @@ export const isElectronQA = !!process.env.ELECTRON_QA;
export const isMac = process.platform === 'darwin'; export const isMac = process.platform === 'darwin';
export const isWindowsOS = process.platform === 'win32'; export const isWindowsOS = process.platform === 'win32';
export const isLinux = process.platform === 'linux'; export const isLinux = process.platform === 'linux';
export const isNodeEnv = !!process.env.NODE_ENV;

View File

@ -6,6 +6,10 @@ import {
ToastNotificationActionTypes, ToastNotificationActionTypes,
} from '../app/analytics-handler'; } from '../app/analytics-handler';
import { config } from '../app/config-handler'; import { config } from '../app/config-handler';
import {
IS_NODE_INTEGRATION_ENABLED,
IS_SAND_BOXED,
} from '../app/window-handler';
import { createComponentWindow, windowExists } from '../app/window-utils'; import { createComponentWindow, windowExists } from '../app/window-utils';
import { AnimationQueue } from '../common/animation-queue'; import { AnimationQueue } from '../common/animation-queue';
import { import {
@ -14,7 +18,6 @@ import {
NOTIFICATION_WINDOW_TITLE, NOTIFICATION_WINDOW_TITLE,
NotificationActions, NotificationActions,
} from '../common/api-interface'; } from '../common/api-interface';
import { isNodeEnv } from '../common/env';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import NotificationHandler from './notification-handler'; import NotificationHandler from './notification-handler';
@ -618,8 +621,8 @@ class Notification extends NotificationHandler {
acceptFirstMouse: true, acceptFirstMouse: true,
title: NOTIFICATION_WINDOW_TITLE, title: NOTIFICATION_WINDOW_TITLE,
webPreferences: { webPreferences: {
sandbox: !isNodeEnv, sandbox: IS_SAND_BOXED,
nodeIntegration: isNodeEnv, nodeIntegration: IS_NODE_INTEGRATION_ENABLED,
devTools: true, devTools: true,
}, },
}; };