From 8a012b19f381ec6903946ea2384ce51415622df0 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 29 Dec 2022 11:10:29 +0900 Subject: [PATCH 01/21] =?UTF-8?q?Change:=20electron-store=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=95=E3=82=A3=E3=82=B0=E3=82=92zod?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 31 +++++- package.json | 4 +- src/background.ts | 269 ++++++++++++++-------------------------------- 3 files changed, 115 insertions(+), 189 deletions(-) diff --git a/package-lock.json b/package-lock.json index 29f69d6f25..39d1f770cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,9 @@ "vue": "3.0.11", "vue-router": "4.0.8", "vuedraggable": "4.1.0", - "vuex": "4.0.2" + "vuex": "4.0.2", + "zod": "3.20.2", + "zod-to-json-schema": "3.20.1" }, "devDependencies": { "@openapitools/openapi-generator-cli": "2.3.3", @@ -28055,6 +28057,22 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", "dev": true + }, + "node_modules/zod": { + "version": "3.20.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.20.2.tgz", + "integrity": "sha512-1MzNQdAvO+54H+EaK5YpyEy0T+Ejo/7YLHS93G3RnYWh5gaotGHwGeN/ZO687qEDU2y4CdStQYXVHIgrUl5UVQ==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.20.1", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.20.1.tgz", + "integrity": "sha512-U+zmNJUKqzv92E+LdEYv0g2LxBLks4HAwfC6cue8jXby5PAeSEPGO4xV9Sl4zmLYyFvJkm0FOfOs6orUO+AI1w==", + "peerDependencies": { + "zod": "^3.20.0" + } } }, "dependencies": { @@ -50198,6 +50216,17 @@ "dev": true } } + }, + "zod": { + "version": "3.20.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.20.2.tgz", + "integrity": "sha512-1MzNQdAvO+54H+EaK5YpyEy0T+Ejo/7YLHS93G3RnYWh5gaotGHwGeN/ZO687qEDU2y4CdStQYXVHIgrUl5UVQ==" + }, + "zod-to-json-schema": { + "version": "3.20.1", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.20.1.tgz", + "integrity": "sha512-U+zmNJUKqzv92E+LdEYv0g2LxBLks4HAwfC6cue8jXby5PAeSEPGO4xV9Sl4zmLYyFvJkm0FOfOs6orUO+AI1w==", + "requires": {} } } } diff --git a/package.json b/package.json index 55befa15e4..e89262aa49 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,9 @@ "vue": "3.0.11", "vue-router": "4.0.8", "vuedraggable": "4.1.0", - "vuex": "4.0.2" + "vuex": "4.0.2", + "zod": "3.20.2", + "zod-to-json-schema": "3.20.1" }, "devDependencies": { "@openapitools/openapi-generator-cli": "2.3.3", diff --git a/src/background.ts b/src/background.ts index e44d9f5177..4706d0d96d 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1,7 +1,7 @@ "use strict"; import dotenv from "dotenv"; -import Store from "electron-store"; +import Store, { Schema } from "electron-store"; import { app, @@ -19,6 +19,7 @@ import path from "path"; import { textEditContextMenu } from "./electron/contextMenu"; import { hasSupportedGpu } from "./electron/device"; import { ipcMainHandle, ipcMainSend } from "@/electron/ipc"; +import { z } from "zod"; import fs from "fs"; import { @@ -36,6 +37,7 @@ import dayjs from "dayjs"; import windowStateKeeper from "electron-window-state"; import EngineManager from "./background/engineManager"; import VvppManager from "./background/vvppManager"; +import zodToJsonSchema from "zod-to-json-schema"; type SingleInstanceLockData = { filePath: string | undefined; @@ -189,193 +191,86 @@ const defaultToolbarButtonSetting: ToolbarSetting = [ "UNDO", "REDO", ]; - // 設定ファイル const store = new Store({ - schema: { - useGpu: { - type: "boolean", - default: false, - }, - inheritAudioInfo: { - type: "boolean", - default: true, - }, - activePointScrollMode: { - type: "string", - enum: ["CONTINUOUSLY", "PAGE", "OFF"], - default: "OFF", - }, - savingSetting: { - type: "object", - properties: { - fileEncoding: { - type: "string", - enum: ["UTF-8", "Shift_JIS"], - default: "UTF-8", - }, - fileNamePattern: { - type: "string", - default: "", - }, - fixedExportEnabled: { type: "boolean", default: false }, - avoidOverwrite: { type: "boolean", default: false }, - fixedExportDir: { type: "string", default: "" }, - exportLab: { type: "boolean", default: false }, - exportText: { type: "boolean", default: false }, - outputStereo: { type: "boolean", default: false }, - outputSamplingRate: { - oneOf: [{ type: "number" }, { const: "default" }], - default: "default", - }, - audioOutputDevice: { type: "string", default: "default" }, - }, - default: { - fileEncoding: "UTF-8", - fileNamePattern: "", - fixedExportEnabled: false, - avoidOverwrite: false, - fixedExportDir: "", - exportLab: false, - exportText: false, - outputStereo: false, - outputSamplingRate: "default", - audioOutputDevice: "default", - splitTextWhenPaste: "PERIOD_AND_NEW_LINE", - }, - }, - // To future developers: if you are to modify the store schema with array type, - // for example, the hotkeySettings below, - // please remember to add a corresponding migration - // Learn more: https://github.com/sindresorhus/electron-store#migrations - hotkeySettings: { - type: "array", - items: { - type: "object", - properties: { - action: { type: "string" }, - combination: { type: "string" }, - }, - }, - default: defaultHotkeySettings, - }, - toolbarSetting: { - type: "array", - items: { - type: "string", - }, - default: defaultToolbarButtonSetting, - }, - userCharacterOrder: { - type: "array", - items: { - type: "string", - }, - default: [], - }, - defaultStyleIds: { - type: "array", - items: { - type: "object", - properties: { - speakerUuid: { type: "string" }, - defaultStyleId: { type: "number" }, - }, - }, - default: [], - }, - presets: { - type: "object", - properties: { - items: { - type: "object", - patternProperties: { - // uuid - "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}": { - type: "object", - properties: { - name: { type: "string" }, - speedScale: { type: "number" }, - pitchScale: { type: "number" }, - intonationScale: { type: "number" }, - volumeScale: { type: "number" }, - prePhonemeLength: { type: "number" }, - postPhonemeLength: { type: "number" }, - }, - }, - }, - additionalProperties: false, - }, - keys: { - type: "array", - items: { - type: "string", - pattern: - "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", - }, - }, - }, - default: { items: {}, keys: [] }, - }, - currentTheme: { - type: "string", - default: "Default", - }, - experimentalSetting: { - type: "object", - properties: { - enablePreset: { type: "boolean", default: false }, - enableInterrogativeUpspeak: { - type: "boolean", - default: false, - }, - }, - default: { - enablePreset: false, - enableInterrogativeUpspeak: false, - }, - }, - acceptRetrieveTelemetry: { - type: "string", - enum: ["Unconfirmed", "Accepted", "Refused"], - default: "Unconfirmed", - }, - acceptTerms: { - type: "string", - enum: ["Unconfirmed", "Accepted", "Rejected"], - default: "Unconfirmed", - }, - splitTextWhenPaste: { - type: "string", - enum: ["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"], - default: "PERIOD_AND_NEW_LINE", - }, - splitterPosition: { - type: "object", - properties: { - portraitPaneWidth: { type: "number" }, - audioInfoPaneWidth: { type: "number" }, - audioDetailPaneHeight: { type: "number" }, - }, - default: {}, - }, - confirmedTips: { - type: "object", - properties: { - tweakableSliderByScroll: { type: "boolean", default: false }, - }, - default: { - tweakableSliderByScroll: false, - }, - }, - engineDirs: { - type: "array", - items: { - type: "string", - }, - default: [], - }, - }, + schema: zodToJsonSchema( + z + .object({ + useGpu: z.boolean().default(false), + inheritAudioInfo: z.boolean().default(true), + activePointScrollMode: z + .enum(["CONTINUOUSLY", "PAGE", "OFF"]) + .default("OFF"), + savingSetting: z + .object({ + fileEncoding: z.enum(["UTF-8", "Shift_JIS"]).default("UTF-8"), + fileNamePattern: z.string().default(""), + fixedExportEnabled: z.boolean().default(false), + avoidOverwrite: z.boolean().default(false), + fixedExportDir: z.string().default(""), + exportLab: z.boolean().default(false), + exportText: z.boolean().default(false), + outputStereo: z.boolean().default(false), + outputSamplingRate: z + .union([z.number(), z.literal("engineDefault")]) + .default("engineDefault"), + audioOutputDevice: z.string().default(""), + }) + .passthrough(), // 別のブランチでの開発中の設定項目があるコンフィグが死ぬのを防ぐ + hotkeySettings: z + .object({ + action: z.string(), + combination: z.string(), + }) + .array() + .default(defaultHotkeySettings), + toolbarSetting: z.string().array().default(defaultToolbarButtonSetting), + userCharacterOrder: z.string().array(), + defaultStyleIds: z + .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) + .array(), + presets: z.object({ + items: z.record( + z.string().uuid(), + z.object({ + name: z.string(), + speedScale: z.number(), + pitchScale: z.number(), + intonationScale: z.number(), + volumeScale: z.number(), + prePhonemeLength: z.number(), + postPhonemeLength: z.number(), + }) + ), + keys: z.string().uuid().array(), + }), + currentTheme: z.string().default("Default"), + experimentalSetting: z.object({ + enablePreset: z.boolean().default(false), + enableInterrogativeUpspeak: z.boolean().default(false), + }), + acceptRetrieveTelemetry: z + .enum(["Unconfirmed", "Accepted", "Refused"]) + .default("Unconfirmed"), + acceptTerms: z + .enum(["Unconfirmed", "Accepted", "Refused"]) + .default("Unconfirmed"), + splitTextWhenPaste: z + .enum(["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"]) + .default("PERIOD_AND_NEW_LINE"), + splitterPosition: z.object({ + portraitPaneWidth: z.number().optional(), + audioInfoPaneWidth: z.number().optional(), + audioDetailPaneHeight: z.number().optional(), + }), + confirmedTips: z.object({ + tweakableSliderByScroll: z.boolean().default(false), + }), + engineDirs: z.string().array(), + }) + .passthrough() + // @ts-expect-error type: 'object'であることは確定している + ).properties as Schema, migrations: { ">=0.13": (store) => { // acceptTems -> acceptTerms @@ -392,7 +287,7 @@ const store = new Store({ ">=0.14": (store) => { // 24000 Hz -> "default" if (store.get("savingSetting").outputSamplingRate == 24000) { - store.set("savingSetting.outputSamplingRate", "default"); + store.set("savingSetting.outputSamplingRate", "engineDefault"); } }, }, From a402c2292f2df743524be8ae5f402729dd472ca6 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 29 Dec 2022 11:14:31 +0900 Subject: [PATCH 02/21] =?UTF-8?q?Change:=20env=E3=81=AE=E3=83=90=E3=83=AA?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92zod?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background/engineManager.ts | 37 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/background/engineManager.ts b/src/background/engineManager.ts index 936c6a8199..4352ed2816 100644 --- a/src/background/engineManager.ts +++ b/src/background/engineManager.ts @@ -16,7 +16,19 @@ import { } from "@/type/preload"; import log from "electron-log"; -import Ajv from "ajv/dist/jtd"; +import { z } from "zod"; + +const envSchema = z + .object({ + uuid: z.string().uuid(), + host: z.string(), + name: z.string(), + executionEnabled: z.boolean(), + executionFilePath: z.string(), + executionArgs: z.array(z.string()), + path: z.string().optional(), + }) + .array(); type MinimumEngineManifest = { name: string; @@ -38,28 +50,7 @@ function createDefaultEngineInfos(defaultEngineDir: string): EngineInfo[] { // TODO: envから直接ではなく、envに書いたengine_manifest.jsonから情報を得るようにする const defaultEngineInfosEnv = process.env.DEFAULT_ENGINE_INFOS ?? "[]"; - const envSchema = { - elements: { - properties: { - uuid: { type: "string" }, - host: { type: "string" }, - name: { type: "string" }, - executionEnabled: { type: "boolean" }, - executionFilePath: { type: "string" }, - executionArgs: { elements: { type: "string" } }, - }, - optionalProperties: { - path: { type: "string" }, - }, - }, - } as const; - const ajv = new Ajv(); - const validate = ajv.compile(envSchema); - - const engines = JSON.parse(defaultEngineInfosEnv); - if (!validate(engines)) { - throw validate.errors; - } + const engines = envSchema.parse(JSON.parse(defaultEngineInfosEnv)); return engines.map((engineInfo) => { return { From 8a5cec2364c9cb29fa8b066fc2fddb8ef30852a6 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 29 Dec 2022 12:39:00 +0900 Subject: [PATCH 03/21] =?UTF-8?q?Fix:=20=E7=B4=B0=E3=81=8B=E3=81=84?= =?UTF-8?q?=E3=81=A8=E3=81=93=E3=82=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/background.ts b/src/background.ts index 4706d0d96d..8762132592 100644 --- a/src/background.ts +++ b/src/background.ts @@ -216,7 +216,7 @@ const store = new Store({ .default("engineDefault"), audioOutputDevice: z.string().default(""), }) - .passthrough(), // 別のブランチでの開発中の設定項目があるコンフィグが死ぬのを防ぐ + .passthrough(), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ hotkeySettings: z .object({ action: z.string(), From 2fa2efba8c924d52018522ad4afbe73c8711270e Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 29 Dec 2022 20:59:20 +0900 Subject: [PATCH 04/21] =?UTF-8?q?Fix:=20default=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=BC=8F=E3=82=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/proxy.ts | 2 +- src/store/setting.ts | 2 +- src/store/type.ts | 2 +- src/type/preload.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/store/proxy.ts b/src/store/proxy.ts index 437c7877ad..2f16866edf 100644 --- a/src/store/proxy.ts +++ b/src/store/proxy.ts @@ -40,7 +40,7 @@ export const convertAudioQueryFromEditorToEngine = ( return { ...editorAudioQuery, outputSamplingRate: - editorAudioQuery.outputSamplingRate == "default" + editorAudioQuery.outputSamplingRate == "engineDefault" ? defaultOutputSamplingRate : editorAudioQuery.outputSamplingRate, }; diff --git a/src/store/setting.ts b/src/store/setting.ts index 95bf559591..0729300303 100644 --- a/src/store/setting.ts +++ b/src/store/setting.ts @@ -27,7 +27,7 @@ export const settingStoreState: SettingStoreState = { exportLab: false, exportText: false, outputStereo: false, - outputSamplingRate: "default", + outputSamplingRate: "engineDefault", audioOutputDevice: "default", }, hotkeySettings: [], diff --git a/src/store/type.ts b/src/store/type.ts index f87885aed1..1d5d43ded2 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -43,7 +43,7 @@ import { QVueGlobals } from "quasar"; * エディタ用のAudioQuery */ export type EditorAudioQuery = Omit & { - outputSamplingRate: number | "default"; + outputSamplingRate: number | "engineDefault"; }; // FIXME: SpeakerIdを追加する diff --git a/src/type/preload.ts b/src/type/preload.ts index 5ae94cd55b..ee70c23e85 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -168,7 +168,7 @@ export type SavingSetting = { avoidOverwrite: boolean; exportText: boolean; outputStereo: boolean; - outputSamplingRate: number | "default"; + outputSamplingRate: number | "engineDefault"; audioOutputDevice: string; }; From 95140636da4d2db3f77d8cef07539354917df242 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Fri, 30 Dec 2022 09:21:07 +0900 Subject: [PATCH 05/21] =?UTF-8?q?Change:=20zod=E3=81=8B=E3=82=89=E5=9E=8B?= =?UTF-8?q?=E3=82=92=E5=8F=96=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.ts | 183 ++-------------------------------------- src/type/preload.ts | 197 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 184 insertions(+), 196 deletions(-) diff --git a/src/background.ts b/src/background.ts index 8762132592..a308816e2b 100644 --- a/src/background.ts +++ b/src/background.ts @@ -19,17 +19,19 @@ import path from "path"; import { textEditContextMenu } from "./electron/contextMenu"; import { hasSupportedGpu } from "./electron/device"; import { ipcMainHandle, ipcMainSend } from "@/electron/ipc"; -import { z } from "zod"; import fs from "fs"; import { HotkeySetting, ThemeConf, AcceptTermsStatus, - ToolbarSetting, EngineInfo, ElectronStoreType, SystemError, + electronStoreSchema, + defaultHotkeySettings, + isMac, + defaultToolbarButtonSetting, } from "./type/preload"; import log from "electron-log"; @@ -94,183 +96,10 @@ protocol.registerSchemesAsPrivileged([ { scheme: "app", privileges: { secure: true, standard: true, stream: true } }, ]); -const isMac = process.platform === "darwin"; - -const defaultHotkeySettings: HotkeySetting[] = [ - { - action: "音声書き出し", - combination: !isMac ? "Ctrl E" : "Meta E", - }, - { - action: "一つだけ書き出し", - combination: "E", - }, - { - action: "音声を繋げて書き出し", - combination: "", - }, - { - action: "再生/停止", - combination: "Space", - }, - { - action: "連続再生/停止", - combination: "Shift Space", - }, - { - action: "アクセント欄を表示", - combination: "1", - }, - { - action: "イントネーション欄を表示", - combination: "2", - }, - { - action: "長さ欄を表示", - combination: "3", - }, - { - action: "テキスト欄を追加", - combination: "Shift Enter", - }, - { - action: "テキスト欄を削除", - combination: "Shift Delete", - }, - { - action: "テキスト欄からフォーカスを外す", - combination: "Escape", - }, - { - action: "テキスト欄にフォーカスを戻す", - combination: "Enter", - }, - { - action: "元に戻す", - combination: !isMac ? "Ctrl Z" : "Meta Z", - }, - { - action: "やり直す", - combination: !isMac ? "Ctrl Y" : "Shift Meta Z", - }, - { - action: "新規プロジェクト", - combination: !isMac ? "Ctrl N" : "Meta N", - }, - { - action: "プロジェクトを名前を付けて保存", - combination: !isMac ? "Ctrl Shift S" : "Shift Meta S", - }, - { - action: "プロジェクトを上書き保存", - combination: !isMac ? "Ctrl S" : "Meta S", - }, - { - action: "プロジェクト読み込み", - combination: !isMac ? "Ctrl O" : "Meta O", - }, - { - action: "テキスト読み込む", - combination: "", - }, - { - action: "全体のイントネーションをリセット", - combination: !isMac ? "Ctrl G" : "Meta G", - }, - { - action: "選択中のアクセント句のイントネーションをリセット", - combination: "R", - }, -]; - -const defaultToolbarButtonSetting: ToolbarSetting = [ - "PLAY_CONTINUOUSLY", - "STOP", - "EXPORT_AUDIO_ONE", - "EMPTY", - "UNDO", - "REDO", -]; // 設定ファイル const store = new Store({ - schema: zodToJsonSchema( - z - .object({ - useGpu: z.boolean().default(false), - inheritAudioInfo: z.boolean().default(true), - activePointScrollMode: z - .enum(["CONTINUOUSLY", "PAGE", "OFF"]) - .default("OFF"), - savingSetting: z - .object({ - fileEncoding: z.enum(["UTF-8", "Shift_JIS"]).default("UTF-8"), - fileNamePattern: z.string().default(""), - fixedExportEnabled: z.boolean().default(false), - avoidOverwrite: z.boolean().default(false), - fixedExportDir: z.string().default(""), - exportLab: z.boolean().default(false), - exportText: z.boolean().default(false), - outputStereo: z.boolean().default(false), - outputSamplingRate: z - .union([z.number(), z.literal("engineDefault")]) - .default("engineDefault"), - audioOutputDevice: z.string().default(""), - }) - .passthrough(), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ - hotkeySettings: z - .object({ - action: z.string(), - combination: z.string(), - }) - .array() - .default(defaultHotkeySettings), - toolbarSetting: z.string().array().default(defaultToolbarButtonSetting), - userCharacterOrder: z.string().array(), - defaultStyleIds: z - .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) - .array(), - presets: z.object({ - items: z.record( - z.string().uuid(), - z.object({ - name: z.string(), - speedScale: z.number(), - pitchScale: z.number(), - intonationScale: z.number(), - volumeScale: z.number(), - prePhonemeLength: z.number(), - postPhonemeLength: z.number(), - }) - ), - keys: z.string().uuid().array(), - }), - currentTheme: z.string().default("Default"), - experimentalSetting: z.object({ - enablePreset: z.boolean().default(false), - enableInterrogativeUpspeak: z.boolean().default(false), - }), - acceptRetrieveTelemetry: z - .enum(["Unconfirmed", "Accepted", "Refused"]) - .default("Unconfirmed"), - acceptTerms: z - .enum(["Unconfirmed", "Accepted", "Refused"]) - .default("Unconfirmed"), - splitTextWhenPaste: z - .enum(["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"]) - .default("PERIOD_AND_NEW_LINE"), - splitterPosition: z.object({ - portraitPaneWidth: z.number().optional(), - audioInfoPaneWidth: z.number().optional(), - audioDetailPaneHeight: z.number().optional(), - }), - confirmedTips: z.object({ - tweakableSliderByScroll: z.boolean().default(false), - }), - engineDirs: z.string().array(), - }) - .passthrough() - // @ts-expect-error type: 'object'であることは確定している - ).properties as Schema, + schema: zodToJsonSchema(electronStoreSchema) // @ts-expect-error type: 'object'であり、propertiesが存在することは確定している + .properties as Schema, migrations: { ">=0.13": (store) => { // acceptTems -> acceptTerms diff --git a/src/type/preload.ts b/src/type/preload.ts index ee70c23e85..128121afee 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -1,25 +1,184 @@ import { IpcRenderer, IpcRendererEvent } from "electron"; import { IpcSOData } from "./ipc"; - -export interface ElectronStoreType { - useGpu: boolean; - inheritAudioInfo: boolean; - activePointScrollMode: ActivePointScrollMode; - savingSetting: SavingSetting; - presets: PresetConfig; +import { z } from "zod"; + +export const isMac = process.platform === "darwin"; +export const defaultHotkeySettings: HotkeySetting[] = [ + { + action: "音声書き出し", + combination: !isMac ? "Ctrl E" : "Meta E", + }, + { + action: "一つだけ書き出し", + combination: "E", + }, + { + action: "音声を繋げて書き出し", + combination: "", + }, + { + action: "再生/停止", + combination: "Space", + }, + { + action: "連続再生/停止", + combination: "Shift Space", + }, + { + action: "アクセント欄を表示", + combination: "1", + }, + { + action: "イントネーション欄を表示", + combination: "2", + }, + { + action: "長さ欄を表示", + combination: "3", + }, + { + action: "テキスト欄を追加", + combination: "Shift Enter", + }, + { + action: "テキスト欄を削除", + combination: "Shift Delete", + }, + { + action: "テキスト欄からフォーカスを外す", + combination: "Escape", + }, + { + action: "テキスト欄にフォーカスを戻す", + combination: "Enter", + }, + { + action: "元に戻す", + combination: !isMac ? "Ctrl Z" : "Meta Z", + }, + { + action: "やり直す", + combination: !isMac ? "Ctrl Y" : "Shift Meta Z", + }, + { + action: "新規プロジェクト", + combination: !isMac ? "Ctrl N" : "Meta N", + }, + { + action: "プロジェクトを名前を付けて保存", + combination: !isMac ? "Ctrl Shift S" : "Shift Meta S", + }, + { + action: "プロジェクトを上書き保存", + combination: !isMac ? "Ctrl S" : "Meta S", + }, + { + action: "プロジェクト読み込み", + combination: !isMac ? "Ctrl O" : "Meta O", + }, + { + action: "テキスト読み込む", + combination: "", + }, + { + action: "全体のイントネーションをリセット", + combination: !isMac ? "Ctrl G" : "Meta G", + }, + { + action: "選択中のアクセント句のイントネーションをリセット", + combination: "R", + }, +]; + +export const defaultToolbarButtonSetting: ToolbarSetting = [ + "PLAY_CONTINUOUSLY", + "STOP", + "EXPORT_AUDIO_ONE", + "EMPTY", + "UNDO", + "REDO", +]; +export const electronStoreSchema = z + .object({ + useGpu: z.boolean().default(false), + inheritAudioInfo: z.boolean().default(true), + activePointScrollMode: z + .enum(["CONTINUOUSLY", "PAGE", "OFF"]) + .default("OFF"), + savingSetting: z + .object({ + fileEncoding: z.enum(["UTF-8", "Shift_JIS"]).default("UTF-8"), + fileNamePattern: z.string().default(""), + fixedExportEnabled: z.boolean().default(false), + avoidOverwrite: z.boolean().default(false), + fixedExportDir: z.string().default(""), + exportLab: z.boolean().default(false), + exportText: z.boolean().default(false), + outputStereo: z.boolean().default(false), + outputSamplingRate: z + .union([z.number(), z.literal("engineDefault")]) + .default("engineDefault"), + audioOutputDevice: z.string().default(""), + }) + .passthrough(), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ + hotkeySettings: z + .object({ + action: z.string(), + combination: z.string(), + }) + .array() + .default(defaultHotkeySettings), + toolbarSetting: z.string().array().default(defaultToolbarButtonSetting), + userCharacterOrder: z.string().array(), + defaultStyleIds: z + .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) + .array(), + presets: z.object({ + items: z.record( + z.string().uuid(), + z.object({ + name: z.string(), + speedScale: z.number(), + pitchScale: z.number(), + intonationScale: z.number(), + volumeScale: z.number(), + prePhonemeLength: z.number(), + postPhonemeLength: z.number(), + }) + ), + keys: z.string().uuid().array(), + }), + currentTheme: z.string().default("Default"), + experimentalSetting: z.object({ + enablePreset: z.boolean().default(false), + enableInterrogativeUpspeak: z.boolean().default(false), + }), + acceptRetrieveTelemetry: z + .enum(["Unconfirmed", "Accepted", "Refused"]) + .default("Unconfirmed"), + acceptTerms: z + .enum(["Unconfirmed", "Accepted", "Refused"]) + .default("Unconfirmed"), + splitTextWhenPaste: z + .enum(["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"]) + .default("PERIOD_AND_NEW_LINE"), + splitterPosition: z.object({ + portraitPaneWidth: z.number().optional(), + audioInfoPaneWidth: z.number().optional(), + audioDetailPaneHeight: z.number().optional(), + }), + confirmedTips: z.object({ + tweakableSliderByScroll: z.boolean().default(false), + }), + engineDirs: z.string().array(), + }) + .passthrough(); +export type ElectronStoreType = Omit< + z.infer, + "hotkeySettings" +> & { hotkeySettings: HotkeySetting[]; - toolbarSetting: ToolbarSetting; - userCharacterOrder: string[]; - defaultStyleIds: DefaultStyleId[]; - currentTheme: string; - experimentalSetting: ExperimentalSetting; - acceptRetrieveTelemetry: AcceptRetrieveTelemetryStatus; - acceptTerms: AcceptTermsStatus; - splitTextWhenPaste: SplitTextWhenPasteType; - splitterPosition: SplitterPosition; - confirmedTips: ConfirmedTips; - engineDirs: string[]; -} +}; export interface Sandbox { getAppInfos(): Promise; From 5624eb7760078f17b698f3b99680165566d42079 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sun, 1 Jan 2023 09:33:18 +0900 Subject: [PATCH 06/21] =?UTF-8?q?Improve:=20=E5=9E=8B=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=A7ts-expect-error=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/background.ts b/src/background.ts index a308816e2b..f99871082d 100644 --- a/src/background.ts +++ b/src/background.ts @@ -96,10 +96,17 @@ protocol.registerSchemesAsPrivileged([ { scheme: "app", privileges: { secure: true, standard: true, stream: true } }, ]); +const electronStoreJsonSchema = zodToJsonSchema( + electronStoreSchema, + "electron-store" +); +if (!("properties" in electronStoreJsonSchema)) { + throw new Error("electronStoreJsonSchema must be object"); +} + // 設定ファイル const store = new Store({ - schema: zodToJsonSchema(electronStoreSchema) // @ts-expect-error type: 'object'であり、propertiesが存在することは確定している - .properties as Schema, + schema: electronStoreJsonSchema.properties as Schema, migrations: { ">=0.13": (store) => { // acceptTems -> acceptTerms From 392469b46ea3b2315e1f8c809c0fca6daa3ed4ab Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sun, 1 Jan 2023 09:37:27 +0900 Subject: [PATCH 07/21] =?UTF-8?q?Fix:=20=E5=8B=95=E3=81=8B=E3=81=AA?= =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/background.ts b/src/background.ts index f99871082d..1defc27ad6 100644 --- a/src/background.ts +++ b/src/background.ts @@ -96,10 +96,7 @@ protocol.registerSchemesAsPrivileged([ { scheme: "app", privileges: { secure: true, standard: true, stream: true } }, ]); -const electronStoreJsonSchema = zodToJsonSchema( - electronStoreSchema, - "electron-store" -); +const electronStoreJsonSchema = zodToJsonSchema(electronStoreSchema); if (!("properties" in electronStoreJsonSchema)) { throw new Error("electronStoreJsonSchema must be object"); } From 792126c5ea598cd137a94e355e03222098c38450 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Sun, 1 Jan 2023 09:59:42 +0900 Subject: [PATCH 08/21] =?UTF-8?q?Fix:=20splitterPosition=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 128121afee..ba9cf530fb 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -157,15 +157,15 @@ export const electronStoreSchema = z .enum(["Unconfirmed", "Accepted", "Refused"]) .default("Unconfirmed"), acceptTerms: z - .enum(["Unconfirmed", "Accepted", "Refused"]) + .enum(["Unconfirmed", "Accepted", "Rejected"]) .default("Unconfirmed"), splitTextWhenPaste: z .enum(["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"]) .default("PERIOD_AND_NEW_LINE"), splitterPosition: z.object({ - portraitPaneWidth: z.number().optional(), - audioInfoPaneWidth: z.number().optional(), - audioDetailPaneHeight: z.number().optional(), + portraitPaneWidth: z.number().nullish(), + audioInfoPaneWidth: z.number().nullish(), + audioDetailPaneHeight: z.number().nullish(), }), confirmedTips: z.object({ tweakableSliderByScroll: z.boolean().default(false), @@ -173,11 +173,10 @@ export const electronStoreSchema = z engineDirs: z.string().array(), }) .passthrough(); -export type ElectronStoreType = Omit< - z.infer, - "hotkeySettings" -> & { +export type ElectronStoreType = z.infer & { hotkeySettings: HotkeySetting[]; + toolbarSetting: ToolbarSetting; + splitterPosition: SplitterPosition; }; export interface Sandbox { From eb8b5a0068a6838ede1aa4536366bf5962c8438b Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 3 Jan 2023 07:53:26 +0900 Subject: [PATCH 09/21] =?UTF-8?q?Code:=20envSchema=E3=82=92=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background/engineManager.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/background/engineManager.ts b/src/background/engineManager.ts index 4352ed2816..bb47cc4d83 100644 --- a/src/background/engineManager.ts +++ b/src/background/engineManager.ts @@ -18,18 +18,6 @@ import { import log from "electron-log"; import { z } from "zod"; -const envSchema = z - .object({ - uuid: z.string().uuid(), - host: z.string(), - name: z.string(), - executionEnabled: z.boolean(), - executionFilePath: z.string(), - executionArgs: z.array(z.string()), - path: z.string().optional(), - }) - .array(); - type MinimumEngineManifest = { name: string; uuid: string; @@ -50,6 +38,17 @@ function createDefaultEngineInfos(defaultEngineDir: string): EngineInfo[] { // TODO: envから直接ではなく、envに書いたengine_manifest.jsonから情報を得るようにする const defaultEngineInfosEnv = process.env.DEFAULT_ENGINE_INFOS ?? "[]"; + const envSchema = z + .object({ + uuid: z.string().uuid(), + host: z.string(), + name: z.string(), + executionEnabled: z.boolean(), + executionFilePath: z.string(), + executionArgs: z.array(z.string()), + path: z.string().optional(), + }) + .array(); const engines = envSchema.parse(JSON.parse(defaultEngineInfosEnv)); return engines.map((engineInfo) => { From adfcd941ac01d54f19fe2e060ba2f159e86313ca Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 3 Jan 2023 08:56:36 +0900 Subject: [PATCH 10/21] =?UTF-8?q?Merge:=20=E3=83=9E=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E5=BF=98=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/App.vue b/src/App.vue index 37c80bd1bf..8f4b23d863 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,6 +40,15 @@ export default defineComponent({ }, { immediate: true } ); + + // フォントの制御用パラメータを変更する + watch( + () => store.state.editorFont, + (editorFont) => { + document.body.setAttribute("data-editor-font", editorFont); + }, + { immediate: true } + ); }, }); From 48bd07ed1595f51969ec7ec7d37ce800718663f3 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 3 Jan 2023 09:48:45 +0900 Subject: [PATCH 11/21] =?UTF-8?q?Fix:=20editorFont=E5=BF=98=E3=82=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 1e384149fd..1f9e3051ee 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -120,7 +120,10 @@ export const electronStoreSchema = z .default("engineDefault"), audioOutputDevice: z.string().default(""), }) - .passthrough(), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ + .passthrough() + .default({}), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ + editorFont: z.enum(["default", "os"]).default("default"), + hotkeySettings: z .object({ action: z.string(), From 71d142d42908b63ee3ee92572a5701d37c5e1a87 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 3 Jan 2023 09:53:20 +0900 Subject: [PATCH 12/21] =?UTF-8?q?Fix:=20experimentalSetting=E5=BF=98?= =?UTF-8?q?=E3=82=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 1f9e3051ee..66752a3f64 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -155,10 +155,13 @@ export const electronStoreSchema = z keys: z.string().uuid().array().default([]), }), currentTheme: z.string().default("Default"), - experimentalSetting: z.object({ - enablePreset: z.boolean().default(false), - enableInterrogativeUpspeak: z.boolean().default(false), - }), + experimentalSetting: z + .object({ + enablePreset: z.boolean().default(false), + enableInterrogativeUpspeak: z.boolean().default(false), + }) + .passthrough() + .default({}), acceptRetrieveTelemetry: z .enum(["Unconfirmed", "Accepted", "Refused"]) .default("Unconfirmed"), From c9f0427df43a84e32654d22ddca63686d7b056da Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 3 Jan 2023 09:54:58 +0900 Subject: [PATCH 13/21] =?UTF-8?q?Fix:=20=E6=AE=8B=E3=82=8A=E3=81=AEDefault?= =?UTF-8?q?=E5=BF=98=E3=82=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 66752a3f64..938ce4c0f2 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -177,10 +177,14 @@ export const electronStoreSchema = z audioInfoPaneWidth: z.number().nullish(), audioDetailPaneHeight: z.number().nullish(), }) + .passthrough() + .default({}), + confirmedTips: z + .object({ + tweakableSliderByScroll: z.boolean().default(false), + }) + .passthrough() .default({}), - confirmedTips: z.object({ - tweakableSliderByScroll: z.boolean().default(false), - }), engineDirs: z.string().array().default([]), }) .passthrough(); From 86389526de0fd67ea9d590b8f570f173607d08e9 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 3 Jan 2023 10:09:01 +0900 Subject: [PATCH 14/21] =?UTF-8?q?Change:=20=E5=85=A8=E3=81=A6zod=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 269 +++++++++++++++++++++----------------------- 1 file changed, 130 insertions(+), 139 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 938ce4c0f2..919514e4be 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -98,101 +98,6 @@ export const defaultToolbarButtonSetting: ToolbarSetting = [ "UNDO", "REDO", ]; -export const electronStoreSchema = z - .object({ - useGpu: z.boolean().default(false), - inheritAudioInfo: z.boolean().default(true), - activePointScrollMode: z - .enum(["CONTINUOUSLY", "PAGE", "OFF"]) - .default("OFF"), - savingSetting: z - .object({ - fileEncoding: z.enum(["UTF-8", "Shift_JIS"]).default("UTF-8"), - fileNamePattern: z.string().default(""), - fixedExportEnabled: z.boolean().default(false), - avoidOverwrite: z.boolean().default(false), - fixedExportDir: z.string().default(""), - exportLab: z.boolean().default(false), - exportText: z.boolean().default(false), - outputStereo: z.boolean().default(false), - outputSamplingRate: z - .union([z.number(), z.literal("engineDefault")]) - .default("engineDefault"), - audioOutputDevice: z.string().default(""), - }) - .passthrough() - .default({}), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ - editorFont: z.enum(["default", "os"]).default("default"), - - hotkeySettings: z - .object({ - action: z.string(), - combination: z.string(), - }) - .array() - .default(defaultHotkeySettings), - toolbarSetting: z.string().array().default(defaultToolbarButtonSetting), - userCharacterOrder: z.string().array().default([]), - defaultStyleIds: z - .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) - .array() - .default([]), - presets: z.object({ - items: z - .record( - z.string().uuid(), - z.object({ - name: z.string(), - speedScale: z.number(), - pitchScale: z.number(), - intonationScale: z.number(), - volumeScale: z.number(), - prePhonemeLength: z.number(), - postPhonemeLength: z.number(), - }) - ) - .default({}), - keys: z.string().uuid().array().default([]), - }), - currentTheme: z.string().default("Default"), - experimentalSetting: z - .object({ - enablePreset: z.boolean().default(false), - enableInterrogativeUpspeak: z.boolean().default(false), - }) - .passthrough() - .default({}), - acceptRetrieveTelemetry: z - .enum(["Unconfirmed", "Accepted", "Refused"]) - .default("Unconfirmed"), - acceptTerms: z - .enum(["Unconfirmed", "Accepted", "Rejected"]) - .default("Unconfirmed"), - splitTextWhenPaste: z - .enum(["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"]) - .default("PERIOD_AND_NEW_LINE"), - splitterPosition: z - .object({ - portraitPaneWidth: z.number().nullish(), - audioInfoPaneWidth: z.number().nullish(), - audioDetailPaneHeight: z.number().nullish(), - }) - .passthrough() - .default({}), - confirmedTips: z - .object({ - tweakableSliderByScroll: z.boolean().default(false), - }) - .passthrough() - .default({}), - engineDirs: z.string().array().default([]), - }) - .passthrough(); -export type ElectronStoreType = z.infer & { - hotkeySettings: HotkeySetting[]; - toolbarSetting: ToolbarSetting; - splitterPosition: SplitterPosition; -}; export interface Sandbox { getAppInfos(): Promise; @@ -353,11 +258,6 @@ export type DefaultStyleId = { defaultStyleId: number; }; -export type HotkeySetting = { - action: HotkeyAction; - combination: HotkeyCombo; -}; - export type EngineInfo = { uuid: string; host: string; @@ -387,50 +287,62 @@ export type PresetConfig = { items: Record; keys: string[]; }; -export type HotkeyAction = - | "音声書き出し" - | "一つだけ書き出し" - | "音声を繋げて書き出し" - | "再生/停止" - | "連続再生/停止" - | "アクセント欄を表示" - | "イントネーション欄を表示" - | "長さ欄を表示" - | "テキスト欄を追加" - | "テキスト欄を削除" - | "テキスト欄からフォーカスを外す" - | "テキスト欄にフォーカスを戻す" - | "元に戻す" - | "やり直す" - | "新規プロジェクト" - | "プロジェクトを名前を付けて保存" - | "プロジェクトを上書き保存" - | "プロジェクト読み込み" - | "テキスト読み込む" - | "全体のイントネーションをリセット" - | "選択中のアクセント句のイントネーションをリセット"; +export const hotkeyActionSchema = z.enum([ + "音声書き出し", + "一つだけ書き出し", + "音声を繋げて書き出し", + "再生/停止", + "連続再生/停止", + "アクセント欄を表示", + "イントネーション欄を表示", + "長さ欄を表示", + "テキスト欄を追加", + "テキスト欄を削除", + "テキスト欄からフォーカスを外す", + "テキスト欄にフォーカスを戻す", + "元に戻す", + "やり直す", + "新規プロジェクト", + "プロジェクトを名前を付けて保存", + "プロジェクトを上書き保存", + "プロジェクト読み込み", + "テキスト読み込む", + "全体のイントネーションをリセット", + "選択中のアクセント句のイントネーションをリセット", +]); + +export type HotkeyAction = z.infer; export type HotkeyCombo = string; +export const hotkeySettingSchema = z.object({ + action: hotkeyActionSchema, + combination: z.string(), +}); +export type HotkeySetting = z.infer; + export type HotkeyReturnType = | void | boolean | Promise | Promise; -export type ToolbarButtonTagType = - | "PLAY_CONTINUOUSLY" - | "STOP" - | "EXPORT_AUDIO_ONE" - | "EXPORT_AUDIO_ALL" - | "EXPORT_AUDIO_CONNECT_ALL" - | "SAVE_PROJECT" - | "UNDO" - | "REDO" - | "IMPORT_TEXT" - | "EMPTY"; +export const toolbarButtonTagSchema = z.enum([ + "PLAY_CONTINUOUSLY", + "STOP", + "EXPORT_AUDIO_ONE", + "EXPORT_AUDIO_ALL", + "EXPORT_AUDIO_CONNECT_ALL", + "SAVE_PROJECT", + "UNDO", + "REDO", + "IMPORT_TEXT", + "EMPTY", +]); +export type ToolbarButtonTagType = z.infer; -export type ToolbarSetting = ToolbarButtonTagType[]; +export const toolbarSettingSchema = toolbarButtonTagSchema.array(); +export type ToolbarSetting = z.infer; export type MoraDataType = | "consonant" @@ -472,15 +384,94 @@ export type ExperimentalSetting = { enableInterrogativeUpspeak: boolean; }; -export type SplitterPosition = { - portraitPaneWidth: number | undefined; - audioInfoPaneWidth: number | undefined; - audioDetailPaneHeight: number | undefined; -}; +export const splitterPositionSchema = z.object({ + portraitPaneWidth: z.number().optional(), + audioInfoPaneWidth: z.number().optional(), + audioDetailPaneHeight: z.number().optional(), +}); +export type SplitterPosition = z.infer; export type ConfirmedTips = { tweakableSliderByScroll: boolean; }; +export const electronStoreSchema = z + .object({ + useGpu: z.boolean().default(false), + inheritAudioInfo: z.boolean().default(true), + activePointScrollMode: z + .enum(["CONTINUOUSLY", "PAGE", "OFF"]) + .default("OFF"), + savingSetting: z + .object({ + fileEncoding: z.enum(["UTF-8", "Shift_JIS"]).default("UTF-8"), + fileNamePattern: z.string().default(""), + fixedExportEnabled: z.boolean().default(false), + avoidOverwrite: z.boolean().default(false), + fixedExportDir: z.string().default(""), + exportLab: z.boolean().default(false), + exportText: z.boolean().default(false), + outputStereo: z.boolean().default(false), + outputSamplingRate: z + .union([z.number(), z.literal("engineDefault")]) + .default("engineDefault"), + audioOutputDevice: z.string().default(""), + }) + .passthrough() + .default({}), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ + editorFont: z.enum(["default", "os"]).default("default"), + + hotkeySettings: hotkeySettingSchema.array().default(defaultHotkeySettings), + toolbarSetting: toolbarSettingSchema.default(defaultToolbarButtonSetting), + userCharacterOrder: z.string().array().default([]), + defaultStyleIds: z + .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) + .array() + .default([]), + presets: z.object({ + items: z + .record( + z.string().uuid(), + z.object({ + name: z.string(), + speedScale: z.number(), + pitchScale: z.number(), + intonationScale: z.number(), + volumeScale: z.number(), + prePhonemeLength: z.number(), + postPhonemeLength: z.number(), + }) + ) + .default({}), + keys: z.string().uuid().array().default([]), + }), + currentTheme: z.string().default("Default"), + experimentalSetting: z + .object({ + enablePreset: z.boolean().default(false), + enableInterrogativeUpspeak: z.boolean().default(false), + }) + .passthrough() + .default({}), + acceptRetrieveTelemetry: z + .enum(["Unconfirmed", "Accepted", "Refused"]) + .default("Unconfirmed"), + acceptTerms: z + .enum(["Unconfirmed", "Accepted", "Rejected"]) + .default("Unconfirmed"), + splitTextWhenPaste: z + .enum(["PERIOD_AND_NEW_LINE", "NEW_LINE", "OFF"]) + .default("PERIOD_AND_NEW_LINE"), + splitterPosition: splitterPositionSchema.default({}), + confirmedTips: z + .object({ + tweakableSliderByScroll: z.boolean().default(false), + }) + .passthrough() + .default({}), + engineDirs: z.string().array().default([]), + }) + .passthrough(); +export type ElectronStoreType = z.infer; // workaround. SystemError(https://nodejs.org/api/errors.html#class-systemerror)が2022/05/19時点ではNodeJSの型定義に記述されていないためこれを追加しています。 export class SystemError extends Error { From 79cee893287751163a062565a131068e0bab7759 Mon Sep 17 00:00:00 2001 From: Nanashi Date: Thu, 5 Jan 2023 07:26:39 +0900 Subject: [PATCH 15/21] Update src/background.ts Co-authored-by: Hiroshiba --- src/background.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/background.ts b/src/background.ts index cfbf941927..559c12d2e5 100644 --- a/src/background.ts +++ b/src/background.ts @@ -96,12 +96,11 @@ protocol.registerSchemesAsPrivileged([ { scheme: "app", privileges: { secure: true, standard: true, stream: true } }, ]); +// 設定ファイル const electronStoreJsonSchema = zodToJsonSchema(electronStoreSchema); if (!("properties" in electronStoreJsonSchema)) { throw new Error("electronStoreJsonSchema must be object"); } - -// 設定ファイル const store = new Store({ schema: electronStoreJsonSchema.properties as Schema, migrations: { From 0de98bc438b857fcc07eab2fd7cff3b11e809ad0 Mon Sep 17 00:00:00 2001 From: Nanashi Date: Thu, 5 Jan 2023 07:29:37 +0900 Subject: [PATCH 16/21] Update src/type/preload.ts Co-authored-by: Hiroshiba --- src/type/preload.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/type/preload.ts b/src/type/preload.ts index 919514e4be..72bf4cea45 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -3,6 +3,7 @@ import { IpcSOData } from "./ipc"; import { z } from "zod"; export const isMac = process.platform === "darwin"; +// ホットキーを追加したときは設定のマイグレーションが必要 export const defaultHotkeySettings: HotkeySetting[] = [ { action: "音声書き出し", From f68923b4ed75aff71ab9a6674c2ed4ce27844170 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 5 Jan 2023 08:42:42 +0900 Subject: [PATCH 17/21] =?UTF-8?q?Code:=20=E3=82=B3=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 72bf4cea45..72283a20e1 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -417,8 +417,8 @@ export const electronStoreSchema = z .default("engineDefault"), audioOutputDevice: z.string().default(""), }) - .passthrough() - .default({}), // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ + .passthrough() // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ + .default({}), editorFont: z.enum(["default", "os"]).default("default"), hotkeySettings: hotkeySettingSchema.array().default(defaultHotkeySettings), From 43ab084ca3fd4b2ea294478dff942f696ae9eedc Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 5 Jan 2023 08:43:40 +0900 Subject: [PATCH 18/21] =?UTF-8?q?Change:=20toolbarSettingSchema=E3=82=92?= =?UTF-8?q?=E5=8D=98=E4=B8=80=E3=81=AE=E5=9E=8B=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 72283a20e1..fe4909e4d1 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -342,8 +342,8 @@ export const toolbarButtonTagSchema = z.enum([ ]); export type ToolbarButtonTagType = z.infer; -export const toolbarSettingSchema = toolbarButtonTagSchema.array(); -export type ToolbarSetting = z.infer; +export const toolbarSettingSchema = toolbarButtonTagSchema; +export type ToolbarSetting = z.infer[]; export type MoraDataType = | "consonant" @@ -422,7 +422,9 @@ export const electronStoreSchema = z editorFont: z.enum(["default", "os"]).default("default"), hotkeySettings: hotkeySettingSchema.array().default(defaultHotkeySettings), - toolbarSetting: toolbarSettingSchema.default(defaultToolbarButtonSetting), + toolbarSetting: toolbarSettingSchema + .array() + .default(defaultToolbarButtonSetting), userCharacterOrder: z.string().array().default([]), defaultStyleIds: z .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) From 70a381f137fd69d5fdcf41c18c67a9a1a93f58f8 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 5 Jan 2023 08:44:20 +0900 Subject: [PATCH 19/21] =?UTF-8?q?Fix:=20=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E5=80=A4=E5=BF=98=E3=82=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index fe4909e4d1..3e7f438ba8 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -430,23 +430,25 @@ export const electronStoreSchema = z .object({ speakerUuid: z.string(), defaultStyleId: z.number() }) .array() .default([]), - presets: z.object({ - items: z - .record( - z.string().uuid(), - z.object({ - name: z.string(), - speedScale: z.number(), - pitchScale: z.number(), - intonationScale: z.number(), - volumeScale: z.number(), - prePhonemeLength: z.number(), - postPhonemeLength: z.number(), - }) - ) - .default({}), - keys: z.string().uuid().array().default([]), - }), + presets: z + .object({ + items: z + .record( + z.string().uuid(), + z.object({ + name: z.string(), + speedScale: z.number(), + pitchScale: z.number(), + intonationScale: z.number(), + volumeScale: z.number(), + prePhonemeLength: z.number(), + postPhonemeLength: z.number(), + }) + ) + .default({}), + keys: z.string().uuid().array().default([]), + }) + .default({}), currentTheme: z.string().default("Default"), experimentalSetting: z .object({ From 71f53270024898e402024541ec9d674e0e867245 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 5 Jan 2023 08:45:37 +0900 Subject: [PATCH 20/21] =?UTF-8?q?Code:=20editorFont=E3=81=AE=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/type/preload.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 3e7f438ba8..7f16dd0ec4 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -419,8 +419,6 @@ export const electronStoreSchema = z }) .passthrough() // 別のブランチでの開発中の設定項目があるコンフィグで死ぬのを防ぐ .default({}), - editorFont: z.enum(["default", "os"]).default("default"), - hotkeySettings: hotkeySettingSchema.array().default(defaultHotkeySettings), toolbarSetting: toolbarSettingSchema .array() @@ -450,6 +448,7 @@ export const electronStoreSchema = z }) .default({}), currentTheme: z.string().default("Default"), + editorFont: z.enum(["default", "os"]).default("default"), experimentalSetting: z .object({ enablePreset: z.boolean().default(false), From c3419e15f68460099c1459e01859a5ecaf163ad2 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 14 Jan 2023 05:34:35 +0900 Subject: [PATCH 21/21] Update src/type/preload.ts --- src/type/preload.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/type/preload.ts b/src/type/preload.ts index 7f16dd0ec4..a6059cc599 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -474,7 +474,7 @@ export const electronStoreSchema = z .default({}), engineDirs: z.string().array().default([]), }) - .passthrough(); + .passthrough(); // release-0.14直前で消す export type ElectronStoreType = z.infer; // workaround. SystemError(https://nodejs.org/api/errors.html#class-systemerror)が2022/05/19時点ではNodeJSの型定義に記述されていないためこれを追加しています。