mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Stop using @electron/remote to obtain app.getPath() (#4078)
* Stop using remote to obtain app.getPath() - Initialize entire map in bootstrap() - Updated unit tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Resolve PR comments Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix build Signed-off-by: Sebastian Malton <sebastian@malton.name> * Ensure that init can only be called once and catch errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace basically all uses of app.getPath() with AppPaths.get() Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix unit tests Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
65b6908bf1
commit
f297407156
45 files changed
+521
-200
No files matched your search
@@ -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[] = [];
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in new issue
Block a user