Skip to content

Commit

Permalink
ローカルファイルからキャラクター情報をロードする周りを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
shirowanisan committed Dec 5, 2021
1 parent 638e36d commit 3166476
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 95 deletions.
71 changes: 1 addition & 70 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ import { ipcMainHandle, ipcMainSend } from "@/electron/ipc";

import fs from "fs";
import {
CharacterInfo,
DefaultStyleId,
HotkeySetting,
MetasJson,
SavingSetting,
ThemeConf,
StyleInfo,
} from "./type/preload";

import log from "electron-log";
Expand Down Expand Up @@ -302,58 +299,8 @@ if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}

// キャラクター情報の読み込み
declare let __static: string;
const characterInfos: CharacterInfo[] = [];
for (const dirRelPath of fs.readdirSync(path.join(__static, "characters"))) {
const dirPath = path.join("characters", dirRelPath);
const policy = fs.readFileSync(
path.join(__static, dirPath, "policy.md"),
"utf-8"
);
const {
speakerName,
speakerUuid,
styles: stylesOrigin,
}: MetasJson = JSON.parse(
fs.readFileSync(path.join(__static, dirPath, "metas.json"), "utf-8")
);
const styles = stylesOrigin.map<StyleInfo>(({ styleName, styleId }) => ({
styleName,
styleId,
iconBase64: fs.readFileSync(
path.join(__static, dirPath, "icons", `${speakerName}_${styleId}.png`),
"base64"
),
voiceSampleBase64s: [...Array(3).keys()].map((x) =>
fs.readFileSync(
path.join(
__static,
dirPath,
"voice_samples",
`${speakerName}_${styleId}_${(x + 1).toString().padStart(3, "0")}.wav`
),
"base64"
)
),
}));
const portraitBase64 = fs.readFileSync(
path.join(__static, dirPath, "portrait.png"),
"base64"
);

characterInfos.push({
portraitBase64,
metas: {
speakerName,
speakerUuid,
styles,
policy,
},
});
}

// 使い方テキストの読み込み
declare let __static: string;
const howToUseText = fs.readFileSync(
path.join(__static, "howtouse.md"),
"utf-8"
Expand Down Expand Up @@ -448,10 +395,6 @@ ipcMainHandle("GET_TEMP_DIR", () => {
return tempDir;
});

ipcMainHandle("GET_CHARACTER_INFOS", () => {
return characterInfos;
});

ipcMainHandle("GET_HOW_TO_USE_TEXT", () => {
return howToUseText;
});
Expand Down Expand Up @@ -717,18 +660,6 @@ ipcMainHandle("IS_UNSET_DEFAULT_STYLE_ID", (_, speakerUuid) => {
return !defaultStyleIds.find((style) => style.speakerUuid === speakerUuid);
});

ipcMainHandle("GET_DEFAULT_STYLE_IDS", () => {
const defaultStyleIds = store.get("defaultStyleIds");
if (defaultStyleIds.length === 0) {
return characterInfos.map<DefaultStyleId>((info) => ({
speakerUuid: info.metas.speakerUuid,
defaultStyleId: info.metas.styles[0].styleId,
}));
} else {
return defaultStyleIds;
}
});

ipcMainHandle("SET_DEFAULT_STYLE_IDS", (_, defaultStyleIds) => {
store.set("defaultStyleIds", defaultStyleIds);
});
Expand Down
8 changes: 0 additions & 8 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ const api: Sandbox = {
return await ipcRendererInvoke("GET_APP_INFOS");
},

getCharacterInfos: async () => {
return await ipcRendererInvoke("GET_CHARACTER_INFOS");
},

getHowToUseText: async () => {
return await ipcRendererInvoke("GET_HOW_TO_USE_TEXT");
},
Expand Down Expand Up @@ -188,10 +184,6 @@ const api: Sandbox = {
return await ipcRendererInvoke("IS_UNSET_DEFAULT_STYLE_ID", speakerUuid);
},

getDefaultStyleIds: async () => {
return await ipcRendererInvoke("GET_DEFAULT_STYLE_IDS");
},

setDefaultStyleIds: async (defaultStyleIds) => {
await ipcRendererInvoke("SET_DEFAULT_STYLE_IDS", defaultStyleIds);
},
Expand Down
10 changes: 0 additions & 10 deletions src/type/ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ type IpcIHData = {
return: string;
};

GET_CHARACTER_INFOS: {
args: [];
return: import("@/type/preload").CharacterInfo[];
};

GET_HOW_TO_USE_TEXT: {
args: [];
return: string;
Expand Down Expand Up @@ -157,11 +152,6 @@ type IpcIHData = {
return: boolean;
};

GET_DEFAULT_STYLE_IDS: {
args: [];
return: import("@/type/preload").DefaultStyleId[];
};

SET_DEFAULT_STYLE_IDS: {
args: [defaultStyleIds: { speakerUuid: string; defaultStyleId: number }[]];
return: void;
Expand Down
2 changes: 0 additions & 2 deletions src/type/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IpcRenderer, IpcRendererEvent } from "electron";

export interface Sandbox {
getAppInfos(): Promise<AppInfos>;
getCharacterInfos(): Promise<CharacterInfo[]>;
getHowToUseText(): Promise<string>;
getPolicyText(): Promise<string>;
getOssLicenses(): Promise<Record<string, string>[]>;
Expand Down Expand Up @@ -53,7 +52,6 @@ export interface Sandbox {
checkFileExists(file: string): Promise<boolean>;
changePinWindow(): void;
isUnsetDefaultStyleId(speakerUuid: string): Promise<boolean>;
getDefaultStyleIds(): Promise<DefaultStyleId[]>;
setDefaultStyleIds(
defaultStyleIds: { speakerUuid: string; defaultStyleId: number }[]
): Promise<void>;
Expand Down
9 changes: 4 additions & 5 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,10 @@ export default defineComponent({
// プロジェクトを初期化
onMounted(async () => {
await store.dispatch("START_WAITING_ENGINE").then(async () => {
await store.dispatch("LOAD_CHARACTER").then(async () => {
await store.dispatch("LOAD_DEFAULT_STYLE_IDS");
});
});
await store.dispatch("START_WAITING_ENGINE");
await store.dispatch("LOAD_CHARACTER");
await store.dispatch("LOAD_DEFAULT_STYLE_IDS");
let isUnsetDefaultStyleIds = false;
if (characterInfos.value == undefined) throw new Error();
for (const info of characterInfos.value) {
Expand Down

0 comments on commit 3166476

Please sign in to comment.