diff --git a/Makefile b/Makefile index 857f14b2cb..a3436115e9 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ ci-validate-dev: binaries/client build-extensions compile-dev .PHONY: dev dev: binaries/client build-extensions rm -rf static/build/ + yarn run build:tray-icons yarn dev .PHONY: lint diff --git a/src/common/app-paths/app-path-names.ts b/src/common/app-paths/app-path-names.ts index 211901dd7a..8e3d2c440e 100644 --- a/src/common/app-paths/app-path-names.ts +++ b/src/common/app-paths/app-path-names.ts @@ -4,9 +4,10 @@ */ import type { app as electronApp } from "electron"; -export type PathName = Parameters[0]; +export type PathName = Parameters[0] | "currentApp"; export const pathNames: PathName[] = [ + "currentApp", "home", "appData", "userData", diff --git a/src/common/app-paths/app-paths.test.ts b/src/common/app-paths/app-paths.test.ts index ff4bd88988..0fa6141f33 100644 --- a/src/common/app-paths/app-paths.test.ts +++ b/src/common/app-paths/app-paths.test.ts @@ -19,6 +19,7 @@ describe("app-paths", () => { builder = getApplicationBuilder(); const defaultAppPathsStub: AppPaths = { + currentApp: "some-current-app", appData: "some-app-data", cache: "some-cache", crashDumps: "some-crash-dumps", @@ -70,6 +71,7 @@ describe("app-paths", () => { const actual = windowDi.inject(appPathsInjectionToken); expect(actual).toEqual({ + currentApp: "some-current-app", appData: "some-app-data", cache: "some-cache", crashDumps: "some-crash-dumps", @@ -93,6 +95,7 @@ describe("app-paths", () => { const actual = mainDi.inject(appPathsInjectionToken); expect(actual).toEqual({ + currentApp: "some-current-app", appData: "some-app-data", cache: "some-cache", crashDumps: "some-crash-dumps", diff --git a/src/common/vars/static-files-directory.global-override-for-injectable.ts b/src/common/vars/static-files-directory.global-override-for-injectable.ts new file mode 100644 index 0000000000..57ea132a0a --- /dev/null +++ b/src/common/vars/static-files-directory.global-override-for-injectable.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getGlobalOverride } from "../test-utils/get-global-override"; +import staticFilesDirectoryInjectable from "./static-files-directory.injectable"; + + +export default getGlobalOverride(staticFilesDirectoryInjectable, () => "some-static-directory"); diff --git a/src/common/vars/static-files-directory.injectable.ts b/src/common/vars/static-files-directory.injectable.ts index f2be4e92f5..8ed9967119 100644 --- a/src/common/vars/static-files-directory.injectable.ts +++ b/src/common/vars/static-files-directory.injectable.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import appPathsInjectable from "../app-paths/app-paths.injectable"; import joinPathsInjectable from "../path/join-paths.injectable"; const staticFilesDirectoryInjectable = getInjectable({ @@ -10,8 +11,9 @@ const staticFilesDirectoryInjectable = getInjectable({ instantiate: (di) => { const joinPaths = di.inject(joinPathsInjectable); + const currentAppDir = di.inject(appPathsInjectable).currentApp; - return joinPaths(__dirname, ".."); + return joinPaths(currentAppDir, "static"); }, }); diff --git a/src/features/application-update/installing-update.test.ts b/src/features/application-update/installing-update.test.ts index f6041c200e..d065f407e3 100644 --- a/src/features/application-update/installing-update.test.ts +++ b/src/features/application-update/installing-update.test.ts @@ -79,7 +79,7 @@ describe("installing update", () => { it("shows normal tray icon", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconTemplate.png", + "/some-static-files-directory/build/tray/trayIconTemplate.png", ); }); @@ -97,7 +97,7 @@ describe("installing update", () => { it("shows tray icon for checking for updates", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + "/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png", ); }); @@ -114,7 +114,7 @@ describe("installing update", () => { it("shows tray icon for normal", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconTemplate.png", + "/some-static-files-directory/build/tray/trayIconTemplate.png", ); }); @@ -141,7 +141,7 @@ describe("installing update", () => { it("still shows tray icon for downloading", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + "/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png", ); }); @@ -160,7 +160,7 @@ describe("installing update", () => { it("still shows normal tray icon", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconTemplate.png", + "/some-static-files-directory/build/tray/trayIconTemplate.png", ); }); @@ -180,7 +180,7 @@ describe("installing update", () => { it("shows tray icon for update being available", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png", + "/some-static-files-directory/build/tray/trayIconUpdateAvailableTemplate.png", ); }); @@ -197,7 +197,7 @@ describe("installing update", () => { it("shows tray icon for checking for updates", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + "/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png", ); }); @@ -215,7 +215,7 @@ describe("installing update", () => { it("shows tray icon for update being available", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png", + "/some-static-files-directory/build/tray/trayIconUpdateAvailableTemplate.png", ); }); }); @@ -234,7 +234,7 @@ describe("installing update", () => { it("shows tray icon for downloading update", () => { expect(builder.tray.getIconPath()).toBe( - "/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", + "/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png", ); }); }); diff --git a/src/features/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts b/src/features/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts index b1769e80af..1dccbf71da 100644 --- a/src/features/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts +++ b/src/features/quitting-and-restarting-the-app/opening-application-window-using-tray.test.ts @@ -8,12 +8,12 @@ import { getApplicationBuilder } from "../../renderer/components/test-utils/get- import type { AsyncFnMock } from "@async-fn/jest"; import asyncFn from "@async-fn/jest"; import type { LensWindow } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable"; -import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable"; import focusApplicationInjectable from "../../main/electron-app/features/focus-application.injectable"; import type { CreateElectronWindow } from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable"; import createElectronWindowInjectable from "../../main/start-main-application/lens-window/application-window/create-electron-window.injectable"; import splashWindowInjectable from "../../main/start-main-application/lens-window/splash-window/splash-window.injectable"; import { runInAction } from "mobx"; +import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; describe("opening application window using tray", () => { describe("given application has started", () => { @@ -36,8 +36,8 @@ describe("opening application window using tray", () => { mainDi.override(focusApplicationInjectable, () => focusApplicationMock); mainDi.override( - lensResourcesDirInjectable, - () => "/some-lens-resources-directory", + staticFilesDirectoryInjectable, + () => "/some-static-directory", ); const loadFileMock = jest @@ -119,7 +119,7 @@ describe("opening application window using tray", () => { }); it("starts loading static HTML of splash window", () => { - expect(callForSplashWindowHtmlMock).toHaveBeenCalledWith("/some-lens-resources-directory/static/splash.html"); + expect(callForSplashWindowHtmlMock).toHaveBeenCalledWith("/some-static-directory/splash.html"); }); describe("when loading of splash window HTML resolves", () => { diff --git a/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts b/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts index f7531b89b1..45a6058d61 100644 --- a/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts +++ b/src/main/app-paths/get-electron-app-path/get-electron-app-path.ts @@ -9,13 +9,17 @@ interface Dependencies { app: App; } -export type GetElectronAppPath = (name: PathName) => string; +export type GetElectronAppPath = (name: PathName | "currentApp") => string; export const getElectronAppPath = ({ app, }: Dependencies): GetElectronAppPath => ( (name) => { try { + if (name === "currentApp") { + return app.getAppPath(); + } + return app.getPath(name); } catch (e) { return ""; diff --git a/src/renderer/components/dock/create-resource/lens-templates.injectable.ts b/src/renderer/components/dock/create-resource/lens-templates.injectable.ts index 86c3e4fd3d..a523fcfcf5 100644 --- a/src/renderer/components/dock/create-resource/lens-templates.injectable.ts +++ b/src/renderer/components/dock/create-resource/lens-templates.injectable.ts @@ -7,9 +7,9 @@ import { hasCorrectExtension } from "./has-correct-extension"; import readFileInjectable from "../../../../common/fs/read-file.injectable"; import readDirectoryInjectable from "../../../../common/fs/read-directory.injectable"; import type { RawTemplates } from "./create-resource-templates.injectable"; -import staticFilesDirectoryInjectable from "../../../../common/vars/static-files-directory.injectable"; import joinPathsInjectable from "../../../../common/path/join-paths.injectable"; import parsePathInjectable from "../../../../common/path/parse.injectable"; +import lensResourcesDirInjectable from "../../../../common/vars/lens-resources-dir.injectable"; const lensCreateResourceTemplatesInjectable = getInjectable({ id: "lens-create-resource-templates", @@ -18,14 +18,14 @@ const lensCreateResourceTemplatesInjectable = getInjectable({ const readFile = di.inject(readFileInjectable); const readDir = di.inject(readDirectoryInjectable); const joinPaths = di.inject(joinPathsInjectable); - const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); const parsePath = di.inject(parsePathInjectable); + const resourcesDirectory = di.inject(lensResourcesDirInjectable) /** * Mapping between file names and their contents */ const templates: [file: string, contents: string][] = []; - const templatesFolder = joinPaths(staticFilesDirectory, "../templates/create-resource"); + const templatesFolder = joinPaths(resourcesDirectory, "templates/create-resource"); for (const dirEntry of await readDir(templatesFolder)) { if (hasCorrectExtension(dirEntry)) {