mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Convert runManyFor to use composite Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert runManySyncFor to use composite and to enfore sync-ness Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove dead code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert getStartableStoppable to be always sync as it is never used in an async fashion Signed-off-by: Sebastian Malton <sebastian@malton.name> * Convert all sync runnables to comply with new checks for sync-ness Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
|
import { reaction } from "mobx";
|
|
import type { MinimalTrayMenuItem } from "../electron-tray/electron-tray.injectable";
|
|
import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
|
|
import trayMenuItemsInjectable from "../tray-menu-item/tray-menu-items.injectable";
|
|
import type { TrayMenuItem } from "../tray-menu-item/tray-menu-item-injection-token";
|
|
|
|
const reactiveTrayMenuItemsInjectable = getInjectable({
|
|
id: "reactive-tray-menu-items",
|
|
|
|
instantiate: (di) => {
|
|
const electronTray = di.inject(electronTrayInjectable);
|
|
const reactiveItems = di.inject(trayMenuItemsInjectable);
|
|
|
|
return getStartableStoppable("reactive-tray-menu-items", () =>
|
|
reaction(
|
|
() => reactiveItems.get().map(toNonReactiveItem),
|
|
(nonReactiveItems) => electronTray.setMenuItems(nonReactiveItems),
|
|
{
|
|
fireImmediately: true,
|
|
},
|
|
),
|
|
);
|
|
},
|
|
});
|
|
|
|
export default reactiveTrayMenuItemsInjectable;
|
|
|
|
const toNonReactiveItem = (item: TrayMenuItem): MinimalTrayMenuItem => ({
|
|
id: item.id,
|
|
parentId: item.parentId,
|
|
click: item.click,
|
|
tooltip: item.tooltip,
|
|
separator: item.separator,
|
|
enabled: item.enabled.get(),
|
|
label: item.label?.get(),
|
|
});
|