mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce tokens for runnables of specific application events for Open Closed Principle
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
bc0b342602
commit
6fe0c2fce5
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
|
||||
export const beforeApplicationIsReadyInjectionToken =
|
||||
getInjectionToken<Runnable>({
|
||||
id: "before-application-is-ready",
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
|
||||
export const onApplicationActivationInjectionToken = getInjectionToken<
|
||||
Runnable<{ hasVisibleWindows: boolean }>
|
||||
>({
|
||||
id: "on-application-activation",
|
||||
});
|
||||
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../../../../run-many-for";
|
||||
import type { Event } from "electron";
|
||||
|
||||
export const onApplicationQuitInjectionToken = getInjectionToken<
|
||||
Runnable<{ event: Event }>
|
||||
>({
|
||||
id: "on-application-quit",
|
||||
});
|
||||
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
import type { Event } from "electron";
|
||||
|
||||
export const onApplicationCloseInjectionToken = getInjectionToken<
|
||||
Runnable<{ event: Event }>
|
||||
>({
|
||||
id: "on-application-close",
|
||||
});
|
||||
@ -3,11 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
|
||||
export interface Setupable {
|
||||
runSetup: () => Promise<void> | void;
|
||||
}
|
||||
|
||||
export const setupableInjectionToken = getInjectionToken<Setupable>({
|
||||
id: "setupable-injection-token",
|
||||
export const onApplicationIsReadyInjectionToken = getInjectionToken<Runnable>({
|
||||
id: "on-application-is-ready",
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
import type { Event } from "electron";
|
||||
|
||||
export const onOpenOfUrlInjectionToken = getInjectionToken<
|
||||
Runnable<{
|
||||
event: Event;
|
||||
url: string;
|
||||
}>
|
||||
>({
|
||||
id: "on-open-of-url",
|
||||
});
|
||||
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
|
||||
export const onRootFrameRenderInjectionToken = getInjectionToken<Runnable>({
|
||||
id: "on-root-frame-render",
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
|
||||
export const onSecondApplicationInstanceInjectionToken = getInjectionToken<
|
||||
Runnable<{ commandLineArguments: string[] }>
|
||||
>({
|
||||
id: "on-second-application-instance",
|
||||
});
|
||||
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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 electronAppInjectable from "../app-paths/get-electron-app-path/electron-app/electron-app.injectable";
|
||||
import { beforeApplicationIsReadyInjectionToken } from "./before-application-is-ready/before-application-is-ready-injection-token";
|
||||
import { onApplicationIsReadyInjectionToken } from "./on-application-is-ready/on-application-is-ready-injection-token";
|
||||
import { onSecondApplicationInstanceInjectionToken } from "./on-second-application-instance/on-second-application-instance-injection-token";
|
||||
import { onApplicationActivationInjectionToken } from "./on-application-activation/on-application-activation-injection-token";
|
||||
import { onOpenOfUrlInjectionToken } from "./on-open-of-url/on-open-of-url-injection-token";
|
||||
import { runManyFor } from "./run-many-for";
|
||||
import {
|
||||
onApplicationCloseInjectionToken,
|
||||
} from "./on-application-close/on-application-close-injection-token";
|
||||
|
||||
const startMainApplicationInjectable = getInjectable({
|
||||
id: "start-main-application",
|
||||
|
||||
instantiate: (di) => {
|
||||
const runMany = runManyFor(di);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
|
||||
const runManyBeforeApplicationIsReady = runMany(
|
||||
beforeApplicationIsReadyInjectionToken,
|
||||
);
|
||||
|
||||
const runManyAfterApplicationIsReady = runMany(
|
||||
onApplicationIsReadyInjectionToken,
|
||||
);
|
||||
|
||||
const runManyForSecondApplicationInstance = runMany(
|
||||
onSecondApplicationInstanceInjectionToken,
|
||||
);
|
||||
|
||||
const runManyForApplicationActivation = runMany(
|
||||
onApplicationActivationInjectionToken,
|
||||
);
|
||||
|
||||
const runManyForApplicationClose = runMany(onApplicationCloseInjectionToken);
|
||||
|
||||
const runManyForOpenOfUrl = runMany(onOpenOfUrlInjectionToken);
|
||||
|
||||
return async () => {
|
||||
app.on("second-instance", async (_, commandLineArguments) => {
|
||||
await runManyForSecondApplicationInstance({ commandLineArguments });
|
||||
});
|
||||
|
||||
app.on("activate", async (_, hasVisibleWindows) => {
|
||||
await runManyForApplicationActivation({ hasVisibleWindows });
|
||||
});
|
||||
|
||||
app.on("will-quit", async (event) => {
|
||||
await runManyForApplicationClose({ event });
|
||||
});
|
||||
|
||||
app.on("open-url", async (event, url) => {
|
||||
await runManyForOpenOfUrl({ event, url });
|
||||
});
|
||||
|
||||
await runManyBeforeApplicationIsReady();
|
||||
|
||||
await app.whenReady();
|
||||
|
||||
await runManyAfterApplicationIsReady();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default startMainApplicationInjectable;
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user