mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Reimplement setup for application tray using runnables instead of non-OCP in index.ts
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
9d193c672f
commit
ca6ab58459
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* 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 trayInitializerInjectable from "./tray-initializer.injectable";
|
||||||
|
import { onApplicationQuitInjectionToken } from "../start-main-application/on-application-close/implementations/quit-application/on-application-quit/on-application-quit-injection-token";
|
||||||
|
|
||||||
|
const setupTrayWhenApplicationIsQuitInjectable = getInjectable({
|
||||||
|
id: "setup-tray-when-application-is-quit",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const trayInitializer = di.inject(trayInitializerInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => {
|
||||||
|
trayInitializer.stop();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
injectionToken: onApplicationQuitInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default setupTrayWhenApplicationIsQuitInjectable;
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* 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 { onApplicationIsReadyInjectionToken } from "../start-main-application/on-application-is-ready/on-application-is-ready-injection-token";
|
||||||
|
import trayInitializerInjectable from "./tray-initializer.injectable";
|
||||||
|
|
||||||
|
const setupTrayWhenApplicationIsReadyInjectable = getInjectable({
|
||||||
|
id: "setup-tray-when-application-is-ready",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const trayInitializer = di.inject(trayInitializerInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => {
|
||||||
|
trayInitializer.start();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
injectionToken: onApplicationIsReadyInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default setupTrayWhenApplicationIsReadyInjectable;
|
||||||
33
src/main/tray/tray-initializer.injectable.ts
Normal file
33
src/main/tray/tray-initializer.injectable.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* 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 { initTray } from "./tray";
|
||||||
|
import windowManagerInjectable from "../window-manager.injectable";
|
||||||
|
import trayMenuItemsInjectable from "./tray-menu-items.injectable";
|
||||||
|
import navigateToPreferencesInjectable from "../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||||
|
import stopServicesAndExitAppInjectable from "../stop-services-and-exit-app.injectable";
|
||||||
|
|
||||||
|
const trayInitializerInjectable = getInjectable({
|
||||||
|
id: "tray-initializer",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
let disposer: () => void;
|
||||||
|
|
||||||
|
return ({
|
||||||
|
start: () => {
|
||||||
|
const windowManager = di.inject(windowManagerInjectable);
|
||||||
|
const trayMenuItems = di.inject(trayMenuItemsInjectable);
|
||||||
|
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||||
|
const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable);
|
||||||
|
|
||||||
|
disposer = initTray(windowManager, trayMenuItems, navigateToPreferences, stopServicesAndExitApp);
|
||||||
|
},
|
||||||
|
|
||||||
|
stop: () => disposer?.(),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default trayInitializerInjectable;
|
||||||
@ -12,13 +12,11 @@ import { checkForUpdates, isAutoUpdateEnabled } from "../app-updater";
|
|||||||
import type { WindowManager } from "../window-manager";
|
import type { WindowManager } from "../window-manager";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
import { isDevelopment, isWindows, productName, staticFilesDirectory } from "../../common/vars";
|
import { isDevelopment, isWindows, productName, staticFilesDirectory } from "../../common/vars";
|
||||||
import { exitApp } from "../exit-app";
|
|
||||||
import type { Disposer } from "../../common/utils";
|
import type { Disposer } from "../../common/utils";
|
||||||
import { disposer, toJS } from "../../common/utils";
|
import { disposer, toJS } from "../../common/utils";
|
||||||
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
|
|
||||||
const TRAY_LOG_PREFIX = "[TRAY]";
|
const TRAY_LOG_PREFIX = "[TRAY]";
|
||||||
|
|
||||||
// note: instance of Tray should be saved somewhere, otherwise it disappears
|
// note: instance of Tray should be saved somewhere, otherwise it disappears
|
||||||
@ -36,6 +34,7 @@ export function initTray(
|
|||||||
windowManager: WindowManager,
|
windowManager: WindowManager,
|
||||||
trayMenuItems: IComputedValue<TrayMenuRegistration[]>,
|
trayMenuItems: IComputedValue<TrayMenuRegistration[]>,
|
||||||
navigateToPreferences: () => void,
|
navigateToPreferences: () => void,
|
||||||
|
stopServicesAndExitApp: () => void,
|
||||||
): Disposer {
|
): Disposer {
|
||||||
const icon = getTrayIconPath();
|
const icon = getTrayIconPath();
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ export function initTray(
|
|||||||
return disposer(
|
return disposer(
|
||||||
autorun(() => {
|
autorun(() => {
|
||||||
try {
|
try {
|
||||||
const menu = createTrayMenu(windowManager, toJS(trayMenuItems.get()), navigateToPreferences);
|
const menu = createTrayMenu(windowManager, toJS(trayMenuItems.get()), navigateToPreferences, stopServicesAndExitApp);
|
||||||
|
|
||||||
tray.setContextMenu(menu);
|
tray.setContextMenu(menu);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -82,6 +81,7 @@ function createTrayMenu(
|
|||||||
windowManager: WindowManager,
|
windowManager: WindowManager,
|
||||||
extensionTrayItems: TrayMenuRegistration[],
|
extensionTrayItems: TrayMenuRegistration[],
|
||||||
navigateToPreferences: () => void,
|
navigateToPreferences: () => void,
|
||||||
|
stopServicesAndExitApp: () => void,
|
||||||
): Menu {
|
): Menu {
|
||||||
let template: Electron.MenuItemConstructorOptions[] = [
|
let template: Electron.MenuItemConstructorOptions[] = [
|
||||||
{
|
{
|
||||||
@ -125,7 +125,7 @@ function createTrayMenu(
|
|||||||
{
|
{
|
||||||
label: "Quit App",
|
label: "Quit App",
|
||||||
click() {
|
click() {
|
||||||
exitApp();
|
stopServicesAndExitApp();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]));
|
]));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user