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
This commit is contained in:
Pritesh Nandgaonkar
2019-04-11 04:04:56 -07:00
committed by Facebook Github Bot
parent 7f20c34e34
commit 25f82986ea
3 changed files with 12 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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 &&

10
src/utils/isHeadless.js Normal file
View File

@@ -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';
}