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

Change: zodを使うように #1078

Merged
merged 25 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8a012b1
Change: electron-storeのコンフィグをzodに
sevenc-nanashi Dec 29, 2022
a402c22
Change: envのバリデーションをzodに
sevenc-nanashi Dec 29, 2022
8a5cec2
Fix: 細かいところを修正
sevenc-nanashi Dec 29, 2022
2fa2efb
Fix: defaultの修正漏れを修正
sevenc-nanashi Dec 29, 2022
9514063
Change: zodから型を取るように
sevenc-nanashi Dec 30, 2022
5624eb7
Improve: 型チェックでts-expect-errorを削除
sevenc-nanashi Jan 1, 2023
392469b
Fix: 動かなかったのを修正
sevenc-nanashi Jan 1, 2023
792126c
Fix: splitterPositionの型を修正
sevenc-nanashi Jan 1, 2023
6d10b74
Merge branch 'main' into poc/ajv-to-zod
sevenc-nanashi Jan 2, 2023
eb8b5a0
Code: envSchemaを移動
sevenc-nanashi Jan 2, 2023
3556e3b
Merge branch 'poc/ajv-to-zod' of github.com:sevenc-nanashi/voicevox i…
sevenc-nanashi Jan 2, 2023
e29b40f
Merge: main -> poc/ajv-to-zod
sevenc-nanashi Jan 2, 2023
1422e71
Merge: main -> poc/ajv-to-zod
sevenc-nanashi Jan 2, 2023
adfcd94
Merge: マージ忘れ
sevenc-nanashi Jan 2, 2023
48bd07e
Fix: editorFont忘れを修正
sevenc-nanashi Jan 3, 2023
71d142d
Fix: experimentalSetting忘れを修正
sevenc-nanashi Jan 3, 2023
c9f0427
Fix: 残りのDefault忘れを修正
sevenc-nanashi Jan 3, 2023
8638952
Change: 全てzodに
sevenc-nanashi Jan 3, 2023
79cee89
Update src/background.ts
sevenc-nanashi Jan 4, 2023
0de98bc
Update src/type/preload.ts
sevenc-nanashi Jan 4, 2023
f68923b
Code: コメントの位置を修正
sevenc-nanashi Jan 4, 2023
43ab084
Change: toolbarSettingSchemaを単一の型に
sevenc-nanashi Jan 4, 2023
70a381f
Fix: デフォルト値忘れを修正
sevenc-nanashi Jan 4, 2023
71f5327
Code: editorFontの位置を修正
sevenc-nanashi Jan 4, 2023
c3419e1
Update src/type/preload.ts
Hiroshiba Jan 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
297 changes: 11 additions & 286 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

import dotenv from "dotenv";
import Store from "electron-store";
import Store, { Schema } from "electron-store";

import {
app,
Expand All @@ -25,17 +25,21 @@ import {
HotkeySetting,
ThemeConf,
AcceptTermsStatus,
ToolbarSetting,
EngineInfo,
ElectronStoreType,
SystemError,
electronStoreSchema,
defaultHotkeySettings,
isMac,
defaultToolbarButtonSetting,
} from "./type/preload";

import log from "electron-log";
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;
Expand Down Expand Up @@ -92,293 +96,14 @@ 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 electronStoreJsonSchema = zodToJsonSchema(electronStoreSchema);
if (!("properties" in electronStoreJsonSchema)) {
throw new Error("electronStoreJsonSchema must be object");
}

// 設定ファイル
sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved
const store = new Store<ElectronStoreType>({
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: "engineDefault" }],
default: "engineDefault",
},
audioOutputDevice: { type: "string", default: "default" },
},
default: {
fileEncoding: "UTF-8",
fileNamePattern: "",
fixedExportEnabled: false,
avoidOverwrite: false,
fixedExportDir: "",
exportLab: false,
exportText: false,
outputStereo: false,
outputSamplingRate: "engineDefault",
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",
},
editorFont: {
anyOf: [{ const: "default" }, { const: "os" }],
},
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: electronStoreJsonSchema.properties as Schema<ElectronStoreType>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここのasを取るいい方法考えてみたのですが思いつきませんでした 😇
zodToJsonSchemaが型消しちゃうんですねぇ

migrations: {
">=0.13": (store) => {
// acceptTems -> acceptTerms
Expand Down
Loading