Convert notifications dispatcher to TS
Summary: Convert notifications dispatcher to TS Reviewed By: danielbuechele Differential Revision: D16689175 fbshipit-source-id: 7806d5452a57566ea3d6fdfd233a1679435e0103
This commit is contained in:
committed by
Facebook Github Bot
parent
c43beb53d1
commit
9edfe88caa
@@ -5,20 +5,20 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {Store} from '../reducers/index.tsx';
|
import {Store} from '../reducers/index';
|
||||||
import type {Logger} from '../fb-interfaces/Logger.js';
|
import {Logger} from '../fb-interfaces/Logger.js';
|
||||||
import type {PluginNotification} from '../reducers/notifications.tsx';
|
import {PluginNotification} from '../reducers/notifications';
|
||||||
import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.tsx';
|
import {FlipperPlugin, FlipperDevicePlugin} from '../plugin';
|
||||||
import isHeadless from '../utils/isHeadless.js';
|
import isHeadless from '../utils/isHeadless.js';
|
||||||
import {ipcRenderer} from 'electron';
|
import {ipcRenderer} from 'electron';
|
||||||
import {selectPlugin} from '../reducers/connections.tsx';
|
import {selectPlugin} from '../reducers/connections';
|
||||||
import {
|
import {
|
||||||
setActiveNotifications,
|
setActiveNotifications,
|
||||||
updatePluginBlacklist,
|
updatePluginBlacklist,
|
||||||
updateCategoryBlacklist,
|
updateCategoryBlacklist,
|
||||||
} from '../reducers/notifications.tsx';
|
} from '../reducers/notifications';
|
||||||
import {textContent} from '../utils/index';
|
import {textContent} from '../utils/index';
|
||||||
import GK from '../fb-stubs/GK.tsx';
|
import GK from '../fb-stubs/GK';
|
||||||
|
|
||||||
type NotificationEvents = 'show' | 'click' | 'close' | 'reply' | 'action';
|
type NotificationEvents = 'show' | 'click' | 'close' | 'reply' | 'action';
|
||||||
const NOTIFICATION_THROTTLE = 5 * 1000; // in milliseconds
|
const NOTIFICATION_THROTTLE = 5 * 1000; // in milliseconds
|
||||||
@@ -85,19 +85,21 @@ export default (store: Store, logger: Logger) => {
|
|||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
const {notifications, pluginStates} = store.getState();
|
const {notifications, pluginStates} = store.getState();
|
||||||
|
|
||||||
const clientPlugins: Map<string, Class<FlipperPlugin<>>> = store.getState()
|
const clientPlugins: Map<string, typeof FlipperPlugin> = store.getState()
|
||||||
.plugins.clientPlugins;
|
.plugins.clientPlugins;
|
||||||
|
|
||||||
const devicePlugins: Map<
|
const devicePlugins: Map<
|
||||||
string,
|
string,
|
||||||
Class<FlipperDevicePlugin<>>,
|
typeof FlipperDevicePlugin
|
||||||
> = store.getState().plugins.devicePlugins;
|
> = store.getState().plugins.devicePlugins;
|
||||||
|
|
||||||
const pluginMap: Map<
|
const pluginMap: Map<
|
||||||
string,
|
string,
|
||||||
Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
|
typeof FlipperPlugin | typeof FlipperDevicePlugin
|
||||||
//$FlowFixMe Flow complains that FlipperPlugin and FlipperDevicePlugin are incompatible, where as we have already mentioned the type of the class it can take in the type
|
> = new Map<string, typeof FlipperDevicePlugin | typeof FlipperPlugin>([
|
||||||
> = new Map([...clientPlugins, ...devicePlugins]);
|
...clientPlugins,
|
||||||
|
...devicePlugins,
|
||||||
|
]);
|
||||||
|
|
||||||
Object.keys(pluginStates).forEach(key => {
|
Object.keys(pluginStates).forEach(key => {
|
||||||
if (knownPluginStates.get(key) !== pluginStates[key]) {
|
if (knownPluginStates.get(key) !== pluginStates[key]) {
|
||||||
@@ -105,9 +107,9 @@ export default (store: Store, logger: Logger) => {
|
|||||||
const split = key.split('#');
|
const split = key.split('#');
|
||||||
const pluginId = split.pop();
|
const pluginId = split.pop();
|
||||||
const client = split.join('#');
|
const client = split.join('#');
|
||||||
const persistingPlugin: ?Class<
|
const persistingPlugin:
|
||||||
FlipperPlugin<> | FlipperDevicePlugin<>,
|
| typeof FlipperPlugin
|
||||||
> = pluginMap.get(pluginId);
|
| typeof FlipperDevicePlugin = pluginMap.get(pluginId);
|
||||||
if (persistingPlugin && persistingPlugin.getActiveNotifications) {
|
if (persistingPlugin && persistingPlugin.getActiveNotifications) {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
setActiveNotifications({
|
setActiveNotifications({
|
||||||
@@ -153,6 +155,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
ipcRenderer.send('sendNotification', {
|
ipcRenderer.send('sendNotification', {
|
||||||
payload: {
|
payload: {
|
||||||
title: n.notification.title,
|
title: n.notification.title,
|
||||||
|
// @ts-ignore Remove this when textContent is converted to tsx
|
||||||
body: textContent(n.notification.message),
|
body: textContent(n.notification.message),
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
@@ -165,7 +168,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'button',
|
type: 'button',
|
||||||
text: `Hide all ${pluginMap.get(n.pluginId)?.title || ''}`,
|
text: `Hide all ${pluginMap.get(n.pluginId).title || ''}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
closeButtonText: 'Hide',
|
closeButtonText: 'Hide',
|
||||||
Reference in New Issue
Block a user