From e49a2fcca8b680245370db4159e503506545ea0b Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Thu, 22 Aug 2024 13:59:42 +0900 Subject: [PATCH] =?UTF-8?q?add:=20=E3=83=87=E3=83=95=E3=82=A9=E3=83=AB?= =?UTF-8?q?=E3=83=88=E3=82=A8=E3=83=B3=E3=82=B8=E3=83=B3=E3=81=8B=E3=81=A4?= =?UTF-8?q?VVPP=E3=81=8C=E8=A8=AD=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E5=9E=8B=E3=81=A8=E5=AE=9F=E8=A3=85=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=20(#2242)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * マルチエンジンオフモード時はデフォルトエンジンだけにする * デフォルトエンジンかつVVPPが設定できるよう型と実装を変更 * ちょっと変更 --- ...55\350\250\210\346\226\271\351\207\235.md" | 11 ++++++++ src/backend/browser/contract.ts | 3 ++- src/backend/electron/manager/engineManager.ts | 8 +++--- src/components/App.vue | 4 +-- src/components/Dialog/EngineManageDialog.vue | 27 +++++++++++-------- src/components/Menu/MenuBar/MenuBar.vue | 2 +- src/store/engine.ts | 16 +++++------ src/type/preload.ts | 4 +-- 8 files changed, 45 insertions(+), 30 deletions(-) diff --git "a/docs/\347\264\260\343\201\213\343\201\204\350\250\255\350\250\210\346\226\271\351\207\235.md" "b/docs/\347\264\260\343\201\213\343\201\204\350\250\255\350\250\210\346\226\271\351\207\235.md" index 3c999d57b6..adccd71e66 100644 --- "a/docs/\347\264\260\343\201\213\343\201\204\350\250\255\350\250\210\346\226\271\351\207\235.md" +++ "b/docs/\347\264\260\343\201\213\343\201\204\350\250\255\350\250\210\346\226\271\351\207\235.md" @@ -38,3 +38,14 @@ export const hogeFugaSchema = z.object({ export type HogeFugaType = z.infer; ``` + +## マルチエンジン + +エンジンの追加は VVPP ファイルをインストールする形と、エンジンディレクトリのパスを指定する形があります。 + +| | VVPP | パス | +| -------------------- | ------------------------------------ | ----------------------------------- | +| `EngineInfo`の`type` | `"vvpp"` | `"path"` | +| 追加時の処理 | zipファイルを所定のフォルダに展開 | エンジンのパスを`config.json`に保存 | +| 読み込み時の処理 | 所定のフォルダ内にあるものを読む | `config.json`に保存されたパスを読む | +| 削除時の処理 | 所定のフォルダ内のディレクトリを削除 | `config.json`からパスを削除 | diff --git a/src/backend/browser/contract.ts b/src/backend/browser/contract.ts index f649de781f..089b07280c 100644 --- a/src/backend/browser/contract.ts +++ b/src/backend/browser/contract.ts @@ -6,6 +6,7 @@ const baseEngineInfo = envEngineInfoSchema export const defaultEngine: EngineInfo = { ...baseEngineInfo, - type: "default", + type: "path", // FIXME: ダミーで"path"にしているので、エンジンAPIのURLを設定できるようにし、type: "URL"にする + isDefault: true, }; export const directoryHandleStoreKey = "directoryHandle"; diff --git a/src/backend/electron/manager/engineManager.ts b/src/backend/electron/manager/engineManager.ts index 6563074cb5..6c32171316 100644 --- a/src/backend/electron/manager/engineManager.ts +++ b/src/backend/electron/manager/engineManager.ts @@ -45,13 +45,14 @@ function createDefaultEngineInfos(defaultEngineDir: string): EngineInfo[] { return engines.map((engineInfo) => { return { ...engineInfo, - type: "default", + isDefault: true, + type: "path", executionFilePath: path.resolve(engineInfo.executionFilePath), path: engineInfo.path == undefined ? undefined : path.resolve(defaultEngineDir, engineInfo.path), - }; + } satisfies EngineInfo; }); } @@ -116,7 +117,8 @@ export class EngineManager { executionFilePath: path.join(engineDir, command), executionArgs: args, type, - }); + isDefault: false, + } satisfies EngineInfo); return "ok"; }; for (const dirName of fs.readdirSync(this.vvppEngineDir)) { diff --git a/src/components/App.vue b/src/components/App.vue index e4c711403a..d14de67080 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -117,10 +117,10 @@ onMounted(async () => { let engineIds: EngineId[]; if (isMultiEngineOffMode) { const main = Object.values(store.state.engineInfos).find( - (engine) => engine.type === "default", + (engine) => engine.isDefault, ); if (!main) { - throw new Error("No main engine found"); + throw new Error("No default engine found"); } engineIds = [main.uuid]; } else { diff --git a/src/components/Dialog/EngineManageDialog.vue b/src/components/Dialog/EngineManageDialog.vue index 84e9478f0f..85ed2ebff8 100644 --- a/src/components/Dialog/EngineManageDialog.vue +++ b/src/components/Dialog/EngineManageDialog.vue @@ -314,10 +314,7 @@ outline textColor="warning" class="text-no-wrap text-bold q-mr-sm" - :disable=" - uiLocked || - !['path', 'vvpp'].includes(engineInfos[selectedId].type) - " + :disable="uiLocked || engineInfos[selectedId].isDefault" @click="deleteEngine" >削除 @@ -386,10 +383,10 @@ const categorizedEngineIds = computed(() => { const sortedEngineInfos = store.getters.GET_SORTED_ENGINE_INFOS; const result = { default: Object.values(sortedEngineInfos) - .filter((info) => info.type === "default") + .filter((info) => info.isDefault) .map((info) => info.uuid), plugin: Object.values(sortedEngineInfos) - .filter((info) => info.type === "path" || info.type === "vvpp") + .filter((info) => !info.isDefault) .map((info) => info.uuid), }; return Object.fromEntries( @@ -512,17 +509,25 @@ const addEngine = async () => { } }; const deleteEngine = async () => { + const engineId = selectedId.value; + if (engineId == undefined) throw new Error("engine is not selected"); + + const engineInfo = engineInfos.value[engineId]; + + // 念の為デフォルトエンジンではないことを確認 + if (engineInfo.isDefault) { + throw new Error("default engine cannot be deleted"); + } + const result = await store.dispatch("SHOW_CONFIRM_DIALOG", { title: "エンジン削除の確認", message: "選択中のエンジンを削除します。よろしいですか?", actionName: "削除", }); if (result === "OK") { - if (selectedId.value == undefined) - throw new Error("engine is not selected"); - switch (engineInfos.value[selectedId.value].type) { + switch (engineInfo.type) { case "path": { - const engineDir = store.state.engineInfos[selectedId.value].path; + const engineDir = engineInfo.path; if (!engineDir) throw new Error("assert engineInfos[selectedId.value].path"); await lockUi( @@ -539,7 +544,7 @@ const deleteEngine = async () => { case "vvpp": { const success = await lockUi( "deletingEngine", - store.dispatch("UNINSTALL_VVPP_ENGINE", selectedId.value), + store.dispatch("UNINSTALL_VVPP_ENGINE", engineId), ); if (success) { void requireReload( diff --git a/src/components/Menu/MenuBar/MenuBar.vue b/src/components/Menu/MenuBar/MenuBar.vue index c27ca224b5..5bd26b70cf 100644 --- a/src/components/Menu/MenuBar/MenuBar.vue +++ b/src/components/Menu/MenuBar/MenuBar.vue @@ -59,7 +59,7 @@ const defaultEngineAltPortTo = computed(() => { // ref: https://github.com/VOICEVOX/voicevox/blob/32940eab36f4f729dd0390dca98f18656240d60d/src/views/EditorHome.vue#L522-L528 const defaultEngineInfo = Object.values(store.state.engineInfos).find( - (engine) => engine.type === "default", + (engine) => engine.isDefault, ); if (defaultEngineInfo == undefined) return undefined; diff --git a/src/store/engine.ts b/src/store/engine.ts index 86f4792e4c..34f9ba2496 100644 --- a/src/store/engine.ts +++ b/src/store/engine.ts @@ -15,17 +15,13 @@ const { info, error } = createLogger("store/engine"); export const engineStore = createPartialStore({ GET_ENGINE_INFOS: { async action({ state, mutations }) { - const engineInfos = await window.backend.engineInfos(); + let engineInfos = await window.backend.engineInfos(); - // マルチエンジンオフモード時はengineIdsをデフォルトエンジンのIDだけにする。 - let engineIds: EngineId[]; + // マルチエンジンオフモード時はデフォルトエンジンだけにする。 if (state.isMultiEngineOffMode) { - engineIds = engineInfos - .filter((engineInfo) => engineInfo.type === "default") - .map((info) => info.uuid); - } else { - engineIds = engineInfos.map((engineInfo) => engineInfo.uuid); + engineInfos = engineInfos.filter((engineInfo) => engineInfo.isDefault); } + const engineIds = engineInfos.map((engineInfo) => engineInfo.uuid); mutations.SET_ENGINE_INFOS({ engineIds, @@ -57,8 +53,8 @@ export const engineStore = createPartialStore({ GET_SORTED_ENGINE_INFOS: { getter: (state) => { return Object.values(state.engineInfos).sort((a, b) => { - const isDefaultA = a.type === "default" ? 1 : 0; - const isDefaultB = b.type === "default" ? 1 : 0; + const isDefaultA = a.isDefault ? 1 : 0; + const isDefaultB = b.isDefault ? 1 : 0; if (isDefaultA !== isDefaultB) { return isDefaultB - isDefaultA; } diff --git a/src/type/preload.ts b/src/type/preload.ts index 2b53a44dcc..9b07278510 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -417,10 +417,10 @@ export type EngineInfo = { executionFilePath: string; executionArgs: string[]; // エンジンの種類。 - // default: デフォルトエンジン // vvpp: vvppファイルから読み込んだエンジン // path: パスを指定して追加したエンジン - type: "default" | "vvpp" | "path"; + type: "vvpp" | "path"; + isDefault: boolean; // デフォルトエンジンかどうか }; export type Preset = {