Introduce menu entry support
Summary:
[interesting] since it shows how Flipper APIs are exposed through sandy. However, the next diff is a much simpler example of that
This diff adds support for adding menu entries for sandy plugin (renamed keyboard actions to menus, as it always creates a menu entry, but not necessarily a keyboard shortcut)
```
client.addMenuEntry(
// custom entry
{
label: 'Reset Selection',
topLevelMenu: 'Edit',
handler: () => {
selectedID.set(null);
},
},
// based on built-in action (sets standard label, shortcut)
{
action: 'createPaste',
handler: () => {
console.log('creating paste');
},
},
);
```
Most of this diff is introducing the concept of FlipperUtils, a set of static Flipper methods (not related to a device or client) that can be used from Sandy. This will for example be used to implement things as `createPaste` as well
Reviewed By: nikoant
Differential Revision: D22766990
fbshipit-source-id: ce90af3b700e6c3d9a779a3bab4673ba356f3933
This commit is contained in:
committed by
Facebook GitHub Bot
parent
94eaaf5dca
commit
9c202a4a10
38
desktop/app/src/utils/flipperLibImplementation.tsx
Normal file
38
desktop/app/src/utils/flipperLibImplementation.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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 type {FlipperLib} from 'flipper-plugin';
|
||||
import type {Logger} from '../fb-interfaces/Logger';
|
||||
import type {Store} from '../reducers';
|
||||
|
||||
let flipperLibInstance: FlipperLib | undefined;
|
||||
|
||||
export function initializeFlipperLibImplementation(
|
||||
_store: Store,
|
||||
_logger: Logger,
|
||||
) {
|
||||
// late require to avoid cyclic dependency
|
||||
const {addSandyPluginEntries} = require('../MenuBar');
|
||||
flipperLibInstance = {
|
||||
enableMenuEntries(entries) {
|
||||
addSandyPluginEntries(entries);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function getFlipperLibImplementation(): FlipperLib {
|
||||
if (!flipperLibInstance) {
|
||||
throw new Error('Flipper lib not instantiated');
|
||||
}
|
||||
return flipperLibInstance;
|
||||
}
|
||||
|
||||
export function setFlipperLibImplementation(impl: FlipperLib) {
|
||||
flipperLibInstance = impl;
|
||||
}
|
||||
Reference in New Issue
Block a user