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:
parent
d262b15cdd
commit
8a90c230be
@ -9,26 +9,30 @@ import directoryForUserDataInjectable from "../app-paths/directory-for-user-data
|
|||||||
import { isErrnoException } from "../utils";
|
import { isErrnoException } from "../utils";
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
|
export type UserStoreFileNameMigration = () => Promise<void>;
|
||||||
|
|
||||||
const userStoreFileNameMigrationInjectable = getInjectable({
|
const userStoreFileNameMigrationInjectable = getInjectable({
|
||||||
id: "user-store-file-name-migration",
|
id: "user-store-file-name-migration",
|
||||||
instantiate: (di) => {
|
instantiate: (di): UserStoreFileNameMigration => {
|
||||||
const userDataPath = di.inject(directoryForUserDataInjectable);
|
const userDataPath = di.inject(directoryForUserDataInjectable);
|
||||||
const configJsonPath = path.join(userDataPath, "config.json");
|
const configJsonPath = path.join(userDataPath, "config.json");
|
||||||
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
||||||
|
|
||||||
try {
|
return async () => {
|
||||||
fse.moveSync(configJsonPath, lensUserStoreJsonPath);
|
try {
|
||||||
} catch (error) {
|
await fse.move(configJsonPath, lensUserStoreJsonPath);
|
||||||
if (error instanceof Error && error.message === "dest already exists.") {
|
} catch (error) {
|
||||||
fse.removeSync(configJsonPath);
|
if (error instanceof Error && error.message === "dest already exists.") {
|
||||||
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
await fse.remove(configJsonPath);
|
||||||
// (No such file or directory)
|
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
||||||
return; // file already moved
|
// (No such file or directory)
|
||||||
} else {
|
return; // file already moved
|
||||||
// pass other errors along
|
} else {
|
||||||
throw error;
|
// pass other errors along
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { ipcMain } from "electron";
|
|
||||||
import userStoreFileNameMigrationInjectable from "./file-name-migration.injectable";
|
|
||||||
import { UserStore } from "./user-store";
|
import { UserStore } from "./user-store";
|
||||||
import selectedUpdateChannelInjectable from "../application-update/selected-update-channel/selected-update-channel.injectable";
|
import selectedUpdateChannelInjectable from "../application-update/selected-update-channel/selected-update-channel.injectable";
|
||||||
|
|
||||||
@ -14,10 +12,6 @@ const userStoreInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
UserStore.resetInstance();
|
UserStore.resetInstance();
|
||||||
|
|
||||||
if (ipcMain) {
|
|
||||||
di.inject(userStoreFileNameMigrationInjectable);
|
|
||||||
}
|
|
||||||
|
|
||||||
return UserStore.createInstance({
|
return UserStore.createInstance({
|
||||||
selectedUpdateChannel: di.inject(selectedUpdateChannelInjectable),
|
selectedUpdateChannel: di.inject(selectedUpdateChannelInjectable),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
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 userStoreInjectable from "../../common/user-store/user-store.injectable";
|
||||||
import { beforeApplicationIsLoadingInjectionToken } from "../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
import { beforeApplicationIsLoadingInjectionToken } from "../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||||
import initDefaultUpdateChannelInjectableInjectable from "../vars/default-update-channel/init.injectable";
|
import initDefaultUpdateChannelInjectableInjectable from "../vars/default-update-channel/init.injectable";
|
||||||
@ -11,9 +12,13 @@ const initUserStoreInjectable = getInjectable({
|
|||||||
id: "init-user-store",
|
id: "init-user-store",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const userStore = di.inject(userStoreInjectable);
|
const userStore = di.inject(userStoreInjectable);
|
||||||
|
const userStoreFileNameMigration = di.inject(userStoreFileNameMigrationInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
run: () => userStore.load(),
|
run: async () => {
|
||||||
|
await userStoreFileNameMigration();
|
||||||
|
userStore.load();
|
||||||
|
},
|
||||||
runAfter: di.inject(initDefaultUpdateChannelInjectableInjectable),
|
runAfter: di.inject(initDefaultUpdateChannelInjectableInjectable),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user