From c0b5f106932604a55dfc3f7aea27c84bad63a521 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 14 Feb 2019 05:59:54 -0800 Subject: [PATCH] Add --launcher-msg option to pass to desktop app Summary: Allows the launcher to provide messages to the user. Currently, in the form of the red notification bar at the bottom. This is just meant as a temporary measure during the alpha to have some clearly noticeable way of getting the user's attention. I consider removing this a blocker for the release as this mechanism is not well suited for this in many ways. The current use case for this is providing a warning if a cached version is used instead of the requested one, e.g. "Could not fetch requested Flipper version 'deadbeef', using cached version instead." Reviewed By: jknoxville, priteshrnandgaonkar Differential Revision: D14073687 fbshipit-source-id: 85630347027063103315eeb1286731fe2478e261 --- src/init.js | 4 ++++ src/utils/__tests__/processConfig.node.js | 3 +++ src/utils/launcher.js | 19 +++++++++++++++++++ src/utils/processConfig.js | 2 ++ static/index.js | 5 +++++ static/setup.js | 1 + 6 files changed, 34 insertions(+) create mode 100644 src/utils/launcher.js diff --git a/src/init.js b/src/init.js index 45a9b394f..e8f2afc4f 100644 --- a/src/init.js +++ b/src/init.js @@ -18,6 +18,8 @@ import {persistStore} from 'redux-persist'; import reducers from './reducers/index.js'; import dispatcher from './dispatcher/index.js'; import TooltipProvider from './ui/components/TooltipProvider.js'; +import config from './utils/processConfig.js'; +import {initLauncherHooks} from './utils/launcher.js'; const path = require('path'); const store = createStore( @@ -55,6 +57,8 @@ function init() { (r.installing || r.active).postMessage({precachedIcons}); }) .catch(console.error); + + initLauncherHooks(config(), store); } // make init function callable from outside diff --git a/src/utils/__tests__/processConfig.node.js b/src/utils/__tests__/processConfig.node.js index 41a18fed1..4afc8caa0 100644 --- a/src/utils/__tests__/processConfig.node.js +++ b/src/utils/__tests__/processConfig.node.js @@ -16,6 +16,7 @@ test('config is decoded from env', () => { disabledPlugins: ['pluginA', 'pluginB', 'pluginC'], pluginPaths: ['/a/path', 'b/path'], lastWindowPosition: {x: 4, y: 8, width: 15, height: 16}, + launcherMsg: 'wubba lubba dub dub', updaterEnabled: false, screenCapturePath: '/my/screenshot/path', launcherEnabled: false, @@ -25,6 +26,7 @@ test('config is decoded from env', () => { disabledPlugins: new Set(['pluginA', 'pluginB', 'pluginC']), pluginPaths: ['/a/path', 'b/path'], lastWindowPosition: {x: 4, y: 8, width: 15, height: 16}, + launcherMsg: 'wubba lubba dub dub', updaterEnabled: false, screenCapturePath: '/my/screenshot/path', launcherEnabled: false, @@ -38,6 +40,7 @@ test('config is decoded from env with defaults', () => { disabledPlugins: new Set([]), pluginPaths: [], lastWindowPosition: undefined, + launcherMsg: undefined, updaterEnabled: true, screenCapturePath: undefined, launcherEnabled: true, diff --git a/src/utils/launcher.js b/src/utils/launcher.js new file mode 100644 index 000000000..4943e0e48 --- /dev/null +++ b/src/utils/launcher.js @@ -0,0 +1,19 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import type {ProcessConfig} from './processConfig.js'; +import type {Store} from '../reducers/index.js'; + +export function initLauncherHooks(config: ProcessConfig, store: Store) { + // TODO(T40488739): This must be replaced with a proper display before launching this. + if (config.launcherMsg) { + store.dispatch({ + type: 'SERVER_ERROR', + payload: config.launcherMsg, + }); + } +} diff --git a/src/utils/processConfig.js b/src/utils/processConfig.js index d2ca3435c..d950f9f9a 100644 --- a/src/utils/processConfig.js +++ b/src/utils/processConfig.js @@ -12,6 +12,7 @@ export type ProcessConfig = {| pluginPaths: Array, lastWindowPosition: ?{x: number, y: number, width: number, height: number}, screenCapturePath: ?string, + launcherMsg: ?string, updaterEnabled: boolean, // Controls whether to delegate to the launcher if present. launcherEnabled: boolean, @@ -28,6 +29,7 @@ export default function config(): ProcessConfig { disabledPlugins: new Set(json.disabledPlugins || []), pluginPaths: json.pluginPaths || [], lastWindowPosition: json.lastWindowPosition, + launcherMsg: json.launcherMsg, updaterEnabled: typeof json.updaterEnabled === 'boolean' ? json.updaterEnabled : true, screenCapturePath: json.screenCapturePath, diff --git a/static/index.js b/static/index.js index bfd5df5fb..f9231d2fc 100644 --- a/static/index.js +++ b/static/index.js @@ -48,6 +48,11 @@ const argv = yargs describe: 'Toggle delegating to the update launcher on startup.', type: 'boolean', }) + .option('launcher-msg', { + describe: + '[Internal] Used to provide a user message from the launcher to the user.', + type: 'string', + }) .version(global.__VERSION__) .help().argv; diff --git a/static/setup.js b/static/setup.js index 2d7429c32..7b8b61da7 100644 --- a/static/setup.js +++ b/static/setup.js @@ -76,6 +76,7 @@ module.exports = function(argv) { config = { ...config, updaterEnabled: argv.updater, + launcherMsg: argv.launcherMsg, }; return {config, configPath, flipperDir};