Skip to content

Commit

Permalink
リファクタリング、ホットキー周りの初期値などをdomainに切り出す
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Nov 18, 2024
1 parent fee6a45 commit 53f154f
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 203 deletions.
6 changes: 4 additions & 2 deletions src/backend/browser/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import {
import { getConfigManager } from "./browserConfig";
import { IpcSOData } from "@/type/ipc";
import {
defaultHotkeySettings,
defaultToolbarButtonSetting,
EngineId,
EngineSettingType,
EngineSettings,
HotkeySettingType,
Sandbox,
} from "@/type/preload";
import { AssetTextFileNames } from "@/type/staticResources";
import {
HotkeySettingType,
defaultHotkeySettings,
} from "@/domain/hotkeyAction";

const toStaticPath = (fileName: string) =>
`${import.meta.env.BASE_URL}/${fileName}`.replaceAll(/\/\/+/g, "/");
Expand Down
8 changes: 5 additions & 3 deletions src/backend/common/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import {
ConfigType,
configSchema,
DefaultStyleId,
defaultHotkeySettings,
HotkeySettingType,
ExperimentalSettingType,
HotkeyCombination,
VoiceId,
PresetKey,
} from "@/type/preload";
import { ensureNotNullish } from "@/helpers/errorHelper";
import { loadEnvEngineInfos } from "@/domain/defaultEngine/envEngineInfo";
import {
HotkeyCombination,
defaultHotkeySettings,
HotkeySettingType,
} from "@/domain/hotkeyAction";

const lockKey = "save";

Expand Down
2 changes: 1 addition & 1 deletion src/backend/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import { AssetTextFileNames } from "@/type/staticResources";
import {
EngineInfo,
SystemError,
defaultHotkeySettings,
isMac,
defaultToolbarButtonSetting,
EngineId,
TextAsset,
} from "@/type/preload";
import { themes } from "@/domain/theme";
import { defaultHotkeySettings } from "@/domain/hotkeyAction";

type SingleInstanceLockData = {
filePath: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialog/HotkeyRecordingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
</template>

<script setup lang="ts">
import { HotkeyCombination } from "@/domain/hotkeyAction";
import { computed } from "vue";

Check failure on line 86 in src/components/Dialog/HotkeyRecordingDialog.vue

View workflow job for this annotation

GitHub Actions / build-test

`vue` import should occur before import of `@/domain/hotkeyAction`

Check failure on line 86 in src/components/Dialog/HotkeyRecordingDialog.vue

View workflow job for this annotation

GitHub Actions / lint

`vue` import should occur before import of `@/domain/hotkeyAction`
import { HotkeyCombination } from "@/type/preload";
const props = defineProps<{
isHotkeyDialogOpened: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dialog/HotkeySettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@
import { computed, ref } from "vue";
import HotkeyRecordingDialog from "./HotkeyRecordingDialog.vue";
import { useStore } from "@/store";
import { useHotkeyManager, eventToCombination } from "@/plugins/hotkeyPlugin";
import {
HotkeyActionNameType,
HotkeyCombination,
HotkeyActionNameType,
HotkeySettingType,
} from "@/type/preload";
import { useHotkeyManager, eventToCombination } from "@/plugins/hotkeyPlugin";
} from "@/domain/hotkeyAction";
const props = defineProps<{
modelValue: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/MenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import { ref, computed, watch } from "vue";
import { MenuItemData } from "./type";
import { useStore } from "@/store";
import { hotkeyActionNameSchema } from "@/type/preload";
import { hotkeyActionNameSchema } from "@/domain/hotkeyAction";
const props = withDefaults(
defineProps<{
selected?: boolean;
Expand Down
6 changes: 4 additions & 2 deletions src/components/Talk/TalkEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ import {
PresetKey,
SplitterPositionType,
Voice,
HotkeyActionNameType,
actionPostfixSelectNthCharacter,
} from "@/type/preload";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
import onetimeWatch from "@/helpers/onetimeWatch";
import {
actionPostfixSelectNthCharacter,
HotkeyActionNameType,
} from "@/domain/hotkeyAction";
const props = defineProps<{
isEnginesReady: boolean;
Expand Down
184 changes: 184 additions & 0 deletions src/domain/hotkeyAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/**
* ショートカットキーやアクションの定義
*/

import { z } from "zod";
import { isMac } from "@/type/preload"; // TODO: 相互参照になるのでhelperに移す #2365

const hotkeyCombinationSchema = z.string().brand("HotkeyCombination");
export type HotkeyCombination = z.infer<typeof hotkeyCombinationSchema>;
export const HotkeyCombination = (
hotkeyCombination: string,
): HotkeyCombination => hotkeyCombinationSchema.parse(hotkeyCombination);

// 共通のアクション名
export const actionPostfixSelectNthCharacter = "番目のキャラクターを選択";

// ホットキーを追加したときは設定のマイグレーションが必要
export const defaultHotkeySettings: HotkeySettingType[] = [
{
action: "音声書き出し",
combination: HotkeyCombination(!isMac ? "Ctrl E" : "Meta E"),

Check failure on line 21 in src/domain/hotkeyAction.ts

View workflow job for this annotation

GitHub Actions / unit-test

components/Dialog/SettingDialog/FileNameTemplateDialog.stories.ts

ReferenceError: Cannot access 'isMac' before initialization ❯ domain/hotkeyAction.ts:21:36

Check failure on line 21 in src/domain/hotkeyAction.ts

View workflow job for this annotation

GitHub Actions / unit-test

components/Sing/SequencerGrid/index.stories.ts

ReferenceError: Cannot access 'isMac' before initialization ❯ domain/hotkeyAction.ts:21:36

Check failure on line 21 in src/domain/hotkeyAction.ts

View workflow job for this annotation

GitHub Actions / unit-test

components/Sing/SequencerRuler/index.stories.ts

ReferenceError: Cannot access 'isMac' before initialization ❯ domain/hotkeyAction.ts:21:36
},
{
action: "選択音声を書き出し",
combination: HotkeyCombination("E"),
},
{
action: "音声を繋げて書き出し",
combination: HotkeyCombination(""),
},
{
action: "再生/停止",
combination: HotkeyCombination("Space"),
},
{
action: "連続再生/停止",
combination: HotkeyCombination("Shift Space"),
},
{
action: "アクセント欄を表示",
combination: HotkeyCombination("1"),
},
{
action: "イントネーション欄を表示",
combination: HotkeyCombination("2"),
},
{
action: "長さ欄を表示",
combination: HotkeyCombination("3"),
},
{
action: "テキスト欄を追加",
combination: HotkeyCombination("Shift Enter"),
},
{
action: "テキスト欄を複製",
combination: HotkeyCombination(!isMac ? "Ctrl D" : "Meta D"),
},
{
action: "テキスト欄を削除",
combination: HotkeyCombination("Shift Delete"),
},
{
action: "テキスト欄からフォーカスを外す",
combination: HotkeyCombination("Escape"),
},
{
action: "テキスト欄にフォーカスを戻す",
combination: HotkeyCombination("Enter"),
},
{
action: "元に戻す",
combination: HotkeyCombination(!isMac ? "Ctrl Z" : "Meta Z"),
},
{
action: "やり直す",
combination: HotkeyCombination(!isMac ? "Ctrl Y" : "Shift Meta Z"),
},
{
action: "新規プロジェクト",
combination: HotkeyCombination(!isMac ? "Ctrl N" : "Meta N"),
},
{
action: "プロジェクトを名前を付けて保存",
combination: HotkeyCombination(!isMac ? "Ctrl Shift S" : "Shift Meta S"),
},
{
action: "プロジェクトを上書き保存",
combination: HotkeyCombination(!isMac ? "Ctrl S" : "Meta S"),
},
{
action: "プロジェクトを読み込む",
combination: HotkeyCombination(!isMac ? "Ctrl O" : "Meta O"),
},
{
action: "テキストを読み込む",
combination: HotkeyCombination(""),
},
{
action: "全体のイントネーションをリセット",
combination: HotkeyCombination(!isMac ? "Ctrl G" : "Meta G"),
},
{
action: "選択中のアクセント句のイントネーションをリセット",
combination: HotkeyCombination("R"),
},
{
action: "コピー",
combination: HotkeyCombination(!isMac ? "Ctrl C" : "Meta C"),
},
{
action: "切り取り",
combination: HotkeyCombination(!isMac ? "Ctrl X" : "Meta X"),
},
{
action: "貼り付け",
combination: HotkeyCombination(!isMac ? "Ctrl V" : "Meta V"),
},
{
action: "すべて選択",
combination: HotkeyCombination(!isMac ? "Ctrl A" : "Meta A"),
},
{
action: "選択解除",
combination: HotkeyCombination("Escape"),
},
...Array.from({ length: 10 }, (_, index) => {
const roleKey = index == 9 ? 0 : index + 1;
return {
action:
`${index + 1}${actionPostfixSelectNthCharacter}` as HotkeyActionNameType,
combination: HotkeyCombination(`${!isMac ? "Ctrl" : "Meta"} ${roleKey}`),
};
}),
];

export const hotkeyActionNameSchema = z.enum([
"音声書き出し",
"選択音声を書き出し",
"音声を繋げて書き出し",
"再生/停止",
"連続再生/停止",
"アクセント欄を表示",
"イントネーション欄を表示",
"長さ欄を表示",
"テキスト欄を追加",
"テキスト欄を複製",
"テキスト欄を削除",
"テキスト欄からフォーカスを外す",
"テキスト欄にフォーカスを戻す",
"元に戻す",
"やり直す",
"新規プロジェクト",
"プロジェクトを名前を付けて保存",
"プロジェクトを上書き保存",
"プロジェクトを読み込む",
"テキストを読み込む",
"全体のイントネーションをリセット",
"選択中のアクセント句のイントネーションをリセット",
"コピー",
"切り取り",
"貼り付け",
"すべて選択",
"選択解除",
"全セルを選択",
`1${actionPostfixSelectNthCharacter}`,
`2${actionPostfixSelectNthCharacter}`,
`3${actionPostfixSelectNthCharacter}`,
`4${actionPostfixSelectNthCharacter}`,
`5${actionPostfixSelectNthCharacter}`,
`6${actionPostfixSelectNthCharacter}`,
`7${actionPostfixSelectNthCharacter}`,
`8${actionPostfixSelectNthCharacter}`,
`9${actionPostfixSelectNthCharacter}`,
`10${actionPostfixSelectNthCharacter}`,
]);

export type HotkeyActionNameType = z.infer<typeof hotkeyActionNameSchema>;

export const hotkeySettingSchema = z.object({
action: hotkeyActionNameSchema,
combination: hotkeyCombinationSchema,
});
export type HotkeySettingType = z.infer<typeof hotkeySettingSchema>;
4 changes: 2 additions & 2 deletions src/plugins/hotkeyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
import { Plugin, inject, onMounted, onUnmounted } from "vue";
import hotkeys from "hotkeys-js";
import { createLogger } from "@/domain/frontend/log";
import {
HotkeyActionNameType,
HotkeyCombination,
HotkeySettingType,
} from "@/type/preload";
import { createLogger } from "@/domain/frontend/log";
} from "@/domain/hotkeyAction";

const hotkeyManagerKey = "hotkeyManager";
export const useHotkeyManager = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
showQuestionDialog,
} from "@/components/Dialog/Dialog";
import {
HotkeySettingType,
SavingSetting,
ExperimentalSettingType,
ToolbarSettingType,
Expand All @@ -16,6 +15,7 @@ import {
RootMiscSettingType,
} from "@/type/preload";
import { IsEqual } from "@/type/utility";
import { HotkeySettingType } from "@/domain/hotkeyAction";

export const settingStoreState: SettingStoreState = {
savingSetting: {
Expand Down
2 changes: 1 addition & 1 deletion src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
DefaultStyleId,
AcceptRetrieveTelemetryStatus,
AcceptTermsStatus,
HotkeySettingType,
MoraDataType,
SavingSetting,
ThemeConf,
Expand Down Expand Up @@ -72,6 +71,7 @@ import {
timeSignatureSchema,
trackSchema,
} from "@/domain/project/schema";
import { HotkeySettingType } from "@/domain/hotkeyAction";

/**
* エディタ用のAudioQuery
Expand Down
2 changes: 1 addition & 1 deletion src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
EngineId,
EngineInfo,
EngineSettingType,
HotkeySettingType,
MessageBoxReturnValue,
NativeThemeType,
TextAsset,
ToolbarSettingType,
} from "@/type/preload";
import { AltPortInfos } from "@/store/type";
import { Result } from "@/type/result";
import { HotkeySettingType } from "@/domain/hotkeyAction";

/**
* invoke, handle
Expand Down
Loading

0 comments on commit 53f154f

Please sign in to comment.