Skip to content

Commit

Permalink
Improve: 複数エンジン登録時の起動を高速化 (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi authored Nov 15, 2022
1 parent f9bd8a0 commit 1f1a334
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 103 deletions.
6 changes: 2 additions & 4 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,8 @@ export default defineComponent({
type: "root",
label: engineInfo.name,
icon:
store.state.engineManifests[engineInfo.uuid] &&
base64ImageToUri(
store.state.engineManifests[engineInfo.uuid].icon
),
engineManifests.value[engineInfo.uuid] &&
base64ImageToUri(engineManifests.value[engineInfo.uuid].icon),
subMenu: [
engineInfo.path && {
type: "button",
Expand Down
9 changes: 0 additions & 9 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,6 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
},
},

LOAD_CHARACTER_ALL: {
action: createUILockAction(async ({ state, dispatch }) => {
for (const engineId of state.engineIds) {
window.electron.logInfo(`Load CharacterInfo from engine ${engineId}`);
await dispatch("LOAD_CHARACTER", { engineId });
}
}),
},

LOAD_CHARACTER: {
action: createUILockAction(async ({ commit, dispatch }, { engineId }) => {
const speakers = await dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
Expand Down
62 changes: 50 additions & 12 deletions src/store/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { EngineState, EngineStoreState, EngineStoreTypes } from "./type";
import { createUILockAction } from "./ui";
import { createPartialStore } from "./vuex";
import type { EngineManifest } from "@/openapi";
import type { EngineInfo } from "@/type/preload";

export const engineStoreState: EngineStoreState = {
engineStates: {},
Expand Down Expand Up @@ -35,18 +37,6 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
},
},

START_WAITING_ENGINE_ALL: {
action: createUILockAction(async ({ state, dispatch }) => {
const engineIds = state.engineIds;

for (const engineId of engineIds) {
await dispatch("START_WAITING_ENGINE", {
engineId,
});
}
}),
},

START_WAITING_ENGINE: {
action: createUILockAction(
async ({ state, commit, dispatch }, { engineId }) => {
Expand Down Expand Up @@ -207,4 +197,52 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
});
},
},

GET_ENGINE_INFOS: {
async action({ commit }) {
commit("SET_ENGINE_INFOS", {
engineInfos: await window.electron.engineInfos(),
});
},
},

SET_ENGINE_INFOS: {
mutation(state, { engineInfos }: { engineInfos: EngineInfo[] }) {
state.engineIds = engineInfos.map((engineInfo) => engineInfo.uuid);
state.engineInfos = Object.fromEntries(
engineInfos.map((engineInfo) => [engineInfo.uuid, engineInfo])
);
state.engineStates = Object.fromEntries(
engineInfos.map((engineInfo) => [engineInfo.uuid, "STARTING"])
);
},
},

SET_ENGINE_MANIFEST: {
mutation(
state,
{
engineId,
engineManifest,
}: { engineId: string; engineManifest: EngineManifest }
) {
state.engineManifests = {
...state.engineManifests,
[engineId]: engineManifest,
};
},
},

FETCH_AND_SET_ENGINE_MANIFEST: {
async action({ commit }, { engineId }) {
commit("SET_ENGINE_MANIFEST", {
engineId,
engineManifest: await this.dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
}).then((instance) =>
instance.invoke("engineManifestEngineManifestGet")({})
),
});
},
},
});
40 changes: 16 additions & 24 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ export type AudioStoreTypes = {
getter: number | undefined;
};

LOAD_CHARACTER_ALL: {
action(): void;
};

LOAD_CHARACTER: {
action(payload: { engineId: string }): void;
};
Expand Down Expand Up @@ -666,10 +662,6 @@ export type EngineStoreTypes = {
getter(engineId: string): boolean;
};

START_WAITING_ENGINE_ALL: {
action(): void;
};

