Files
flipper/desktop/flipper-ui-core/src/dispatcher/application.tsx
Michel Weststrate eab4f0d3d3 Bits & pieces
Summary: Added a command to let a file be opened by the OS, and some other small bits and pieces to make Flipper browser compatible.

Reviewed By: lblasa

Differential Revision: D32721748

fbshipit-source-id: a4ad1c2f662f4651ddf6c20c57e5af1e123914a8
2021-12-08 04:30:56 -08:00

76 lines
2.2 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Store} from '../reducers/index';
import {Logger} from 'flipper-common';
import {
importFileToStore,
IMPORT_FLIPPER_TRACE_EVENT,
} from '../utils/exportData';
import {tryCatchReportPlatformFailures} from 'flipper-common';
import {handleDeeplink} from '../deeplink';
import {Dialog} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
export default (store: Store, logger: Logger) => {
const renderHost = getRenderHostInstance();
const onFocus = () => {
setTimeout(() => {
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: true, time: Date.now()},
});
}, 1);
};
const onBlur = () => {
setTimeout(() => {
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: false, time: Date.now()},
});
}, 1);
};
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
window.addEventListener('beforeunload', () => {
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
});
// windowIsFocussed is initialized in the store before the app is fully ready.
// So wait until everything is up and running and then check and set the isFocussed state.
window.addEventListener('flipper-store-ready', () => {
const isFocused = renderHost.hasFocus();
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: isFocused, time: Date.now()},
});
});
renderHost.onIpcEvent('flipper-protocol-handler', (query: string) => {
handleDeeplink(store, logger, query).catch((e) => {
console.warn('Failed to handle deeplink', query, e);
Dialog.alert({
title: 'Failed to open deeplink',
type: 'error',
message: `Failed to handle deeplink '${query}': ${
e.message ?? e.toString()
}`,
});
});
});
renderHost.onIpcEvent('open-flipper-file', (url: string) => {
tryCatchReportPlatformFailures(() => {
return importFileToStore(url, store);
}, `${IMPORT_FLIPPER_TRACE_EVENT}:Deeplink`);
});
};