Skip to content

Commit

Permalink
fix: config.json の validation 失敗時にわかりやすいログを出すように (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
raa0121 authored Feb 23, 2023
1 parent 13a268c commit eb11467
Showing 1 changed file with 58 additions and 46 deletions.
104 changes: 58 additions & 46 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,55 +125,67 @@ const electronStoreJsonSchema = zodToJsonSchema(electronStoreSchema);
if (!("properties" in electronStoreJsonSchema)) {
throw new Error("electronStoreJsonSchema must be object");
}
const store = new Store<ElectronStoreType>({
schema: electronStoreJsonSchema.properties as Schema<ElectronStoreType>,
migrations: {
">=0.13": (store) => {
// acceptTems -> acceptTerms
const prevIdentifier = "acceptTems";
const prevValue = store.get(prevIdentifier, undefined) as
| AcceptTermsStatus
| undefined;
if (prevValue) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
store.delete(prevIdentifier as any);
store.set("acceptTerms", prevValue);
}
},
">=0.14": (store) => {
// FIXME: できるならEngineManagerからEnginIDを取得したい
if (process.env.DEFAULT_ENGINE_INFOS == undefined)
throw new Error("DEFAULT_ENGINE_INFOS == undefined");
const engineId = EngineId(
JSON.parse(process.env.DEFAULT_ENGINE_INFOS)[0].uuid
);
if (engineId == undefined)
throw new Error("DEFAULT_ENGINE_INFOS[0].uuid == undefined");
const prevDefaultStyleIds = store.get("defaultStyleIds");
store.set(
"defaultStyleIds",
prevDefaultStyleIds.map((defaultStyle) => ({
engineId,
speakerUuid: defaultStyle.speakerUuid,
defaultStyleId: defaultStyle.defaultStyleId,
}))
);
let store: Store<ElectronStoreType>;
try {
store = new Store<ElectronStoreType>({
schema: electronStoreJsonSchema.properties as Schema<ElectronStoreType>,
migrations: {
">=0.13": (store) => {
// acceptTems -> acceptTerms
const prevIdentifier = "acceptTems";
const prevValue = store.get(prevIdentifier, undefined) as
| AcceptTermsStatus
| undefined;
if (prevValue) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
store.delete(prevIdentifier as any);
store.set("acceptTerms", prevValue);
}
},
">=0.14": (store) => {
// FIXME: できるならEngineManagerからEnginIDを取得したい
if (process.env.DEFAULT_ENGINE_INFOS == undefined)
throw new Error("DEFAULT_ENGINE_INFOS == undefined");
const engineId = EngineId(
JSON.parse(process.env.DEFAULT_ENGINE_INFOS)[0].uuid
);
if (engineId == undefined)
throw new Error("DEFAULT_ENGINE_INFOS[0].uuid == undefined");
const prevDefaultStyleIds = store.get("defaultStyleIds");
store.set(
"defaultStyleIds",
prevDefaultStyleIds.map((defaultStyle) => ({
engineId,
speakerUuid: defaultStyle.speakerUuid,
defaultStyleId: defaultStyle.defaultStyleId,
}))
);

const outputSamplingRate: number =
const outputSamplingRate: number =
// @ts-expect-error 削除されたパラメータ。
store.get("savingSetting").outputSamplingRate;
store.set(`engineSettings.${engineId}`, {
useGpu: store.get("useGpu"),
outputSamplingRate:
outputSamplingRate === 24000 ? "engineDefault" : outputSamplingRate,
});
// @ts-expect-error 削除されたパラメータ。
store.get("savingSetting").outputSamplingRate;
store.set(`engineSettings.${engineId}`, {
useGpu: store.get("useGpu"),
outputSamplingRate:
outputSamplingRate === 24000 ? "engineDefault" : outputSamplingRate,
});
// @ts-expect-error 削除されたパラメータ。
store.delete("savingSetting.outputSamplingRate");
// @ts-expect-error 削除されたパラメータ。
store.delete("useGpu");
store.delete("savingSetting.outputSamplingRate");
// @ts-expect-error 削除されたパラメータ。
store.delete("useGpu");
},
},
},
});
});
} catch (e) {
dialog.showErrorBox(
"設定ファイルの読み込みに失敗しました。",
`${app.getPath(
"userData"
)} にある config.json の名前を変えることで解決することがあります(ただし設定がすべてリセットされます)。`
);
app.exit(1);
throw e;
}

// engine
const vvppEngineDir = path.join(app.getPath("userData"), "vvpp-engines");
Expand Down

0 comments on commit eb11467

Please sign in to comment.