mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Expose a way to reactively control visibility of preference tabs and tray menu items through Extension API (#5789)
This commit is contained in:
1 parent
544bbdc952
commit
eb6cc70143
30 files changed
+1295
-194
No files matched your search
@@ -16,6 +16,7 @@ import { withErrorSuppression } from "../../../common/utils/with-error-suppressi
|
||||
import type { WithErrorLoggingFor } from "../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||
import withErrorLoggingInjectable from "../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||
import getRandomIdInjectable from "../../../common/utils/get-random-id.injectable";
|
||||
import { isBoolean } from "../../../common/utils";
|
||||
|
||||
const trayMenuItemRegistratorInjectable = getInjectable({
|
||||
id: "tray-menu-item-registrator",
|
||||
@@ -64,14 +65,31 @@ const toItemInjectablesFor = (extension: LensMainExtension, withErrorLoggingFor:
|
||||
|
||||
// TODO: Find out how to improve typing so that instead of
|
||||
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||
x => withErrorSuppression(x),
|
||||
(x) => withErrorSuppression(x),
|
||||
);
|
||||
|
||||
return decorated(registration);
|
||||
},
|
||||
|
||||
enabled: computed(() => registration.enabled ?? true),
|
||||
visible: computed(() => true),
|
||||
enabled: computed(() => {
|
||||
if (registration.enabled === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isBoolean(registration.enabled)) {
|
||||
return registration.enabled;
|
||||
}
|
||||
|
||||
return registration.enabled.get();
|
||||
}),
|
||||
|
||||
visible: computed(() => {
|
||||
if (!registration.visible) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return registration.visible.get();
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: trayMenuItemInjectionToken,
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
export interface TrayMenuRegistration {
|
||||
label?: string;
|
||||
click?: (menuItem: TrayMenuRegistration) => void;
|
||||
id?: string;
|
||||
type?: "normal" | "separator" | "submenu";
|
||||
toolTip?: string;
|
||||
enabled?: boolean;
|
||||
enabled?: boolean | IComputedValue<boolean>;
|
||||
submenu?: TrayMenuRegistration[];
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
Reference in new issue
Block a user