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

Move userStoreFileMigration call to the init runnable

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-09-19 16:35:24 -04:00
parent d262b15cdd
commit 8a90c230be
3 changed files with 23 additions and 20 deletions

View File

@ -9,26 +9,30 @@ 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;
}
}
}
};
},
});

View File

@ -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),
});

View File

@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import userStoreFileNameMigrationInjectable from "../../common/user-store/file-name-migration.injectable";
import userStoreInjectable from "../../common/user-store/user-store.injectable";
import { beforeApplicationIsLoadingInjectionToken } from "../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
import initDefaultUpdateChannelInjectableInjectable from "../vars/default-update-channel/init.injectable";
@ -11,9 +12,13 @@ const initUserStoreInjectable = getInjectable({
id: "init-user-store",
instantiate: (di) => {
const userStore = di.inject(userStoreInjectable);
const userStoreFileNameMigration = di.inject(userStoreFileNameMigrationInjectable);
return {
run: () => userStore.load(),
run: async () => {
await userStoreFileNameMigration();
userStore.load();
},
runAfter: di.inject(initDefaultUpdateChannelInjectableInjectable),
};
},