diff --git a/package-lock.json b/package-lock.json index b9b4e12bf3..6da39e115c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "electron-window-state": "5.0.3", "encoding-japanese": "1.0.30", "fast-array-diff": "1.1.0", + "fast-base64": "0.1.8", "glob": "8.0.3", "hotkeys-js": "3.13.6", "immer": "9.0.21", @@ -6613,6 +6614,11 @@ "resolved": "https://registry.npmjs.org/fast-array-diff/-/fast-array-diff-1.1.0.tgz", "integrity": "sha512-muSPyZa/yHCoDQhah9th57AmLENB1nekbrUoLAqOpQXdl1Kw8VbH24Syl5XLscaQJlx7KRU95bfTDPvVB5BJvw==" }, + "node_modules/fast-base64": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/fast-base64/-/fast-base64-0.1.8.tgz", + "integrity": "sha512-LICiPjlLyh7/P3gcJYDjKEIX41odzqny1VHSnPsAlBb/zcSJJPYrSNHs54e2TytDRTwHZl7KG5c33IMLdT+9Eg==" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", diff --git a/package.json b/package.json index 6ba653859c..72c281c52b 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "electron-window-state": "5.0.3", "encoding-japanese": "1.0.30", "fast-array-diff": "1.1.0", + "fast-base64": "0.1.8", "glob": "8.0.3", "immer": "9.0.21", "markdown-it": "13.0.2", diff --git a/src/@types/fast-base64.d.ts b/src/@types/fast-base64.d.ts new file mode 100644 index 0000000000..a52a07fa05 --- /dev/null +++ b/src/@types/fast-base64.d.ts @@ -0,0 +1,5 @@ +// fast-base64の型定義が壊れているので、ここで型定義を追加する。 +declare module "fast-base64" { + export function toBytes(base64: string): Promise; + export function toBase64(bytes: Uint8Array): Promise; +} diff --git a/src/backend/electron/electronConfig.ts b/src/backend/electron/electronConfig.ts index 06678ebf93..57219548a4 100644 --- a/src/backend/electron/electronConfig.ts +++ b/src/backend/electron/electronConfig.ts @@ -1,6 +1,7 @@ import { join } from "path"; import fs from "fs"; import { app } from "electron"; +import { moveFile } from "move-file"; import { BaseConfigManager, Metadata } from "@/backend/common/ConfigManager"; import { ConfigType } from "@/type/preload"; @@ -21,10 +22,16 @@ export class ElectronConfigManager extends BaseConfigManager { } protected async save(config: ConfigType & Metadata) { + // ファイル書き込みに失敗したときに設定が消えないように、tempファイル書き込み後上書き移動する + const temp_path = `${this.configPath}.tmp`; await fs.promises.writeFile( - this.configPath, + temp_path, JSON.stringify(config, undefined, 2), ); + + await moveFile(temp_path, this.configPath, { + overwrite: true, + }); } private get configPath(): string { diff --git a/src/components/CharacterButton.vue b/src/components/CharacterButton.vue index 3e49c5f91a..2ca2304b50 100644 --- a/src/components/CharacterButton.vue +++ b/src/components/CharacterButton.vue @@ -196,11 +196,11 @@