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:
parent
e2d3f5ad4e
commit
c69ad966d8
1
Makefile
1
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
|
||||
|
||||
@ -4,9 +4,10 @@
|
||||
*/
|
||||
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[] = [
|
||||
"currentApp",
|
||||
"home",
|
||||
"appData",
|
||||
"userData",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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");
|
||||
@ -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");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -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",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
@ -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 "";
|
||||
|
||||
@ -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)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user