Files
flipper/desktop/flipper-ui-browser/src/initializeRenderHost.tsx
Michel Weststrate 78413c1ecf Register shortcuts on window instead of globally
Summary:
Changelog: Register shortcuts only for Flipper application instead of globally. Fixes https://github.com/facebook/flipper/issues/3090

As reported, during decapitation we accidentally started registering shortcuts globally, rather per app as it used to be in the menu's. This diff fixes that and also makes sure shortcuts are supported in the browser version of flipper

Reviewed By: lawrencelomax

Differential Revision: D33158445

fbshipit-source-id: 8371e5b96e772152eeb93ba990e1f5edb9e67085
2021-12-16 14:51:08 -08:00

79 lines
2.1 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 {FlipperServer, FlipperServerConfig} from 'flipper-common';
import {RenderHost} from 'flipper-ui-core';
export function initializeRenderHost(
flipperServer: FlipperServer,
flipperServerConfig: FlipperServerConfig,
) {
window.FlipperRenderHostInstance = {
readTextFromClipboard() {
// TODO:
return undefined;
},
writeTextToClipboard(_text: string) {
// TODO:
},
async importFile() {
throw new Error('Not implemented');
},
async exportFile() {
throw new Error('Not implemented');
},
openLink(url: string) {
window.open(url, '_blank');
},
hasFocus() {
return document.hasFocus();
},
onIpcEvent(_event) {
// no-op
},
sendIpcEvent(_event, ..._args: any[]) {
// no-op
},
shouldUseDarkColors() {
return !!(
window.flipperConfig.theme === 'dark' ||
(window.flipperConfig.theme === 'system' &&
window.matchMedia?.('(prefers-color-scheme: dark)'))
);
},
restartFlipper() {
window.flipperShowError!(
'Flipper settings have changed, please restart flipper server for the changes to take effect',
);
},
loadDefaultPlugins: getDefaultPluginsIndex,
serverConfig: flipperServerConfig,
GK(gatekeeper) {
return flipperServerConfig.gatekeepers[gatekeeper] ?? false;
},
flipperServer,
async requirePlugin(path) {
// TODO: use `await import(path)`?
const source = await flipperServer.exec('plugin-source', path);
// eslint-disable-next-line no-eval
return eval(source);
},
getStaticResourceUrl(path): string {
// the 'static' folder is mounted as static middleware in Express at the root
return '/' + path;
},
} as RenderHost;
}
function getDefaultPluginsIndex() {
// eslint-disable-next-line import/no-unresolved
const index = require('./defaultPlugins');
return index.default || index;
}