mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Expose a way to control tray item enableablity through Extension API
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
5253df0647
commit
7d7ae86245
@ -11,7 +11,8 @@ import { getExtensionFakeFor } from "../../renderer/components/test-utils/get-ex
|
||||
describe("preferences: extension adding tray items", () => {
|
||||
describe("when extension with tray items is enabled", () => {
|
||||
let builder: ApplicationBuilder;
|
||||
let someObservable: IObservableValue<boolean>;
|
||||
let someObservableForVisibility: IObservableValue<boolean>;
|
||||
let someObservableForEnabled: IObservableValue<boolean>;
|
||||
|
||||
beforeEach(async () => {
|
||||
builder = getApplicationBuilder();
|
||||
@ -22,7 +23,8 @@ describe("preferences: extension adding tray items", () => {
|
||||
|
||||
const getExtensionFake = getExtensionFakeFor(builder);
|
||||
|
||||
someObservable = observable.box(false);
|
||||
someObservableForVisibility = observable.box(false);
|
||||
someObservableForEnabled = observable.box(false);
|
||||
|
||||
const testExtension = getExtensionFake({
|
||||
id: "some-extension-id",
|
||||
@ -33,13 +35,36 @@ describe("preferences: extension adding tray items", () => {
|
||||
{
|
||||
label: "some-controlled-visibility",
|
||||
click: () => {},
|
||||
visible: computed(() => someObservable.get()),
|
||||
visible: computed(() => someObservableForVisibility.get()),
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-uncontrolled-visibility",
|
||||
click: () => {},
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-controlled-enabled",
|
||||
click: () => {},
|
||||
enabled: computed(() => someObservableForEnabled.get()),
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-uncontrolled-enabled",
|
||||
click: () => {},
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-statically-enabled",
|
||||
click: () => {},
|
||||
enabled: true,
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-statically-disabled",
|
||||
click: () => {},
|
||||
enabled: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@ -65,7 +90,7 @@ describe("preferences: extension adding tray items", () => {
|
||||
|
||||
it("when item becomes visible, shows the item", () => {
|
||||
runInAction(() => {
|
||||
someObservable.set(true);
|
||||
someObservableForVisibility.set(true);
|
||||
});
|
||||
|
||||
expect(
|
||||
@ -74,5 +99,52 @@ describe("preferences: extension adding tray items", () => {
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
|
||||
it("given item does not have enabled status, item is enabled by default", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-uncontrolled-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
describe("given item has controlled enabled status and is disabled", () => {
|
||||
it("is disabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-controlled-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(false);
|
||||
});
|
||||
|
||||
it("when item becomes enabled, items is enabled", () => {
|
||||
runInAction(() => {
|
||||
someObservableForEnabled.set(true);
|
||||
});
|
||||
|
||||
const item = builder.tray.get(
|
||||
"some-controlled-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("given item is statically enabled, item is enabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-statically-enabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it("given item is statically disabled, item is disabled", () => {
|
||||
const item = builder.tray.get(
|
||||
"some-statically-disabled-tray-menu-item-for-extension-some-extension",
|
||||
);
|
||||
|
||||
expect(item?.enabled).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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,13 +65,23 @@ 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),
|
||||
enabled: computed(() => {
|
||||
if (registration.enabled === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isBoolean(registration.enabled)) {
|
||||
return registration.enabled;
|
||||
}
|
||||
|
||||
return registration.enabled.get();
|
||||
}),
|
||||
|
||||
visible: computed(() => {
|
||||
if (!registration.visible) {
|
||||
|
||||
@ -11,7 +11,7 @@ export interface TrayMenuRegistration {
|
||||
id?: string;
|
||||
type?: "normal" | "separator" | "submenu";
|
||||
toolTip?: string;
|
||||
enabled?: boolean;
|
||||
enabled?: boolean | IComputedValue<boolean>;
|
||||
submenu?: TrayMenuRegistration[];
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user