From 25f82986eac9f502c0265eccc57b7de17e9f8751 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 11 Apr 2019 04:04:56 -0700 Subject: [PATCH] Avoid triggering notification in headless Summary: There was a bug where headless version used to crash when crash reporter plugin used to get messages. So the problem was that it tried to trigger the notification in headless version, which obviously won't work. Solves this [bug](https://our.intern.facebook.com/intern/sandcastle/log/?instance_id=88210824&step_id=773963185&step_index=5&name=Get+headless+and+run+it) Bug: {F155634920} Reviewed By: jknoxville, danielbuechele Differential Revision: D14874122 fbshipit-source-id: 2614b16665a354be7a75844a372dbea7a59d7e55 --- .../com/facebook/flipper/sample/RootComponentSpec.java | 1 - src/dispatcher/notifications.js | 3 ++- src/utils/isHeadless.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/utils/isHeadless.js diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java b/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java index e4d33498b..f4ae22d00 100644 --- a/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java +++ b/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java @@ -23,7 +23,6 @@ import com.facebook.litho.annotations.OnUpdateState; import com.facebook.litho.annotations.State; import com.facebook.litho.fresco.FrescoImage; import com.facebook.litho.widget.Text; - @LayoutSpec public class RootComponentSpec { diff --git a/src/dispatcher/notifications.js b/src/dispatcher/notifications.js index 428f7b80b..da2e649d9 100644 --- a/src/dispatcher/notifications.js +++ b/src/dispatcher/notifications.js @@ -9,7 +9,7 @@ import type {Store} from '../reducers/index.js'; import type {Logger} from '../fb-interfaces/Logger.js'; import type {PluginNotification} from '../reducers/notifications'; import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js'; - +import isHeadless from '../utils/isHeadless.js'; import {ipcRenderer} from 'electron'; import {selectPlugin} from '../reducers/connections'; import { @@ -128,6 +128,7 @@ export default (store: Store, logger: Logger) => { activeNotifications.forEach((n: PluginNotification) => { if ( + !isHeadless() && store.getState().connections.selectedPlugin !== 'notifications' && !knownNotifications.has(n.notification.id) && blacklistedPlugins.indexOf(n.pluginId) === -1 && diff --git a/src/utils/isHeadless.js b/src/utils/isHeadless.js new file mode 100644 index 000000000..679869320 --- /dev/null +++ b/src/utils/isHeadless.js @@ -0,0 +1,10 @@ +/** + * 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 + */ + +export default function isHeadless(): boolean { + return typeof global.window === 'undefined'; +}