Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron-storeのマイグレーション処理を自前で行う #1122

Closed
Hiroshiba opened this issue Jan 18, 2023 · 1 comment
Closed

electron-storeのマイグレーション処理を自前で行う #1122

Hiroshiba opened this issue Jan 18, 2023 · 1 comment

Comments

@Hiroshiba
Copy link
Member

Hiroshiba commented Jan 18, 2023

内容

electron-storeのマイグレーションは、まず過去のjsonオブジェクトを現在のjsonスキーマでバリデーションする仕様になっています。

この影響で、過去のjsonオブジェクトが現在のjsonスキーマに合わなかった場合、マイグレーション前にエラーが出ます。

なので、設定ファイルのマイグレーションはelectron-storeに頼らず、jsonオブジェクトを更新する形で自前実装したほうが楽になりそうです。

Pros 良くなる点

electron-storeの仕様に付き合わなくて良くなる

Cons 悪くなる点

自前実装が必要

実現方法

プロジェクトファイルのマイグレーションと同じ流れになりそうです。
こんな感じで、semverでsatisfyしてobjを書き換えるだけで良いかなと思います。

if (
semver.satisfies(projectAppVersion, "<0.4", semverSatisfiesOptions)
) {
for (const audioItemsKey in obj.audioItems) {
if ("charactorIndex" in obj.audioItems[audioItemsKey]) {
obj.audioItems[audioItemsKey].characterIndex =
obj.audioItems[audioItemsKey].charactorIndex;
delete obj.audioItems[audioItemsKey].charactorIndex;
}
}
for (const audioItemsKey in obj.audioItems) {
if (obj.audioItems[audioItemsKey].query != null) {
obj.audioItems[audioItemsKey].query.volumeScale = 1;
obj.audioItems[audioItemsKey].query.prePhonemeLength = 0.1;
obj.audioItems[audioItemsKey].query.postPhonemeLength = 0.1;
obj.audioItems[audioItemsKey].query.outputSamplingRate =
DEFAULT_SAMPLING_RATE;
}
}
}

問題としては、たしかelectron-storeは設定jsonオブジェクトを受け取れないはずです。
勝手にconfig.jsonを読み込むので、どのタイミングでどうやってマイグレーションした結果を反映すれば良いのかが若干見えないでいます。
(いっそelectron-storeから脱却したほうが良いかも・・・?)

@Hiroshiba
Copy link
Member Author

こちらのプルリクエストで解決しました!(thx @sevenc-nanashi !!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant