diff --git a/desktop/scripts/start-dev-server.ts b/desktop/scripts/start-dev-server.ts index cc6d58ba7..e21edb523 100644 --- a/desktop/scripts/start-dev-server.ts +++ b/desktop/scripts/start-dev-server.ts @@ -62,7 +62,7 @@ const argv = yargs }, 'open-dev-tools': { describe: - 'Open Dev Tools window on startup. The flag is disabled by default. Env var FLIPPER_OPEN_DEV_TOOLS is equivalent to the command-line option "--open-dev-tools".', + 'Open Dev Tools window on startup. The flag is disabled by default. Env var FLIPPER_OPEN_DEV_TOOLS is equivalent to the command-line option "--open-dev-tools". If "FLIPPER_UPDATE_DEV_TOOLS=true" is set additionally, Flipper will try to update the dev tools from the play store.', type: 'boolean', }, 'dev-server-port': { diff --git a/desktop/static/main.ts b/desktop/static/main.ts index 2305ce80f..e2b9a4108 100644 --- a/desktop/static/main.ts +++ b/desktop/static/main.ts @@ -28,6 +28,7 @@ import setup from './setup'; import isFB from './fb-stubs/isFB'; import delegateToLauncher from './launcher'; import yargs from 'yargs'; +import {promisify} from 'util'; const VERSION: string = (global as any).__VERSION__; @@ -170,7 +171,7 @@ app.on('will-finish-launching', () => { app.on('ready', () => { // If we delegate to the launcher, shut down this instance of the app. - delegateToLauncher(argv).then((hasLauncherInvoked: boolean) => { + delegateToLauncher(argv).then(async (hasLauncherInvoked: boolean) => { if (hasLauncherInvoked) { app.quit(); return; @@ -186,8 +187,39 @@ app.on('ready', () => { REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS, } = require('electron-devtools-installer'); - installExtension(REACT_DEVELOPER_TOOLS.id); - installExtension(REDUX_DEVTOOLS.id); + // if set, try to download a newever version of the dev tools + const forceDownload = process.env.FLIPPER_UPDATE_DEV_TOOLS === 'true'; + if (forceDownload) { + console.log('Force updating DevTools'); + } + // Redux + await installExtension(REDUX_DEVTOOLS.id).catch((e: any) => { + console.error('Failed to install Redux devtools extension', e); + }, forceDownload); + // React + // Fix for extension loading (see D27685981) + // Work around per https://github.com/electron/electron/issues/23662#issuecomment-787420799 + const reactDevToolsPath = `${os.homedir()}/Library/Application Support/Electron/extensions/${ + REACT_DEVELOPER_TOOLS.id + }`; + if (await promisify(fs.exists)(reactDevToolsPath)) { + console.log('Loading React devtools from disk ' + reactDevToolsPath); + await session.defaultSession + .loadExtension( + reactDevToolsPath, + // @ts-ignore only supported (and needed) in Electron 12 + {allowFileAccess: true}, + ) + .catch((e) => { + console.error('Failed to loa React devtools from disk: ', e); + }); + } else { + await installExtension(REACT_DEVELOPER_TOOLS.id, { + loadExtensionOptions: {allowFileAccess: true, forceDownload}, + }).catch((e: any) => { + console.error('Failed to install React devtools extension', e); + }); + } } }); }); diff --git a/docs/extending/dev-setup.mdx b/docs/extending/dev-setup.mdx index dde4ad4f1..9c4153e17 100644 --- a/docs/extending/dev-setup.mdx +++ b/docs/extending/dev-setup.mdx @@ -120,7 +120,10 @@ Options: which means that all plugins loaded. [array] --open-dev-tools Open Dev Tools window on startup. The flag is disabled by default. Env var FLIPPER_OPEN_DEV_TOOLS is equivalent - to the command-line option "--open-dev-tools". [boolean] + to the command-line option "--open-dev-tools". If + "FLIPPER_UPDATE_DEV_TOOLS=true" is set additionally, + Flipper will try to update the dev tools from the play + store. [boolean] --dev-server-port Dev server port. 3000 by default. Env var "PORT=3001" is equivalent to the command-line option "--dev-server-port 3001". [number] [default: 3000]