Restructure to monorepo (#6907)

* wip: restructure to monorepo

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* refactor create-release-pr to a package

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* build fixes

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* github workflow fixes

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix typo

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* add webpack-env types to core

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix github workflows

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* refactor/fix integration tests

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* lint fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* yarn run dev

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* eslint settings for vscode

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* move templates to right package

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* open-lens build fixes

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* integration test fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix nx task dependencies

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* use bash shell for unit tests in test workflow

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix test:unit for windows

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix win-ca webpack error in open-lens

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix win-ca webpack error in open-lens

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix build:app on windows

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* remove ELECTRON_BUILDER_EXTRA_ARGS

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* sync src/ from master

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* remove Makefile from core

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2023-01-24 10:46:26 -08:00
1 parent 0066ca4ea2
commit 2657df2293
3321 files changed
+28699 -11447

No files matched your search

@@ -0,0 +1,46 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { kebabCase } from "lodash";
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
import electronAppInjectable from "./electron-app.injectable";
export default getGlobalOverride(electronAppInjectable, () => {
const commandLineArgs: string[] = [];
const chromiumArgs = new Map<string, string | undefined>();
const appPaths = new Map<string, string>();
const app = ({
getVersion: () => "6.0.0",
setLoginItemSettings: () => { },
on: () => app,
whenReady: async () => {},
getPath: (name) => appPaths.get(name) ?? `/some-directory-for-${kebabCase(name)}`,
setPath: (name, value) => appPaths.set(name, value),
getAppPath: () => "/some-path-to-the-applcation-binary",
focus: () => {},
commandLine: {
appendArgument: (value) => commandLineArgs.push(value),
appendSwitch: (key, value) => chromiumArgs.set(key, value),
getSwitchValue: (key) => chromiumArgs.get(key),
hasSwitch: (key) => chromiumArgs.has(key),
removeSwitch: (key) => chromiumArgs.delete(key),
},
disableHardwareAcceleration: () => {},
requestSingleInstanceLock: () => true,
getLoginItemSettings: () => ({
executableWillLaunchAtLogin: false,
openAtLogin: false,
openAsHidden: false,
wasOpenedAtLogin: false,
wasOpenedAsHidden: false,
restoreState: false,
launchItems: [],
}),
exit: () => {},
} as Partial<Electron.App> as Electron.App);
return app;
});
@@ -0,0 +1,14 @@
/**
* 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 { app } from "electron";
const electronAppInjectable = getInjectable({
id: "electron-app",
instantiate: () => app,
causesSideEffects: true,
});
export default electronAppInjectable;
@@ -0,0 +1,14 @@
/**
* 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 { autoUpdater } from "electron";
const autoUpdaterInjectable = getInjectable({
id: "auto-updater",
instantiate: () => autoUpdater,
causesSideEffects: true,
});
export default autoUpdaterInjectable;
@@ -0,0 +1,20 @@
/**
* 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 "../electron-app.injectable";
const disableHardwareAccelerationInjectable = getInjectable({
id: "disable-hardware-acceleration",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
return () => {
app.disableHardwareAcceleration();
};
},
});
export default disableHardwareAccelerationInjectable;
@@ -0,0 +1,26 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
import electronDialogInjectable from "./electron-dialog.injectable";
export default getGlobalOverride(electronDialogInjectable, () => ({
showCertificateTrustDialog: async () => {},
showErrorBox: () => {},
showMessageBox: async () => ({
checkboxChecked: false,
response: 0,
}),
showMessageBoxSync: () => 0,
showOpenDialog: async () => ({
canceled: true,
filePaths: [],
}),
showOpenDialogSync: () => [],
showSaveDialog: async () => ({
canceled: true,
}),
showSaveDialogSync: () => "",
}));
@@ -0,0 +1,14 @@
/**
* 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 { dialog } from "electron";
const electronDialogInjectable = getInjectable({
id: "electron-dialog",
instantiate: () => dialog,
causesSideEffects: true,
});
export default electronDialogInjectable;
@@ -0,0 +1,20 @@
/**
* 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 electronUpdaterInjectable from "./electron-updater.injectable";
const electronQuitAndInstallUpdateInjectable = getInjectable({
id: "electron-quit-and-install-update",
instantiate: (di) => {
const electronUpdater = di.inject(electronUpdaterInjectable);
return () => {
electronUpdater.quitAndInstall(true, true);
};
},
});
export default electronQuitAndInstallUpdateInjectable;
@@ -0,0 +1,18 @@
/**
* 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 electronUpdaterInjectable from "./electron-updater.injectable";
const electronUpdaterIsActiveInjectable = getInjectable({
id: "electron-updater-is-active",
instantiate: (di) => {
const electronUpdater = di.inject(electronUpdaterInjectable);
return electronUpdater.isUpdaterActive();
},
});
export default electronUpdaterIsActiveInjectable;
@@ -0,0 +1,14 @@
/**
* 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 { autoUpdater } from "electron-updater";
const electronUpdaterInjectable = getInjectable({
id: "electron-updater",
instantiate: () => autoUpdater,
causesSideEffects: true,
});
export default electronUpdaterInjectable;
@@ -0,0 +1,18 @@
/**
* 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 "../electron-app.injectable";
const exitAppInjectable = getInjectable({
id: "exit-app",
instantiate: (di) => () => {
const app = di.inject(electronAppInjectable);
app.exit(0);
},
});
export default exitAppInjectable;
@@ -0,0 +1,20 @@
/**
* 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 "../electron-app.injectable";
const focusApplicationInjectable = getInjectable({
id: "focus-application",
instantiate: (di) => {
const electronApp = di.inject(electronAppInjectable);
return () => {
electronApp.focus({ steal: true });
};
},
});
export default focusApplicationInjectable;
@@ -0,0 +1,18 @@
/**
* 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 "../electron-app.injectable";
const getCommandLineSwitchInjectable = getInjectable({
id: "get-command-line-switch",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
return (name: string) => app.commandLine.getSwitchValue(name);
},
});
export default getCommandLineSwitchInjectable;
@@ -0,0 +1,18 @@
/**
* 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 nativeThemeInjectable from "./native-theme.injectable";
const getElectronThemeInjectable = getInjectable({
id: "get-electron-theme",
instantiate: (di) => {
const nativeTheme = di.inject(nativeThemeInjectable);
return () => nativeTheme.shouldUseDarkColors ? "dark" : "light";
},
});
export default getElectronThemeInjectable;
@@ -0,0 +1,16 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import EventEmitter from "events";
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
import nativeThemeInjectable from "./native-theme.injectable";
export default getGlobalOverride(nativeThemeInjectable, () => Object.assign(new EventEmitter(), {
shouldUseDarkColors: true,
inForcedColorsMode: true,
shouldUseHighContrastColors: false,
shouldUseInvertedColorScheme: false,
themeSource: "dark" as const,
}));
@@ -0,0 +1,14 @@
/**
* 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 { nativeTheme } from "electron";
const nativeThemeInjectable = getInjectable({
id: "native-theme",
instantiate: () => nativeTheme,
causesSideEffects: true,
});
export default nativeThemeInjectable;
@@ -0,0 +1,14 @@
/**
* 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 { powerMonitor } from "electron";
const powerMonitorInjectable = getInjectable({
id: "power-monitor",
instantiate: () => powerMonitor,
causesSideEffects: true,
});
export default powerMonitorInjectable;
@@ -0,0 +1,18 @@
/**
* 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 "../electron-app.injectable";
const requestSingleInstanceLockInjectable = getInjectable({
id: "request-single-instance-lock",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
return () => app.requestSingleInstanceLock();
},
});
export default requestSingleInstanceLockInjectable;
@@ -0,0 +1,20 @@
/**
* 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 type { Settings } from "electron";
import electronAppInjectable from "../electron-app.injectable";
export type SetLoginItemSettings = (settings: Settings) => void;
const setLoginItemSettingsInjectable = getInjectable({
id: "set-login-item-settings",
instantiate: (di): SetLoginItemSettings => {
const electronApp = di.inject(electronAppInjectable);
return (settings) => electronApp.setLoginItemSettings(settings);
},
});
export default setLoginItemSettingsInjectable;
@@ -0,0 +1,20 @@
/**
* 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 electronUpdaterInjectable from "./electron-updater.injectable";
const setUpdateOnQuitInjectable = getInjectable({
id: "set-update-on-quit",
instantiate: (di) => {
const electronUpdater = di.inject(electronUpdaterInjectable);
return (updateOnQuit: boolean) => {
electronUpdater.autoInstallOnAppQuit = updateOnQuit;
};
},
});
export default setUpdateOnQuitInjectable;
@@ -0,0 +1,27 @@
/**
* 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 "../electron-app.injectable";
import isMacInjectable from "../../../common/vars/is-mac.injectable";
import commandLineArgumentsInjectable from "../../utils/command-line-arguments.injectable";
const shouldStartHiddenInjectable = getInjectable({
id: "should-start-hidden",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
const isMac = di.inject(isMacInjectable);
const commandLineArguments = di.inject(commandLineArgumentsInjectable);
// Start the app without showing the main window when auto starting on login
// (On Windows and Linux, we get a flag. On MacOS, we get special API.)
return (
commandLineArguments.includes("--hidden") ||
(isMac && app.getLoginItemSettings().wasOpenedAsHidden)
);
},
});
export default shouldStartHiddenInjectable;
@@ -0,0 +1,20 @@
/**
* 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 electronDialogInjectable from "./electron-dialog.injectable";
const showErrorPopupInjectable = getInjectable({
id: "show-error-popup",
instantiate: (di) => {
const dialog = di.inject(electronDialogInjectable);
return (heading: string, message: string) => {
dialog.showErrorBox(heading, message);
};
},
});
export default showErrorPopupInjectable;
@@ -0,0 +1,28 @@
/**
* 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 electronDialogInjectable from "./electron-dialog.injectable";
export type ShowMessagePopup = (title: string, message: string, detail: string) => void;
const showMessagePopupInjectable = getInjectable({
id: "show-message-popup",
instantiate: (di): ShowMessagePopup => {
const dialog = di.inject(electronDialogInjectable);
return async (title, message, detail) => {
await dialog.showMessageBox({
title,
message,
detail,
type: "info",
buttons: ["Close"],
});
};
},
});
export default showMessagePopupInjectable;
@@ -0,0 +1,9 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverrideForFunction } from "../../../common/test-utils/get-global-override-for-function";
import showOpenDialogInjectable from "./show-open-dialog.injectable";
export default getGlobalOverrideForFunction(showOpenDialogInjectable);
@@ -0,0 +1,17 @@
/**
* 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 type { OpenDialogOptions } from "electron";
import { dialog } from "electron";
export type ShowOpenDialog = (options: OpenDialogOptions) => Promise<Electron.OpenDialogReturnValue>;
const showOpenDialogInjectable = getInjectable({
id: "show-open-dialog",
instantiate: (): ShowOpenDialog => opts => dialog.showOpenDialog(opts),
causesSideEffects: true,
});
export default showOpenDialogInjectable;
@@ -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 { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable";
import nativeThemeInjectable from "./native-theme.injectable";
import getElectronThemeInjectable from "./get-electron-theme.injectable";
const syncThemeFromOperatingSystemInjectable = getInjectable({
id: "sync-theme-from-operating-system",
instantiate: (di) => {
const currentThemeState = di.inject(operatingSystemThemeStateInjectable);
const nativeTheme = di.inject(nativeThemeInjectable);
const getElectronTheme = di.inject(getElectronThemeInjectable);
return getStartableStoppable("sync-theme-from-operating-system", () => {
const updateThemeState = () => {
currentThemeState.set(getElectronTheme());
};
nativeTheme.on("updated", updateThemeState);
return () => {
nativeTheme.off("updated", updateThemeState);
};
});
},
});
export default syncThemeFromOperatingSystemInjectable;
@@ -0,0 +1,14 @@
/**
* 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 "../electron-app.injectable";
const waitForElectronToBeReadyInjectable = getInjectable({
id: "wait-for-electron-to-be-ready",
instantiate: (di) => () => di.inject(electronAppInjectable).whenReady(),
});
export default waitForElectronToBeReadyInjectable;
@@ -0,0 +1,24 @@
/**
* 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 { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import lensProtocolRouterMainInjectable from "../../protocol-handler/lens-protocol-router-main/lens-protocol-router-main.injectable";
const cleanUpDeepLinkingInjectable = getInjectable({
id: "clean-up-deep-linking",
instantiate: (di) => {
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
return {
id: "clean-up-deep-linking",
run: () => void lensProtocolRouterMain.cleanup(),
};
},
injectionToken: beforeQuitOfBackEndInjectionToken,
});
export default cleanUpDeepLinkingInjectable;
@@ -0,0 +1,35 @@
/**
* 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 { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
import electronAppInjectable from "../../electron-app.injectable";
import { isEmpty } from "lodash/fp";
import getVisibleWindowsInjectable from "../../../start-main-application/lens-window/get-visible-windows.injectable";
const hideDockForLastClosedWindowInjectable = getInjectable({
id: "hide-dock-when-there-are-no-windows",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
return {
id: "hide-dock-when-there-are-no-windows",
run: () => {
const visibleWindows = getVisibleWindows();
if (isEmpty(visibleWindows)) {
app.dock?.hide();
}
return undefined;
},
};
},
injectionToken: beforeQuitOfFrontEndInjectionToken,
});
export default hideDockForLastClosedWindowInjectable;
@@ -0,0 +1,26 @@
/**
* 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 "../../electron-app.injectable";
import { afterWindowIsOpenedInjectionToken } from "../../../start-main-application/runnable-tokens/after-window-is-opened-injection-token";
const showDockForFirstOpenedWindowInjectable = getInjectable({
id: "show-dock-for-first-opened-window",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
return {
id: "show-dock-for-first-opened-window",
run: () => {
app.dock?.show();
},
};
},
injectionToken: afterWindowIsOpenedInjectionToken,
});
export default showDockForFirstOpenedWindowInjectable;
@@ -0,0 +1,32 @@
/**
* 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 { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import requestSingleInstanceLockInjectable from "../features/request-single-instance-lock.injectable";
import exitAppInjectable from "../features/exit-app.injectable";
const enforceSingleApplicationInstanceInjectable = getInjectable({
id: "enforce-single-application-instance",
instantiate: (di) => {
const requestSingleInstanceLock = di.inject(requestSingleInstanceLockInjectable);
const exitApp = di.inject(exitAppInjectable);
return {
id: "enforce-single-application-instance",
run: () => {
if (!requestSingleInstanceLock()) {
exitApp();
}
return undefined;
},
};
},
injectionToken: beforeElectronIsReadyInjectionToken,
});
export default enforceSingleApplicationInstanceInjectable;
@@ -0,0 +1,30 @@
/**
* 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 appNameInjectable from "../../../common/vars/app-name.injectable";
import { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import electronAppInjectable from "../electron-app.injectable";
const setupApplicationNameInjectable = getInjectable({
id: "setup-application-name",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
const appName = di.inject(appNameInjectable);
return {
id: "setup-application-name",
run: () => {
app.setName(appName);
return undefined;
},
};
},
injectionToken: beforeElectronIsReadyInjectionToken,
});
export default setupApplicationNameInjectable;
@@ -0,0 +1,74 @@
/**
* 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 "../electron-app.injectable";
import openDeepLinkInjectable from "../../protocol-handler/lens-protocol-router-main/open-deep-link-for-url/open-deep-link.injectable";
import loggerInjectable from "../../../common/logger.injectable";
import commandLineArgumentsInjectable from "../../utils/command-line-arguments.injectable";
import { pipeline } from "@ogre-tools/fp";
import { find, startsWith, toLower, map } from "lodash/fp";
import { onLoadOfApplicationInjectionToken } from "../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
import showApplicationWindowInjectable from "../../start-main-application/lens-window/show-application-window.injectable";
const setupDeepLinkingInjectable = getInjectable({
id: "setup-deep-linking",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
const logger = di.inject(loggerInjectable);
const openDeepLinkForUrl = di.inject(openDeepLinkInjectable);
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
const firstInstanceCommandLineArguments = di.inject(
commandLineArgumentsInjectable,
);
return {
id: "setup-deep-linking",
run: async () => {
logger.info(`📟 Setting protocol client for lens://`);
if (app.setAsDefaultProtocolClient("lens")) {
logger.info("📟 Protocol client register succeeded ✅");
} else {
logger.info("📟 Protocol client register failed ❗");
}
const url = getDeepLinkUrl(firstInstanceCommandLineArguments);
if (url) {
await openDeepLinkForUrl(url);
}
app.on("open-url", async (event, url) => {
event.preventDefault();
await openDeepLinkForUrl(url);
});
app.on(
"second-instance",
async (_, secondInstanceCommandLineArguments) => {
const url = getDeepLinkUrl(secondInstanceCommandLineArguments);
await showApplicationWindow();
if (url) {
await openDeepLinkForUrl(url);
}
},
);
},
};
},
injectionToken: onLoadOfApplicationInjectionToken,
});
export default setupDeepLinkingInjectable;
const getDeepLinkUrl = (commandLineArguments: string[]) =>
pipeline(commandLineArguments, map(toLower), find(startsWith("lens://")));
@@ -0,0 +1,43 @@
/**
* 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 nodeEnvInjectionToken from "../../../common/vars/node-env-injection-token";
import loggerInjectable from "../../../common/logger.injectable";
import { onLoadOfApplicationInjectionToken } from "../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
const setupDeveloperToolsInDevelopmentEnvironmentInjectable = getInjectable({
id: "setup-developer-tools-in-development-environment",
instantiate: (di) => {
const logger = di.inject(loggerInjectable);
const nodeEnv = di.inject(nodeEnvInjectionToken);
return {
id: "setup-developer-tools-in-development-environment",
run: () => {
if (nodeEnv !== "development") {
return;
}
logger.info("🤓 Installing developer tools");
import("electron-devtools-installer")
.then(({ default: devToolsInstaller, REACT_DEVELOPER_TOOLS }) =>
devToolsInstaller([REACT_DEVELOPER_TOOLS]),
)
.then((name) =>
logger.info(`[DEVTOOLS-INSTALLER]: installed ${name}`),
)
.catch((error) =>
logger.error(`[DEVTOOLS-INSTALLER]: failed`, { error }),
);
},
};
},
injectionToken: onLoadOfApplicationInjectionToken,
});
export default setupDeveloperToolsInDevelopmentEnvironmentInjectable;
@@ -0,0 +1,30 @@
/**
* 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 powerMonitorInjectable from "../features/power-monitor.injectable";
import exitAppInjectable from "../features/exit-app.injectable";
import { onLoadOfApplicationInjectionToken } from "../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
const setupDeviceShutdownInjectable = getInjectable({
id: "setup-device-shutdown",
instantiate: (di) => {
const powerMonitor = di.inject(powerMonitorInjectable);
const exitApp = di.inject(exitAppInjectable);
return {
id: "setup-device-shutdown",
run: () => {
powerMonitor.on("shutdown", async () => {
exitApp();
});
},
};
},
injectionToken: onLoadOfApplicationInjectionToken,
});
export default setupDeviceShutdownInjectable;
@@ -0,0 +1,46 @@
/**
* 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 { setupIpcMainHandlers } from "./setup-ipc-main-handlers";
import loggerInjectable from "../../../../common/logger.injectable";
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
import { onLoadOfApplicationInjectionToken } from "../../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
import applicationMenuItemCompositeInjectable from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
import emitAppEventInjectable from "../../../../common/app-event-bus/emit-event.injectable";
import getClusterByIdInjectable from "../../../../common/cluster-store/get-by-id.injectable";
import pushCatalogToRendererInjectable from "../../../catalog-sync-to-renderer/push-catalog-to-renderer.injectable";
const setupIpcMainHandlersInjectable = getInjectable({
id: "setup-ipc-main-handlers",
instantiate: (di) => {
const logger = di.inject(loggerInjectable);
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
const clusterStore = di.inject(clusterStoreInjectable);
const emitAppEvent = di.inject(emitAppEventInjectable);
const getClusterById = di.inject(getClusterByIdInjectable);
return {
id: "setup-ipc-main-handlers",
run: () => {
logger.debug("[APP-MAIN] initializing ipc main handlers");
setupIpcMainHandlers({
applicationMenuItemComposite,
pushCatalogToRenderer,
clusterStore,
emitAppEvent,
getClusterById,
});
},
};
},
injectionToken: onLoadOfApplicationInjectionToken,
causesSideEffects: true,
});
export default setupIpcMainHandlersInjectable;
@@ -0,0 +1,84 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { IpcMainInvokeEvent } from "electron";
import { BrowserWindow, Menu } from "electron";
import { clusterFrameMap } from "../../../../common/cluster-frames";
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterDisconnectHandler, clusterStates } from "../../../../common/ipc/cluster";
import type { ClusterId } from "../../../../common/cluster-types";
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
import type { IComputedValue } from "mobx";
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
import { handleWindowAction, onLocationChange } from "../../../ipc/window";
import type { ApplicationMenuItemTypes } from "../../../../features/application-menu/main/menu-items/application-menu-item-injection-token";
import type { Composite } from "../../../../common/utils/composite/get-composite/get-composite";
import { getApplicationMenuTemplate } from "../../../../features/application-menu/main/populate-application-menu.injectable";
import type { MenuItemRoot } from "../../../../features/application-menu/main/application-menu-item-composite.injectable";
import type { EmitAppEvent } from "../../../../common/app-event-bus/emit-event.injectable";
import type { GetClusterById } from "../../../../common/cluster-store/get-by-id.injectable";
interface Dependencies {
applicationMenuItemComposite: IComputedValue<Composite<ApplicationMenuItemTypes | MenuItemRoot>>;
clusterStore: ClusterStore;
emitAppEvent: EmitAppEvent;
getClusterById: GetClusterById;
pushCatalogToRenderer: () => void;
}
export const setupIpcMainHandlers = ({
applicationMenuItemComposite,
clusterStore,
emitAppEvent,
getClusterById,
pushCatalogToRenderer,
}: Dependencies) => {
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
return getClusterById(clusterId)
?.activate(force);
});
ipcMainHandle(clusterSetFrameIdHandler, (event: IpcMainInvokeEvent, clusterId: ClusterId) => {
const cluster = getClusterById(clusterId);
if (cluster) {
clusterFrameMap.set(cluster.id, { frameId: event.frameId, processId: event.processId });
pushCatalogToRenderer();
}
});
ipcMainHandle(clusterDisconnectHandler, (event, clusterId: ClusterId) => {
emitAppEvent({ name: "cluster", action: "stop" });
const cluster = getClusterById(clusterId);
if (cluster) {
cluster.disconnect();
clusterFrameMap.delete(cluster.id);
}
});
ipcMainHandle(windowActionHandleChannel, (event, action) => handleWindowAction(action));
ipcMainOn(windowLocationChangedChannel, () => onLocationChange());
ipcMainHandle(broadcastMainChannel, (event, channel, ...args) => broadcastMessage(channel, ...args));
ipcMainOn(windowOpenAppMenuAsContextMenuChannel, async (event) => {
const electronTemplate = getApplicationMenuTemplate(applicationMenuItemComposite.get());
const menu = Menu.buildFromTemplate(electronTemplate);
menu.popup({
...BrowserWindow.fromWebContents(event.sender),
// Center of the topbar menu icon
x: 20,
y: 20,
});
});
ipcMainHandle(clusterStates, () => (
clusterStore.clustersList.map(cluster => ({
id: cluster.id,
state: cluster.getState(),
}))
));
};
@@ -0,0 +1,36 @@
/**
* 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 "../electron-app.injectable";
import loggerInjectable from "../../../common/logger.injectable";
import { onLoadOfApplicationInjectionToken } from "../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
import showApplicationWindowInjectable from "../../start-main-application/lens-window/show-application-window.injectable";
const setupMainWindowVisibilityAfterActivationInjectable = getInjectable({
id: "setup-main-window-visibility-after-activation",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
const logger = di.inject(loggerInjectable);
return {
id: "setup-main-window-visibility-after-activation",
run: () => {
app.on("activate", async (_, windowIsVisible) => {
logger.info("APP:ACTIVATE", { hasVisibleWindows: windowIsVisible });
if (!windowIsVisible) {
await showApplicationWindow();
}
});
},
};
},
injectionToken: onLoadOfApplicationInjectionToken,
});
export default setupMainWindowVisibilityAfterActivationInjectable;
@@ -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 { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import electronAppInjectable from "../electron-app.injectable";
import { runManyFor } from "../../../common/runnable/run-many-for";
import { afterWindowIsOpenedInjectionToken } from "../../start-main-application/runnable-tokens/after-window-is-opened-injection-token";
const setupRunnablesAfterWindowIsOpenedInjectable = getInjectable({
id: "setup-runnables-after-window-is-opened",
instantiate: (di) => {
const afterWindowIsOpened = runManyFor(di)(afterWindowIsOpenedInjectionToken);
const app = di.inject(electronAppInjectable);
return {
id: "setup-runnables-after-window-is-opened",
run: () => {
app.on("browser-window-created", () => {
afterWindowIsOpened();
});
return undefined;
},
};
},
injectionToken: beforeElectronIsReadyInjectionToken,
});
export default setupRunnablesAfterWindowIsOpenedInjectable;
@@ -0,0 +1,55 @@
/**
* 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 { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import electronAppInjectable from "../electron-app.injectable";
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
import autoUpdaterInjectable from "../features/auto-updater.injectable";
import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application",
instantiate: (di) => {
const runManySync = runManySyncFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable);
return {
id: "setup-closing-of-application",
run: () => {
let isAutoUpdating = false;
autoUpdater.on("before-quit-for-update", () => {
isAutoUpdating = true;
});
app.on("will-quit", (event) => {
runRunnablesBeforeQuitOfFrontEnd();
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
if (shouldQuitBackEnd) {
runRunnablesBeforeQuitOfBackEnd();
} else {
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
event.preventDefault();
}
});
return undefined;
},
};
},
injectionToken: beforeElectronIsReadyInjectionToken,
});
export default setupRunnablesBeforeClosingOfApplicationInjectable;