mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix crash on clean startup (#6276)
* Convert ReleaseChannel into an InitializableState Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix init timing for DefaultUpdateChannel Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make UserStore loading seperate from creation to fix initialization timing errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix overrides of UserStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix UserStore tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move userStoreFileMigration call to the init runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for userStoreFileMigratiom Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
dad6dcacda
commit
4c49134dbc
18 files changed
+159
-49
No files matched your search
@@ -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 userStoreFileNameMigrationInjectable from "./file-name-migration.injectable";
|
||||
|
||||
export default getGlobalOverride(userStoreFileNameMigrationInjectable, () => async () => {});
|
||||
@@ -9,27 +9,32 @@ import directoryForUserDataInjectable from "../app-paths/directory-for-user-data
|
||||
import { isErrnoException } from "../utils";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
|
||||
export type UserStoreFileNameMigration = () => Promise<void>;
|
||||
|
||||
const userStoreFileNameMigrationInjectable = getInjectable({
|
||||
id: "user-store-file-name-migration",
|
||||
instantiate: (di) => {
|
||||
instantiate: (di): UserStoreFileNameMigration => {
|
||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||
const configJsonPath = path.join(userDataPath, "config.json");
|
||||
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
||||
|
||||
try {
|
||||
fse.moveSync(configJsonPath, lensUserStoreJsonPath);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "dest already exists.") {
|
||||
fse.removeSync(configJsonPath);
|
||||
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
||||
// (No such file or directory)
|
||||
return; // file already moved
|
||||
} else {
|
||||
// pass other errors along
|
||||
throw error;
|
||||
return async () => {
|
||||
try {
|
||||
await fse.move(configJsonPath, lensUserStoreJsonPath);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "dest already exists.") {
|
||||
await fse.remove(configJsonPath);
|
||||
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
||||
// (No such file or directory)
|
||||
return; // file already moved
|
||||
} else {
|
||||
// pass other errors along
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default userStoreFileNameMigrationInjectable;
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { ipcMain } from "electron";
|
||||
import userStoreFileNameMigrationInjectable from "./file-name-migration.injectable";
|
||||
import { UserStore } from "./user-store";
|
||||
import selectedUpdateChannelInjectable from "../application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
|
||||
@@ -14,10 +12,6 @@ const userStoreInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
UserStore.resetInstance();
|
||||
|
||||
if (ipcMain) {
|
||||
di.inject(userStoreFileNameMigrationInjectable);
|
||||
}
|
||||
|
||||
return UserStore.createInstance({
|
||||
selectedUpdateChannel: di.inject(selectedUpdateChannelInjectable),
|
||||
});
|
||||
|
||||
@@ -34,7 +34,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
});
|
||||
|
||||
makeObservable(this);
|
||||
this.load();
|
||||
}
|
||||
|
||||
@observable lastSeenAppVersion = "0.0.0";
|
||||
|
||||
Reference in new issue
Block a user