Skip to content

Commit

Permalink
add: デフォルトエンジンかつVVPPが設定できるよう型と実装を変更 (#2242)
Browse files Browse the repository at this point in the history
* マルチエンジンオフモード時はデフォルトエンジンだけにする

* デフォルトエンジンかつVVPPが設定できるよう型と実装を変更

* ちょっと変更
  • Loading branch information
Hiroshiba authored Aug 22, 2024
1 parent 38c4f18 commit e49a2fc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 30 deletions.
11 changes: 11 additions & 0 deletions docs/細かい設計方針.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ export const hogeFugaSchema = z.object({

export type HogeFugaType = z.infer<typeof hogeFugaSchema>;
```

## マルチエンジン

エンジンの追加は VVPP ファイルをインストールする形と、エンジンディレクトリのパスを指定する形があります。

| | VVPP | パス |
| -------------------- | ------------------------------------ | ----------------------------------- |
| `EngineInfo``type` | `"vvpp"` | `"path"` |
| 追加時の処理 | zipファイルを所定のフォルダに展開 | エンジンのパスを`config.json`に保存 |
| 読み込み時の処理 | 所定のフォルダ内にあるものを読む | `config.json`に保存されたパスを読む |
| 削除時の処理 | 所定のフォルダ内のディレクトリを削除 | `config.json`からパスを削除 |
3 changes: 2 additions & 1 deletion src/backend/browser/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 5 additions & 3 deletions src/backend/electron/manager/engineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 16 additions & 11 deletions src/components/Dialog/EngineManageDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>削除</QBtn
>
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/MenuBar/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const defaultEngineAltPortTo = computed<number | undefined>(() => {
// 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;
Expand Down
16 changes: 6 additions & 10 deletions src/store/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ const { info, error } = createLogger("store/engine");
export const engineStore = createPartialStore<EngineStoreTypes>({
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,
Expand Down Expand Up @@ -57,8 +53,8 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit e49a2fc

Please sign in to comment.