From e6cdae2b6819340156e8695fe0596d61f1ac812f Mon Sep 17 00:00:00 2001 From: Baptiste Clarey Sjostrand <112877883+baphony@users.noreply.github.com> Date: Tue, 7 May 2024 16:39:05 +0200 Subject: [PATCH] SDA-4544 Allow to load react dev tools chrome extension (#2145) * SDA-4561 - SDA branch cut * SDA-4544 Allow to load react dev tools chrome extension --------- Co-authored-by: Kiran Niranjan --- package-lock.json | 216 +++++++++++++++++++++++++++++++++++ package.json | 1 + src/app/extension-handler.ts | 29 +++++ src/app/main.ts | 3 + 4 files changed, 249 insertions(+) create mode 100644 src/app/extension-handler.ts diff --git a/package-lock.json b/package-lock.json index e37597b2..8d0157b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,6 +42,7 @@ "del": "3.0.0", "electron": "29.3.1", "electron-builder": "^24.13.2", + "electron-devtools-installer": "^3.2.0", "electron-icon-maker": "0.0.5", "electron-osx-sign": "^0.6.0", "enzyme": "^3.11.0", @@ -6584,6 +6585,51 @@ "node": ">=12" } }, + "node_modules/electron-devtools-installer": { + "version": "3.2.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/electron-devtools-installer/-/electron-devtools-installer-3.2.0.tgz", + "integrity": "sha512-t3UczsYugm4OAbqvdImMCImIMVdFzJAHgbwHpkl5jmfu1izVgUcP/mnrPqJIpEeCK1uZGpt+yHgWEN+9EwoYhQ==", + "dev": true, + "dependencies": { + "rimraf": "^3.0.2", + "semver": "^7.2.1", + "tslib": "^2.1.0", + "unzip-crx-3": "^0.2.0" + } + }, + "node_modules/electron-devtools-installer/node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, + "node_modules/electron-devtools-installer/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/electron-devtools-installer/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, "node_modules/electron-dl": { "version": "3.5.0", "license": "MIT", @@ -9548,6 +9594,12 @@ "node": ">=4" } }, + "node_modules/immediate": { + "version": "3.0.6", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "dev": true + }, "node_modules/import-fresh": { "version": "3.3.0", "dev": true, @@ -11534,6 +11586,33 @@ "verror": "1.10.0" } }, + "node_modules/jszip": { + "version": "3.10.1", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/jszip/-/jszip-3.10.1.tgz", + "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "dev": true, + "dependencies": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "setimmediate": "^1.0.5" + } + }, + "node_modules/jszip/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, "node_modules/just-debounce": { "version": "1.1.0", "dev": true, @@ -11753,6 +11832,15 @@ "node": ">= 0.8.0" } }, + "node_modules/lie": { + "version": "3.3.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dev": true, + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/liftoff": { "version": "3.1.0", "dev": true, @@ -15162,6 +15250,12 @@ "node": ">=0.10.0" } }, + "node_modules/setimmediate": { + "version": "1.0.5", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", + "dev": true + }, "node_modules/sha.js": { "version": "2.4.11", "dev": true, @@ -17028,6 +17122,17 @@ "node": ">=8" } }, + "node_modules/unzip-crx-3": { + "version": "0.2.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/unzip-crx-3/-/unzip-crx-3-0.2.0.tgz", + "integrity": "sha512-0+JiUq/z7faJ6oifVB5nSwt589v1KCduqIJupNVDoWSXZtWDmjDGO3RAEOvwJ07w90aoXoP4enKsR7ecMrJtWQ==", + "dev": true, + "dependencies": { + "jszip": "^3.1.0", + "mkdirp": "^0.5.1", + "yaku": "^0.16.6" + } + }, "node_modules/upath": { "version": "1.2.0", "dev": true, @@ -17575,6 +17680,12 @@ "dev": true, "license": "ISC" }, + "node_modules/yaku": { + "version": "0.16.7", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/yaku/-/yaku-0.16.7.tgz", + "integrity": "sha512-Syu3IB3rZvKvYk7yTiyl1bo/jiEFaaStrgv1V2TIJTqYPStSMQVO8EQjg/z+DRzLq/4LIIharNT3iH1hylEIRw==", + "dev": true + }, "node_modules/yallist": { "version": "4.0.0", "license": "ISC" @@ -22491,6 +22602,44 @@ } } }, + "electron-devtools-installer": { + "version": "3.2.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/electron-devtools-installer/-/electron-devtools-installer-3.2.0.tgz", + "integrity": "sha512-t3UczsYugm4OAbqvdImMCImIMVdFzJAHgbwHpkl5jmfu1izVgUcP/mnrPqJIpEeCK1uZGpt+yHgWEN+9EwoYhQ==", + "dev": true, + "requires": { + "rimraf": "^3.0.2", + "semver": "^7.2.1", + "tslib": "^2.1.0", + "unzip-crx-3": "^0.2.0" + }, + "dependencies": { + "rimraf": { + "version": "3.0.2", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "semver": { + "version": "7.6.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "tslib": { + "version": "2.6.2", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + } + } + }, "electron-dl": { "version": "3.5.0", "requires": { @@ -24563,6 +24712,12 @@ } } }, + "immediate": { + "version": "3.0.6", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "dev": true + }, "import-fresh": { "version": "3.3.0", "dev": true, @@ -25913,6 +26068,35 @@ "verror": "1.10.0" } }, + "jszip": { + "version": "3.10.1", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/jszip/-/jszip-3.10.1.tgz", + "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "dev": true, + "requires": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "setimmediate": "^1.0.5" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.8", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } + } + }, "just-debounce": { "version": "1.1.0", "dev": true @@ -26063,6 +26247,15 @@ "type-check": "~0.3.2" } }, + "lie": { + "version": "3.3.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dev": true, + "requires": { + "immediate": "~3.0.5" + } + }, "liftoff": { "version": "3.1.0", "dev": true, @@ -28461,6 +28654,12 @@ } } }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", + "dev": true + }, "sha.js": { "version": "2.4.11", "dev": true, @@ -29774,6 +29973,17 @@ "path-exists": "^4.0.0" } }, + "unzip-crx-3": { + "version": "0.2.0", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/unzip-crx-3/-/unzip-crx-3-0.2.0.tgz", + "integrity": "sha512-0+JiUq/z7faJ6oifVB5nSwt589v1KCduqIJupNVDoWSXZtWDmjDGO3RAEOvwJ07w90aoXoP4enKsR7ecMrJtWQ==", + "dev": true, + "requires": { + "jszip": "^3.1.0", + "mkdirp": "^0.5.1", + "yaku": "^0.16.6" + } + }, "upath": { "version": "1.2.0", "dev": true @@ -30184,6 +30394,12 @@ "version": "4.0.1", "dev": true }, + "yaku": { + "version": "0.16.7", + "resolved": "https://repo.symphony.com/artifactory/api/npm/npm-virtual-dev/yaku/-/yaku-0.16.7.tgz", + "integrity": "sha512-Syu3IB3rZvKvYk7yTiyl1bo/jiEFaaStrgv1V2TIJTqYPStSMQVO8EQjg/z+DRzLq/4LIIharNT3iH1hylEIRw==", + "dev": true + }, "yallist": { "version": "4.0.0" }, diff --git a/package.json b/package.json index 3d90ecb1..59454432 100644 --- a/package.json +++ b/package.json @@ -180,6 +180,7 @@ "del": "3.0.0", "electron": "29.3.1", "electron-builder": "^24.13.2", + "electron-devtools-installer": "^3.2.0", "electron-icon-maker": "0.0.5", "electron-osx-sign": "^0.6.0", "enzyme": "^3.11.0", diff --git a/src/app/extension-handler.ts b/src/app/extension-handler.ts new file mode 100644 index 00000000..18cb5fed --- /dev/null +++ b/src/app/extension-handler.ts @@ -0,0 +1,29 @@ +import installExtension, { + REACT_DEVELOPER_TOOLS, +} from 'electron-devtools-installer'; + +import { Logger } from '../common/loggerBase'; +import { getCommandLineArgs } from '../common/utils'; + +const isCommandLineArgEnabled = (name: string) => + getCommandLineArgs(process.argv, `--${name}`, true) || + getCommandLineArgs(process.argv, `--${name}=1`, true) || + getCommandLineArgs(process.argv, `--${name}=true`, true); + +/** + * Load React Dev Tools extension + * @param logger + * @returns Promise + */ +export const loadReactDevToolsExtension = async (logger: Logger) => { + if (!isCommandLineArgEnabled('enableReactDevTools')) { + return; + } + + try { + const name = await installExtension(REACT_DEVELOPER_TOOLS); + logger.info(`main: Added Extension: ${name}`); + } catch (error) { + logger.error(`main: Error while loading ReactDevTool Extension: ${error}`); + } +}; diff --git a/src/app/main.ts b/src/app/main.ts index 614b0f15..3b4b7834 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -15,6 +15,7 @@ import { ICustomBrowserWindow, windowHandler } from './window-handler'; import { autoLaunchInstance } from './auto-launch-controller'; import { autoUpdate } from './auto-update-handler'; +import { loadReactDevToolsExtension } from './extension-handler'; import { presenceStatusStore } from './stores'; // Set automatic period substitution to false because of a bug in draft js on the client app @@ -111,6 +112,8 @@ const startApplication = async () => { await autoUpdate.init(); await windowHandler.createApplication(); logger.info(`main: created application`); + + await loadReactDevToolsExtension(logger); }; // Handle multiple/single instances