Skip to content

Commit cd9bdc8

Browse files
authored
[refactor] VueRouterの依存を失くす (#1875)
* VueRouterの依存を失くす * /talkなどを削除
1 parent cc2bceb commit cd9bdc8

File tree

12 files changed

+64
-73
lines changed

12 files changed

+64
-73
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ npm run electron:serve
7373
npm run browser:serve
7474
```
7575

76-
また、main ブランチのビルド結果がこちらにデプロイされています <https://voicevox-browser-dev.netlify.app/#/talk>
76+
また、main ブランチのビルド結果がこちらにデプロイされています <https://voicevox-browser-dev.netlify.app/>
7777
今はローカル PC 上で音声合成エンジンを起動する必要があります。
7878

7979
## ビルド
@@ -114,7 +114,7 @@ Playwright を使用しているためテストパターンを生成すること
114114
**ブラウザ版を起動している状態で**以下のコマンドを実行してください。
115115

116116
```bash
117-
npx playwright codegen http://localhost:5173/#/talk --viewport-size=800,600
117+
npx playwright codegen http://localhost:5173/ --viewport-size=800,600
118118
```
119119

120120
詳細は [Playwright ドキュメントの Test generator](https://playwright.dev/docs/codegen-intro) を参照してください。

docs/コードの歩き方.md

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ TODO
8888
- styles ディレクトリ ・・・ CSS や SCSS などのディレクトリ。
8989
- infrastructures ディレクトリ ・・・ UI 用のコードと UI 以外のコードを跨ぐときに一枚かませたいときのためのコードのディレクトリ。
9090
- openapi ディレクトリ ・・・ エンジンの API を叩くためのコードのディレクトリ。OpenAPI で自動生成される。
91-
- router ディレクトリ ・・・ Vue Router 用のディレクトリ。
9291
- helpers ディレクトリ ・・・ 便利な関数を置くディレクトリ。
9392
- shared ディレクトリ ・・・ UI と Electron 両方から参照されるコードを置くディレクトリ。
9493
- public

package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"tree-kill": "1.2.2",
6464
"uuid": "9.0.0",
6565
"vue": "3.2.45",
66-
"vue-router": "4.0.8",
6766
"vuedraggable": "4.1.0",
6867
"vuex": "4.0.2",
6968
"zod": "3.22.4"

src/backend/electron/main.ts

-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ async function loadUrl(obj: {
470470
projectFilePath?: string;
471471
}) {
472472
const fragment =
473-
"#/talk" +
474473
`?isMultiEngineOffMode=${obj?.isMultiEngineOffMode ?? false}` +
475474
`&projectFilePath=${obj?.projectFilePath ?? ""}`;
476475
return win.loadURL(`${firstUrl}${fragment}`);

src/components/App.vue

+37-27
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
<template>
22
<ErrorBoundary>
33
<!-- TODO: メニューバーをEditorHomeから移動する -->
4-
<RouterView v-slot="{ Component }">
5-
<KeepAlive>
6-
<Component
7-
:is="Component"
8-
:is-engines-ready="isEnginesReady"
9-
:is-project-file-loaded="isProjectFileLoaded"
10-
/>
11-
</KeepAlive>
12-
</RouterView>
4+
<KeepAlive>
5+
<Component
6+
:is="openedEditor == 'talk' ? TalkEditor : SingEditor"
7+
v-if="openedEditor != undefined"
8+
:key="openedEditor"
9+
:is-engines-ready="isEnginesReady"
10+
:is-project-file-loaded="isProjectFileLoaded"
11+
/>
12+
</KeepAlive>
1313
<AllDialog :is-engines-ready="isEnginesReady" />
1414
</ErrorBoundary>
1515
</template>
1616

1717
<script setup lang="ts">
1818
import { watch, onMounted, ref, computed, toRaw } from "vue";
1919
import { useGtm } from "@gtm-support/vue-gtm";
20-
import { useRoute } from "vue-router";
20+
import TalkEditor from "@/components/Talk/TalkEditor.vue";
21+
import SingEditor from "@/components/Sing/SingEditor.vue";
2122
import { EngineId } from "@/type/preload";
2223
import ErrorBoundary from "@/components/ErrorBoundary.vue";
2324
import { useStore } from "@/store";
2425
import { useHotkeyManager } from "@/plugins/hotkeyPlugin";
2526
import AllDialog from "@/components/Dialog/AllDialog.vue";
2627
2728
const store = useStore();
28-
const route = useRoute();
2929
30-
// TODO: プロジェクトファイルの読み込みもEditorHomeから移動する
31-
const projectFilePath = computed(() => route.query["projectFilePath"]);
30+
const openedEditor = computed(() => store.state.openedEditor);
31+
32+
/**
33+
* 読み込むプロジェクトファイルのパス。
34+
* undefinedのときは何も読み込むべきものがない。
35+
*/
36+
const projectFilePath = ref<string | undefined>(undefined);
3237
3338
// Google Tag Manager
3439
const gtm = useGtm();
@@ -49,20 +54,13 @@ watch(
4954
{ immediate: true }
5055
);
5156
52-
// エディタの切り替えを監視する
57+
// エディタの切り替えを監視してショートカットキーの設定を変更する
5358
watch(
54-
() => route.path,
55-
async (unknownPath) => {
56-
let path: "talk" | "song";
57-
if (["/talk", "/song"].includes(unknownPath)) {
58-
path = unknownPath.slice(1) as "talk" | "song";
59-
} else {
60-
// 不明なパスの場合はトークエディタにする
61-
path = "talk";
62-
window.backend.logWarn(`unknown path: ${unknownPath}`);
59+
() => store.state.openedEditor,
60+
async (openedEditor) => {
61+
if (openedEditor != undefined) {
62+
hotkeyManager.onEditorChange(openedEditor);
6363
}
64-
65-
hotkeyManager.onEditorChange(path);
6664
}
6765
);
6866
@@ -71,10 +69,22 @@ const { hotkeyManager } = useHotkeyManager();
7169
const isEnginesReady = ref(false);
7270
const isProjectFileLoaded = ref<boolean | "waiting">("waiting");
7371
onMounted(async () => {
72+
const queryString = window.location.search;
73+
const urlParams = new URLSearchParams(queryString);
74+
7475
await store.dispatch("INIT_VUEX");
7576
76-
const hotkeySettings = store.state.hotkeySettings;
77+
// プロジェクトファイルのパスを取得
78+
const _projectFilePath = urlParams.get("projectFilePath");
79+
if (_projectFilePath != undefined && _projectFilePath !== "") {
80+
projectFilePath.value = _projectFilePath;
81+
}
82+
83+
// どちらのエディタを開くか設定
84+
await store.dispatch("SET_OPENED_EDITOR", { editor: "talk" });
7785
86+
// ショートカットキーの設定を登録
87+
const hotkeySettings = store.state.hotkeySettings;
7888
hotkeyManager.load(structuredClone(toRaw(hotkeySettings)));
7989
8090
// エンジンの初期化開始
@@ -83,7 +93,7 @@ onMounted(async () => {
8393
await store.dispatch("GET_ENGINE_INFOS");
8494
8595
// URLパラメータに従ってマルチエンジンをオフにする
86-
const isMultiEngineOffMode = route.query["isMultiEngineOffMode"] === "true";
96+
const isMultiEngineOffMode = urlParams.get("isMultiEngineOffMode") === "true";
8797
store.dispatch("SET_IS_MULTI_ENGINE_OFF_MODE", isMultiEngineOffMode);
8898
8999
// マルチエンジンオフモードのときはデフォルトエンジンだけにする

src/components/Menu/MenuBar/TitleBarEditorSwitcher.vue

+5-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- FIXME: 画面サイズが小さくなると表示が崩れるのを直す -->
77
<!-- NOTE: デザインしづらいからQBtnかdivの方が良い -->
88
<QBtnToggle
9-
:model-value="nowEditor"
9+
:model-value="openedEditor"
1010
unelevated
1111
:disable="uiLocked"
1212
dense
@@ -15,31 +15,22 @@
1515
{ label: 'トーク', value: 'talk' },
1616
{ label: 'ソング', value: 'song' },
1717
]"
18-
@update:model-value="gotoLink"
18+
@update:model-value="switchEditor"
1919
/>
2020
</template>
2121

2222
<script setup lang="ts">
2323
import { computed } from "vue";
24-
import { useRouter } from "vue-router";
2524
import { useStore } from "@/store";
2625
import { EditorType } from "@/type/preload";
2726

2827
const store = useStore();
29-
const router = useRouter();
3028

29+
const openedEditor = computed(() => store.state.openedEditor);
3130
const uiLocked = computed(() => store.getters.UI_LOCKED);
3231

33-
const nowEditor = computed<EditorType>(() => {
34-
const path = router.currentRoute.value.path;
35-
if (path === "/talk") return "talk";
36-
if (path === "/song") return "song";
37-
window.backend.logWarn(`unknown path: ${path}`);
38-
return "talk";
39-
});
40-
41-
const gotoLink = (editor: EditorType) => {
42-
router.push("/" + editor);
32+
const switchEditor = async (editor: EditorType) => {
33+
await store.dispatch("SET_OPENED_EDITOR", { editor });
4334
};
4435
</script>
4536

src/main.ts

-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createApp } from "vue";
22
import { createGtm } from "@gtm-support/vue-gtm";
33
import { Quasar, Dialog, Loading, Notify } from "quasar";
44
import iconSet from "quasar/icon-set/material-icons";
5-
import router from "./router";
65
import { store, storeKey } from "./store";
76
import { ipcMessageReceiver } from "./plugins/ipcMessageReceiverPlugin";
87
import { hotkeyPlugin } from "./plugins/hotkeyPlugin";
@@ -19,11 +18,9 @@ window.dataLayer = [];
1918

2019
createApp(App)
2120
.use(store, storeKey)
22-
.use(router)
2321
.use(
2422
createGtm({
2523
id: import.meta.env.VITE_GTM_CONTAINER_ID ?? "GTM-DUMMY",
26-
vueRouter: router,
2724
// NOTE: 最初はgtm.jsを読まず、プライバシーポリシーに同意後に読み込む
2825
enabled: false,
2926
})

src/router/index.ts

-21
This file was deleted.

src/store/type.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ export type SettingStoreTypes = {
15061506
*/
15071507

15081508
export type UiStoreState = {
1509+
openedEditor: EditorType | undefined; // undefinedのときはどのエディタを開くか定まっていない
15091510
uiLockCount: number;
15101511
dialogLockCount: number;
15111512
reloadingLock: boolean;
@@ -1530,6 +1531,11 @@ export type UiStoreState = {
15301531
};
15311532

15321533
export type UiStoreTypes = {
1534+
SET_OPENED_EDITOR: {
1535+
mutation: { editor: EditorType };
1536+
action(palyoad: { editor: EditorType }): void;
1537+
};
1538+
15331539
UI_LOCKED: {
15341540
getter: boolean;
15351541
};

src/store/ui.ts

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function withProgress<T>(
4545
}
4646

4747
export const uiStoreState: UiStoreState = {
48+
openedEditor: undefined,
4849
uiLockCount: 0,
4950
dialogLockCount: 0,
5051
reloadingLock: false,
@@ -69,6 +70,15 @@ export const uiStoreState: UiStoreState = {
6970
};
7071

7172
export const uiStore = createPartialStore<UiStoreTypes>({
73+
SET_OPENED_EDITOR: {
74+
mutation(state, { editor }) {
75+
state.openedEditor = editor;
76+
},
77+
action({ commit }, { editor }) {
78+
commit("SET_OPENED_EDITOR", { editor });
79+
},
80+
},
81+
7282
UI_LOCKED: {
7383
getter(state) {
7484
return state.uiLockCount > 0;

tests/e2e/navigators.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { expect, Page } from "@playwright/test";
22
import { getNewestQuasarDialog, getQuasarMenu } from "./locators";
33

44
/**
5-
* /#/talkに移動
5+
* 最初の画面に移動
66
*/
77
export async function gotoHome({ page }: { page: Page }) {
8-
const BASE_URL = "http://localhost:7357/#/talk";
8+
const BASE_URL = "http://localhost:7357/";
99
await page.setViewportSize({ width: 800, height: 600 });
1010
await page.goto(BASE_URL);
1111
}

0 commit comments

Comments
 (0)