Skip to content

Commit

Permalink
Change: zodを使うように (#1078)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroshiba <[email protected]>
close undefined
  • Loading branch information
sevenc-nanashi authored Jan 13, 2023
1 parent 2830cc0 commit 64863fc
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 378 deletions.
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.2.45",
"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
298 changes: 11 additions & 287 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 @@ -100,293 +104,13 @@ 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");
}
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>,
migrations: {
">=0.13": (store) => {
// acceptTems -> acceptTerms
Expand Down
Loading

0 comments on commit 64863fc

Please sign in to comment.