-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathApp.vue
152 lines (130 loc) · 4.79 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<ErrorBoundary>
<MenuBar
v-if="openedEditor != undefined"
:file-sub-menu-data="subMenuData.fileSubMenuData.value"
:edit-sub-menu-data="subMenuData.editSubMenuData.value"
:editor="openedEditor"
/>
<KeepAlive>
<Component
:is="openedEditor == 'talk' ? TalkEditor : SingEditor"
v-if="openedEditor != undefined"
:key="openedEditor"
:is-engines-ready="isEnginesReady"
:is-project-file-loaded="isProjectFileLoaded"
/>
</KeepAlive>
<AllDialog :is-engines-ready="isEnginesReady" />
</ErrorBoundary>
</template>
<script setup lang="ts">
import { watch, onMounted, ref, computed, toRaw } from "vue";
import { useGtm } from "@gtm-support/vue-gtm";
import TalkEditor from "@/components/Talk/TalkEditor.vue";
import SingEditor from "@/components/Sing/SingEditor.vue";
import { EngineId } from "@/type/preload";
import ErrorBoundary from "@/components/ErrorBoundary.vue";
import { useStore } from "@/store";
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
import AllDialog from "@/components/Dialog/AllDialog.vue";
import MenuBar from "@/components/Menu/MenuBar/MenuBar.vue";
import { useMenuBarData as useTalkMenuBarData } from "@/components/Talk/menuBarData";
import { useMenuBarData as useSingMenuBarData } from "@/components/Sing/menuBarData";
const store = useStore();
const talkMenuBarData = useTalkMenuBarData();
const singMenuBarData = useSingMenuBarData();
const subMenuData = computed(() => {
if (openedEditor.value === "talk" || openedEditor.value == undefined) {
return talkMenuBarData;
} else if (openedEditor.value === "song") {
return singMenuBarData;
}
throw new Error(`Invalid openedEditor: ${openedEditor.value}`);
});
const openedEditor = computed(() => store.state.openedEditor);
// Google Tag Manager
const gtm = useGtm();
watch(
() => store.state.acceptRetrieveTelemetry,
(acceptRetrieveTelemetry) => {
gtm?.enable(acceptRetrieveTelemetry === "Accepted");
},
{ immediate: true },
);
// フォントの制御用パラメータを変更する
watch(
() => store.state.editorFont,
(editorFont) => {
document.body.setAttribute("data-editor-font", editorFont);
},
{ immediate: true },
);
// エディタの切り替えを監視してショートカットキーの設定を変更する
watch(
() => store.state.openedEditor,
async (openedEditor) => {
if (openedEditor != undefined) {
hotkeyManager.onEditorChange(openedEditor);
}
},
);
// ソフトウェアを初期化
const { hotkeyManager } = useHotkeyManager();
const isEnginesReady = ref(false);
const isProjectFileLoaded = ref<boolean | "waiting">("waiting");
onMounted(async () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
await store.dispatch("INIT_VUEX");
// プロジェクトファイルのパスを取得
const projectFilePath = urlParams.get("projectFilePath");
// どちらのエディタを開くか設定
await store.dispatch("SET_OPENED_EDITOR", { editor: "talk" });
// ショートカットキーの設定を登録
const hotkeySettings = store.state.hotkeySettings;
hotkeyManager.load(structuredClone(toRaw(hotkeySettings)));
// エンジンの初期化開始
// エンジン情報取得
await store.dispatch("GET_ENGINE_INFOS");
// URLパラメータに従ってマルチエンジンをオフにする
const isMultiEngineOffMode = urlParams.get("isMultiEngineOffMode") === "true";
store.dispatch("SET_IS_MULTI_ENGINE_OFF_MODE", isMultiEngineOffMode);
// マルチエンジンオフモードのときはデフォルトエンジンだけにする
let engineIds: EngineId[];
if (isMultiEngineOffMode) {
const main = Object.values(store.state.engineInfos).find(
(engine) => engine.type === "default",
);
if (!main) {
throw new Error("No main engine found");
}
engineIds = [main.uuid];
} else {
engineIds = store.state.engineIds;
}
await store.dispatch("LOAD_USER_CHARACTER_ORDER");
await store.dispatch("POST_ENGINE_START", {
engineIds,
});
// 辞書を同期
await store.dispatch("SYNC_ALL_USER_DICT");
isEnginesReady.value = true;
// エンジン起動後にダイアログを開く
store.dispatch("SET_DIALOG_OPEN", {
isAcceptRetrieveTelemetryDialogOpen:
store.state.acceptRetrieveTelemetry === "Unconfirmed",
isAcceptTermsDialogOpen:
import.meta.env.MODE !== "development" &&
store.state.acceptTerms !== "Accepted",
});
// プロジェクトファイルが指定されていればロード
if (typeof projectFilePath === "string" && projectFilePath !== "") {
isProjectFileLoaded.value = await store.dispatch("LOAD_PROJECT_FILE", {
filePath: projectFilePath,
});
} else {
isProjectFileLoaded.value = false;
}
});
</script>