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

Replace basically all uses of app.getPath() with AppPaths.get()

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-27 14:13:38 -04:00
parent 9a17097543
commit ebd918fcf7
12 changed files with 31 additions and 31 deletions

View File

@ -21,6 +21,7 @@
import { app, ipcMain, ipcRenderer } from "electron";
import { observable, when } from "mobx";
import path from "path";
import logger from "./logger";
import { fromEntries, toJS } from "./utils";
import { isWindows } from "./vars";
@ -71,6 +72,12 @@ export class AppPaths {
}
private static initMain(): void {
if (process.env.CICD) {
app.setPath("appData", process.env.CICD);
}
app.setPath("userData", path.join(app.getPath("appData"), app.getName()));
AppPaths.paths.set(fromEntries(pathNames.map(pathName => [pathName, app.getPath(pathName)])));
ipcMain.handle(AppPaths.ipcChannel, () => toJS(AppPaths.paths.get()));
}

View File

@ -27,7 +27,7 @@ import path from "path";
import { BaseStore } from "../common/base-store";
import type { LensExtensionId } from "../extensions/lens-extension";
import { toJS } from "../common/utils";
import { app } from "electron";
import { AppPaths } from "../common/app-paths";
interface FSProvisionModel {
extensions: Record<string, string>; // extension names to paths
@ -55,7 +55,7 @@ export class FilesystemProvisionerStore extends BaseStore<FSProvisionModel> {
if (!this.registeredExtensions.has(extensionName)) {
const salt = randomBytes(32).toString("hex");
const hashedName = SHA256(`${extensionName}/${salt}`).toString();
const dirPath = path.resolve(app.getPath("userData"), "extension_data", hashedName);
const dirPath = path.resolve(AppPaths.get("userData"), "extension_data", hashedName);
this.registeredExtensions.set(extensionName, dirPath);
}

View File

@ -63,14 +63,12 @@ import { ensureDir } from "fs-extra";
import { Router } from "./router";
import { initMenu } from "./menu";
import { initTray } from "./tray";
import * as path from "path";
import { kubeApiRequest, shellApiRequest } from "./proxy-functions";
import { AppPaths } from "../common/app-paths";
const onCloseCleanup = disposer();
const onQuitCleanup = disposer();
const workingDir = path.join(app.getPath("appData"), appName);
SentryInit();
app.setName(appName);
@ -83,13 +81,6 @@ if (app.setAsDefaultProtocolClient("lens")) {
logger.info("📟 Protocol client register failed ❗");
}
if (process.env.CICD) {
app.setPath("appData", process.env.CICD);
app.setPath("userData", path.join(process.env.CICD, appName));
} else {
app.setPath("userData", workingDir);
}
AppPaths.init();
if (process.env.LENS_DISABLE_GPU) {
@ -130,7 +121,7 @@ app.on("second-instance", (event, argv) => {
});
app.on("ready", async () => {
logger.info(`🚀 Starting ${productName} from "${app.getPath("exe")}"`);
logger.info(`🚀 Starting ${productName} from "${AppPaths.get("exe")}"`);
logger.info("🐚 Syncing shell environment");
await shellSync();

View File

@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { app, BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
import { KubernetesCluster } from "../../common/catalog-entities";
import { clusterFrameMap } from "../../common/cluster-frames";
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler, clusterSetDeletingHandler, clusterClearDeletingHandler } from "../../common/cluster-ipc";
@ -34,6 +34,7 @@ import { ResourceApplier } from "../resource-applier";
import { WindowManager } from "../window-manager";
import path from "path";
import { remove } from "fs-extra";
import { AppPaths } from "../../common/app-paths";
export function initIpcMainHandlers() {
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
@ -99,7 +100,7 @@ export function initIpcMainHandlers() {
try {
// remove the local storage file
const localStorageFilePath = path.resolve(app.getPath("userData"), "lens-local-storage", `${cluster.id}.json`);
const localStorageFilePath = path.resolve(AppPaths.get("userData"), "lens-local-storage", `${cluster.id}.json`);
await remove(localStorageFilePath);
} catch {}

View File

@ -22,15 +22,15 @@
import type { KubeConfig } from "@kubernetes/client-node";
import type { Cluster } from "./cluster";
import type { ContextHandler } from "./context-handler";
import { app } from "electron";
import path from "path";
import fs from "fs-extra";
import { dumpConfigYaml } from "../common/kube-helpers";
import logger from "./logger";
import { LensProxy } from "./lens-proxy";
import { AppPaths } from "../common/app-paths";
export class KubeconfigManager {
protected configDir = app.getPath("temp");
protected configDir = AppPaths.get("temp");
protected tempFile: string = null;
constructor(protected cluster: Cluster, protected contextHandler: ContextHandler) { }

View File

@ -32,7 +32,7 @@ import { getBundledKubectlVersion } from "../common/utils/app-version";
import { isDevelopment, isWindows, isTestEnv } from "../common/vars";
import { SemVer } from "semver";
import { defaultPackageMirror, packageMirrors } from "../common/user-store/preferences-helpers";
import { app } from "electron";
import { AppPaths } from "../common/app-paths";
const bundledVersion = getBundledKubectlVersion();
const kubectlMap: Map<string, string> = new Map([
@ -81,7 +81,7 @@ export class Kubectl {
protected dirname: string;
static get kubectlDir() {
return path.join(app.getPath("userData"), "binaries", "kubectl");
return path.join(AppPaths.get("userData"), "binaries", "kubectl");
}
public static readonly bundledKubectlVersion: string = bundledVersion;

View File

@ -23,12 +23,12 @@
// convert file path cluster icons to their base64 encoded versions
import path from "path";
import { app } from "electron";
import fse from "fs-extra";
import { loadConfigFromFileSync } from "../../common/kube-helpers";
import { MigrationDeclaration, migrationLog } from "../helpers";
import type { ClusterModel } from "../../common/cluster-types";
import { getCustomKubeConfigPath, storedKubeConfigFolder } from "../../common/utils";
import { AppPaths } from "../../common/app-paths";
interface Pre360ClusterModel extends ClusterModel {
kubeConfig: string;
@ -37,7 +37,7 @@ interface Pre360ClusterModel extends ClusterModel {
export default {
version: "3.6.0-beta.1",
run(store) {
const userDataPath = app.getPath("userData");
const userDataPath = AppPaths.get("userData");
const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? [];
const migratedClusters: ClusterModel[] = [];

View File

@ -20,10 +20,10 @@
*/
import path from "path";
import { app } from "electron";
import fse from "fs-extra";
import type { ClusterModel } from "../../common/cluster-types";
import type { MigrationDeclaration } from "../helpers";
import { AppPaths } from "../../common/app-paths";
interface Pre500WorkspaceStoreModel {
workspaces: {
@ -35,7 +35,7 @@ interface Pre500WorkspaceStoreModel {
export default {
version: "5.0.0-beta.10",
run(store) {
const userDataPath = app.getPath("userData");
const userDataPath = AppPaths.get("userData");
try {
const workspaceData: Pre500WorkspaceStoreModel = fse.readJsonSync(path.join(userDataPath, "lens-workspace-store.json"));

View File

@ -23,8 +23,8 @@ import type { ClusterModel, ClusterPreferences, ClusterPrometheusPreferences } f
import { MigrationDeclaration, migrationLog } from "../helpers";
import { generateNewIdFor } from "../utils";
import path from "path";
import { app } from "electron";
import { moveSync, removeSync } from "fs-extra";
import { AppPaths } from "../../common/app-paths";
function mergePrometheusPreferences(left: ClusterPrometheusPreferences, right: ClusterPrometheusPreferences): ClusterPrometheusPreferences {
if (left.prometheus && left.prometheusProvider) {
@ -106,7 +106,7 @@ function moveStorageFolder({ folder, newId, oldId }: { folder: string, newId: st
export default {
version: "5.0.0-beta.13",
run(store) {
const folder = path.resolve(app.getPath("userData"), "lens-local-storage");
const folder = path.resolve(AppPaths.get("userData"), "lens-local-storage");
const oldClusters: ClusterModel[] = store.get("clusters") ?? [];
const clusters = new Map<string, ClusterModel>();

View File

@ -19,11 +19,11 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { app } from "electron";
import fse from "fs-extra";
import { isNull } from "lodash";
import path from "path";
import * as uuid from "uuid";
import { AppPaths } from "../../common/app-paths";
import type { ClusterStoreModel } from "../../common/cluster-store";
import { defaultHotbarCells, getEmptyHotbar, Hotbar, HotbarItem } from "../../common/hotbar-types";
import { catalogEntity } from "../../main/catalog-sources/general";
@ -48,7 +48,7 @@ export default {
run(store) {
const rawHotbars = store.get("hotbars");
const hotbars: Hotbar[] = Array.isArray(rawHotbars) ? rawHotbars.filter(h => h && typeof h === "object") : [];
const userDataPath = app.getPath("userData");
const userDataPath = AppPaths.get("userData");
// Hotbars might be empty, if some of the previous migrations weren't run
if (hotbars.length === 0) {

View File

@ -19,7 +19,6 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { app } from "electron";
import { existsSync, readFileSync } from "fs";
import path from "path";
import os from "os";
@ -27,14 +26,16 @@ import type { ClusterStoreModel } from "../../common/cluster-store";
import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../common/user-store";
import { MigrationDeclaration, migrationLog } from "../helpers";
import { isLogicalChildPath, storedKubeConfigFolder } from "../../common/utils";
import { AppPaths } from "../../common/app-paths";
export default {
version: "5.0.3-beta.1",
run(store) {
try {
const { syncKubeconfigEntries = [], ...preferences }: UserPreferencesModel = store.get("preferences") ?? {};
const { clusters = [] }: ClusterStoreModel = JSON.parse(readFileSync(path.resolve(app.getPath("userData"), "lens-cluster-store.json"), "utf-8")) ?? {};
const extensionDataDir = path.resolve(app.getPath("userData"), "extension_data");
const userData = AppPaths.get("userData");
const { clusters = [] }: ClusterStoreModel = JSON.parse(readFileSync(path.resolve(userData, "lens-cluster-store.json"), "utf-8")) ?? {};
const extensionDataDir = path.resolve(userData, "extension_data");
const syncPaths = new Set(syncKubeconfigEntries.map(s => s.filePath));
syncPaths.add(path.join(os.homedir(), ".kube"));

View File

@ -19,12 +19,12 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { app } from "electron";
import fse from "fs-extra";
import path from "path";
import { AppPaths } from "../../common/app-paths";
export function fileNameMigration() {
const userDataPath = app.getPath("userData");
const userDataPath = AppPaths.get("userData");
const configJsonPath = path.join(userDataPath, "config.json");
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");