1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

use currentApp path for static files

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2022-12-09 09:14:03 +02:00
parent e2d3f5ad4e
commit c69ad966d8
9 changed files with 39 additions and 19 deletions

View File

@ -33,6 +33,7 @@ ci-validate-dev: binaries/client build-extensions compile-dev
.PHONY: dev .PHONY: dev
dev: binaries/client build-extensions dev: binaries/client build-extensions
rm -rf static/build/ rm -rf static/build/
yarn run build:tray-icons
yarn dev yarn dev
.PHONY: lint .PHONY: lint

View File

@ -4,9 +4,10 @@
*/ */
import type { app as electronApp } from "electron"; import type { app as electronApp } from "electron";
export type PathName = Parameters<typeof electronApp["getPath"]>[0]; export type PathName = Parameters<typeof electronApp["getPath"]>[0] | "currentApp";
export const pathNames: PathName[] = [ export const pathNames: PathName[] = [
"currentApp",
"home", "home",
"appData", "appData",
"userData", "userData",

View File

@ -19,6 +19,7 @@ describe("app-paths", () => {
builder = getApplicationBuilder(); builder = getApplicationBuilder();
const defaultAppPathsStub: AppPaths = { const defaultAppPathsStub: AppPaths = {
currentApp: "some-current-app",
appData: "some-app-data", appData: "some-app-data",
cache: "some-cache", cache: "some-cache",
crashDumps: "some-crash-dumps", crashDumps: "some-crash-dumps",
@ -70,6 +71,7 @@ describe("app-paths", () => {
const actual = windowDi.inject(appPathsInjectionToken); const actual = windowDi.inject(appPathsInjectionToken);
expect(actual).toEqual({ expect(actual).toEqual({
currentApp: "some-current-app",
appData: "some-app-data", appData: "some-app-data",
cache: "some-cache", cache: "some-cache",
crashDumps: "some-crash-dumps", crashDumps: "some-crash-dumps",
@ -93,6 +95,7 @@ describe("app-paths", () => {
const actual = mainDi.inject(appPathsInjectionToken); const actual = mainDi.inject(appPathsInjectionToken);
expect(actual).toEqual({ expect(actual).toEqual({
currentApp: "some-current-app",
appData: "some-app-data", appData: "some-app-data",
cache: "some-cache", cache: "some-cache",
crashDumps: "some-crash-dumps", crashDumps: "some-crash-dumps",

View File

@ -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");

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import appPathsInjectable from "../app-paths/app-paths.injectable";
import joinPathsInjectable from "../path/join-paths.injectable"; import joinPathsInjectable from "../path/join-paths.injectable";
const staticFilesDirectoryInjectable = getInjectable({ const staticFilesDirectoryInjectable = getInjectable({
@ -10,8 +11,9 @@ const staticFilesDirectoryInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const joinPaths = di.inject(joinPathsInjectable); const joinPaths = di.inject(joinPathsInjectable);
const currentAppDir = di.inject(appPathsInjectable).currentApp;
return joinPaths(__dirname, ".."); return joinPaths(currentAppDir, "static");
}, },
}); });

View File

@ -79,7 +79,7 @@ describe("installing update", () => {
it("shows normal tray icon", () => { it("shows normal tray icon", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("shows tray icon for checking for updates", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("shows tray icon for normal", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("still shows tray icon for downloading", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("still shows normal tray icon", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("shows tray icon for update being available", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("shows tray icon for checking for updates", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("shows tray icon for update being available", () => {
expect(builder.tray.getIconPath()).toBe( 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", () => { it("shows tray icon for downloading update", () => {
expect(builder.tray.getIconPath()).toBe( expect(builder.tray.getIconPath()).toBe(
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png", "/some-static-files-directory/build/tray/trayIconCheckingForUpdatesTemplate.png",
); );
}); });
}); });

View File

@ -8,12 +8,12 @@ import { getApplicationBuilder } from "../../renderer/components/test-utils/get-
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn 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 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 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 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 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 splashWindowInjectable from "../../main/start-main-application/lens-window/splash-window/splash-window.injectable";
import { runInAction } from "mobx"; import { runInAction } from "mobx";
import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable";
describe("opening application window using tray", () => { describe("opening application window using tray", () => {
describe("given application has started", () => { describe("given application has started", () => {
@ -36,8 +36,8 @@ describe("opening application window using tray", () => {
mainDi.override(focusApplicationInjectable, () => focusApplicationMock); mainDi.override(focusApplicationInjectable, () => focusApplicationMock);
mainDi.override( mainDi.override(
lensResourcesDirInjectable, staticFilesDirectoryInjectable,
() => "/some-lens-resources-directory", () => "/some-static-directory",
); );
const loadFileMock = jest const loadFileMock = jest
@ -119,7 +119,7 @@ describe("opening application window using tray", () => {
}); });
it("starts loading static HTML of splash window", () => { 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", () => { describe("when loading of splash window HTML resolves", () => {

View File

@ -9,13 +9,17 @@ interface Dependencies {
app: App; app: App;
} }
export type GetElectronAppPath = (name: PathName) => string; export type GetElectronAppPath = (name: PathName | "currentApp") => string;
export const getElectronAppPath = ({ export const getElectronAppPath = ({
app, app,
}: Dependencies): GetElectronAppPath => ( }: Dependencies): GetElectronAppPath => (
(name) => { (name) => {
try { try {
if (name === "currentApp") {
return app.getAppPath();
}
return app.getPath(name); return app.getPath(name);
} catch (e) { } catch (e) {
return ""; return "";

View File

@ -7,9 +7,9 @@ import { hasCorrectExtension } from "./has-correct-extension";
import readFileInjectable from "../../../../common/fs/read-file.injectable"; import readFileInjectable from "../../../../common/fs/read-file.injectable";
import readDirectoryInjectable from "../../../../common/fs/read-directory.injectable"; import readDirectoryInjectable from "../../../../common/fs/read-directory.injectable";
import type { RawTemplates } from "./create-resource-templates.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 joinPathsInjectable from "../../../../common/path/join-paths.injectable";
import parsePathInjectable from "../../../../common/path/parse.injectable"; import parsePathInjectable from "../../../../common/path/parse.injectable";
import lensResourcesDirInjectable from "../../../../common/vars/lens-resources-dir.injectable";
const lensCreateResourceTemplatesInjectable = getInjectable({ const lensCreateResourceTemplatesInjectable = getInjectable({
id: "lens-create-resource-templates", id: "lens-create-resource-templates",
@ -18,14 +18,14 @@ const lensCreateResourceTemplatesInjectable = getInjectable({
const readFile = di.inject(readFileInjectable); const readFile = di.inject(readFileInjectable);
const readDir = di.inject(readDirectoryInjectable); const readDir = di.inject(readDirectoryInjectable);
const joinPaths = di.inject(joinPathsInjectable); const joinPaths = di.inject(joinPathsInjectable);
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
const parsePath = di.inject(parsePathInjectable); const parsePath = di.inject(parsePathInjectable);
const resourcesDirectory = di.inject(lensResourcesDirInjectable)
/** /**
* Mapping between file names and their contents * Mapping between file names and their contents
*/ */
const templates: [file: string, contents: string][] = []; 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)) { for (const dirEntry of await readDir(templatesFolder)) {
if (hasCorrectExtension(dirEntry)) { if (hasCorrectExtension(dirEntry)) {