START_WAITING_ENGINE: {
action(payload: { engineId: string }): void;
};
Expand Down Expand Up @@ -708,6 +700,22 @@ export type EngineStoreTypes = {
INITIALIZE_ENGINE_SPEAKER: {
action(payload: { engineId: string; styleId: number }): void;
};

GET_ENGINE_INFOS: {
action(): void;
};

SET_ENGINE_INFOS: {
mutation: { engineInfos: EngineInfo[] };
};

SET_ENGINE_MANIFEST: {
mutation: { engineId: string; engineManifest: EngineManifest };
};

FETCH_AND_SET_ENGINE_MANIFEST: {
action(payload: { engineId: string }): void;
};
};

/*
Expand Down Expand Up @@ -1052,22 +1060,6 @@ export type UiStoreTypes = {
action(payload: { useGpu: boolean }): void;
};

GET_ENGINE_INFOS: {
action(): void;
};

SET_ENGINE_INFOS: {
mutation: { engineInfos: EngineInfo[] };
};

SET_ENGINE_MANIFESTS: {
mutation: { engineManifests: Record<string, EngineManifest> };
};

FETCH_AND_SET_ENGINE_MANIFESTS: {
action(): void;
};

SET_INHERIT_AUDIOINFO: {
mutation: { inheritAudioInfo: boolean };
action(payload: { inheritAudioInfo: boolean }): void;
Expand Down
52 changes: 1 addition & 51 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
UiStoreState,
UiStoreTypes,
} from "./type";
import { ActivePointScrollMode, EngineInfo } from "@/type/preload";
import { EngineManifest } from "@/openapi";
import { ActivePointScrollMode } from "@/type/preload";
import { createPartialStore } from "./vuex";

export function createUILockAction<S, A extends ActionsBase, K extends keyof A>(
Expand Down Expand Up @@ -389,55 +388,6 @@ export const uiStore = createPartialStore<UiStoreTypes>({
},
},

GET_ENGINE_INFOS: {
async action({ commit }) {
commit("SET_ENGINE_INFOS", {
engineInfos: await window.electron.engineInfos(),
});
},
},

SET_ENGINE_INFOS: {
mutation(state, { engineInfos }: { engineInfos: EngineInfo[] }) {
state.engineIds = engineInfos.map((engineInfo) => engineInfo.uuid);
state.engineInfos = Object.fromEntries(
engineInfos.map((engineInfo) => [engineInfo.uuid, engineInfo])
);
state.engineStates = Object.fromEntries(
engineInfos.map((engineInfo) => [engineInfo.uuid, "STARTING"])
);
},
},

SET_ENGINE_MANIFESTS: {
mutation(
state,
{ engineManifests }: { engineManifests: Record<string, EngineManifest> }
) {
state.engineManifests = engineManifests;
},
},

FETCH_AND_SET_ENGINE_MANIFESTS: {
async action({ state, commit }) {
commit("SET_ENGINE_MANIFESTS", {
engineManifests: Object.fromEntries(
await Promise.all(
state.engineIds.map(
async (engineId) =>
await this.dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
}).then(async (instance) => [
engineId,
await instance.invoke("engineManifestEngineManifestGet")({}),
])
)
)
),
});
},
},

SET_INHERIT_AUDIOINFO: {
mutation(state, { inheritAudioInfo }: { inheritAudioInfo: boolean }) {
state.inheritAudioInfo = inheritAudioInfo;
Expand Down
10 changes: 7 additions & 3 deletions src/views/EditorHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,15 @@ export default defineComponent({
onMounted(async () => {
await store.dispatch("GET_ENGINE_INFOS");
await store.dispatch("START_WAITING_ENGINE_ALL");
await Promise.all(
store.state.engineIds.map(async (engineId) => {
await store.dispatch("START_WAITING_ENGINE", { engineId });
await store.dispatch("FETCH_AND_SET_ENGINE_MANIFESTS");
await store.dispatch("FETCH_AND_SET_ENGINE_MANIFEST", { engineId });
await store.dispatch("LOAD_CHARACTER_ALL");
await store.dispatch("LOAD_CHARACTER", { engineId });
})
);
await store.dispatch("LOAD_USER_CHARACTER_ORDER");
await store.dispatch("LOAD_DEFAULT_STYLE_IDS");
Expand Down

0 comments on commit 1f1a334

Please sign in to comment.