Skip to content

Commit

Permalink
Merge branch 'main' into エンジンのmockを作る
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Nov 6, 2024
2 parents a70082d + 3b6bd19 commit 5a1bfbe
Show file tree
Hide file tree
Showing 15 changed files with 1,059 additions and 956 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/DANGEROUS_trigger_preview_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Trigger preview-pages' workflow"

# プレビュー用ページのワークフローを起動する。
# 詳細: https://github.com/voicevox/preview-pages?tab=readme-ov-file#%E4%BB%95%E7%B5%84%E3%81%BF

on:
pull_request_target:
types:
- opened
- synchronize
- closed
- reopened
push:
branches:
- main
- project-*

jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Trigger Workflow
run: |
gh workflow run -R voicevox/preview-pages update_pages.yml
env:
GH_TOKEN: ${{ secrets.TRIGGER_PREVIEW_PAGES_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/build_preview_pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Build Preview Pages"

# プレビュー用ページをビルドする。
# 詳細: https://github.com/voicevox/preview-pages?tab=readme-ov-file#%E4%BB%95%E7%B5%84%E3%81%BF

on:
push:
branches:
- main
- project-*
pull_request:

jobs:
# このJobの名前を変更したときは、voicevox/preview-pages側のscripts/collect.tsも変更すること。
build_preview_pages:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup environment
uses: ./.github/actions/setup-environment

- name: Build
run: |
npm run storybook:build -- --output-dir $(pwd)/dist_preview/storybook
npm run browser:build -- --base ./ --outDir $(pwd)/dist_preview/editor
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: preview-pages
path: dist_preview
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ electron-builder.yml

# Storybook
storybook-static/

# Preview Build Output
dist_preview/
4 changes: 2 additions & 2 deletions src/backend/browser/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
} from "@/type/preload";
import { AssetTextFileNames } from "@/type/staticResources";

// TODO: base pathを設定できるようにするか、ビルド時埋め込みにする
const toStaticPath = (fileName: string) => `/${fileName}`;
const toStaticPath = (fileName: string) =>
`${import.meta.env.BASE_URL}/${fileName}`.replaceAll(/\/\/+/, "/");

// FIXME: asを使わないようオーバーロードにした。オーバーロードも使わない書き方にしたい。
function onReceivedIPCMsg<
Expand Down
41 changes: 29 additions & 12 deletions src/backend/electron/engineAndVvppController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import log from "electron-log/main";
import { BrowserWindow, dialog } from "electron";

import EngineInfoManager from "./manager/engineInfoManager";
import EngineProcessManager from "./manager/engineProcessManager";
import VvppManager from "./manager/vvppManager";
import { RuntimeInfoManager } from "./manager/RuntimeInfoManager";
import { ElectronConfigManager } from "./electronConfig";
import { getConfigManager } from "./electronConfig";
import { getEngineInfoManager } from "./manager/engineInfoManager";
import { getEngineProcessManager } from "./manager/engineProcessManager";
import { getRuntimeInfoManager } from "./manager/RuntimeInfoManager";
import { getVvppManager } from "./manager/vvppManager";
import {
EngineId,
EngineInfo,
Expand All @@ -17,13 +17,21 @@ import {
* エンジンとVVPP周りの処理の流れを制御するクラス。
*/
export class EngineAndVvppController {
constructor(
private runtimeInfoManager: RuntimeInfoManager,
private configManager: ElectronConfigManager,
private engineInfoManager: EngineInfoManager,
private engineProcessManager: EngineProcessManager,
private vvppManager: VvppManager,
) {}
private get configManager() {
return getConfigManager();
}
private get engineInfoManager() {
return getEngineInfoManager();
}
private get engineProcessManager() {
return getEngineProcessManager();
}
private get runtimeInfoManager() {
return getRuntimeInfoManager();
}
private get vvppManager() {
return getVvppManager();
}

/**
* VVPPエンジンをインストールする。
Expand Down Expand Up @@ -232,3 +240,12 @@ export class EngineAndVvppController {
return { engineCleanupResult, configSavedResult };
}
}

let manager: EngineAndVvppController | undefined;

export function getEngineAndVvppController() {
if (manager == undefined) {
manager = new EngineAndVvppController();
}
return manager;
}
54 changes: 23 additions & 31 deletions src/backend/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ import log from "electron-log/main";
import dayjs from "dayjs";
import windowStateKeeper from "electron-window-state";
import { hasSupportedGpu } from "./device";
import EngineInfoManager from "./manager/engineInfoManager";
import EngineProcessManager from "./manager/engineProcessManager";
import VvppManager, { isVvppFile } from "./manager/vvppManager";
import {
getEngineInfoManager,
initializeEngineInfoManager,
} from "./manager/engineInfoManager";
import {
getEngineProcessManager,
initializeEngineProcessManager,
} from "./manager/engineProcessManager";
import { initializeVvppManager, isVvppFile } from "./manager/vvppManager";
import configMigration014 from "./configMigration014";
import { RuntimeInfoManager } from "./manager/RuntimeInfoManager";
import { initializeRuntimeInfoManager } from "./manager/RuntimeInfoManager";
import { registerIpcMainHandle, ipcMainSendProxy, IpcMainHandle } from "./ipc";
import { getConfigManager } from "./electronConfig";
import { EngineAndVvppController } from "./engineAndVvppController";
import { getEngineAndVvppController } from "./engineAndVvppController";
import { writeFileSafely } from "./fileHelper";
import { failure, success } from "@/type/result";
import { AssetTextFileNames } from "@/type/staticResources";
Expand Down Expand Up @@ -170,35 +176,21 @@ const onEngineProcessError = (engineInfo: EngineInfo, error: Error) => {
dialog.showErrorBox("音声合成エンジンエラー", error.message);
};

const runtimeInfoManager = new RuntimeInfoManager(
path.join(app.getPath("userData"), "runtime-info.json"),
app.getVersion(),
);

const configManager = getConfigManager();

const engineInfoManager = new EngineInfoManager({
configManager,
initializeRuntimeInfoManager({
runtimeInfoPath: path.join(app.getPath("userData"), "runtime-info.json"),
appVersion: app.getVersion(),
});
initializeEngineInfoManager({
defaultEngineDir: appDirPath,
vvppEngineDir,
});
const engineProcessManager = new EngineProcessManager({
configManager,
onEngineProcessError,
engineInfosFetcher:
engineInfoManager.fetchEngineInfos.bind(engineInfoManager),
engineAltPortUpdater: engineInfoManager.updateAltPort.bind(engineInfoManager),
engineSettingsGetter: () => configManager.get("engineSettings"),
});
const vvppManager = new VvppManager({ vvppEngineDir });

const engineAndVvppController = new EngineAndVvppController(
runtimeInfoManager,
configManager,
engineInfoManager,
engineProcessManager,
vvppManager,
);
initializeEngineProcessManager({ onEngineProcessError });
initializeVvppManager({ vvppEngineDir });

const configManager = getConfigManager();
const engineInfoManager = getEngineInfoManager();
const engineProcessManager = getEngineProcessManager();
const engineAndVvppController = getEngineAndVvppController();

// エンジンのフォルダを開く
function openEngineDirectory(engineId: EngineId) {
Expand Down
16 changes: 16 additions & 0 deletions src/backend/electron/manager/RuntimeInfoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,19 @@ export class RuntimeInfoManager {
});
}
}

let manager: RuntimeInfoManager | undefined;

export function initializeRuntimeInfoManager(payload: {
runtimeInfoPath: string;
appVersion: string;
}) {
manager = new RuntimeInfoManager(payload.runtimeInfoPath, payload.appVersion);
}

export function getRuntimeInfoManager() {
if (manager == undefined) {
throw new Error("RuntimeInfoManager is not initialized");
}
return manager;
}
33 changes: 21 additions & 12 deletions src/backend/electron/manager/engineInfoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { dialog } from "electron"; // FIXME: ここでelectronをimportするの

import log from "electron-log/main";

import { getConfigManager } from "../electronConfig";
import {
EngineInfo,
EngineDirValidationResult,
Expand All @@ -14,7 +15,6 @@ import {
minimumEngineManifestSchema,
} from "@/type/preload";
import { AltPortInfos } from "@/store/type";
import { BaseConfigManager } from "@/backend/common/ConfigManager";
import { loadEnvEngineInfos } from "@/domain/defaultEngine/envEngineInfo";

/**
Expand Down Expand Up @@ -45,19 +45,13 @@ function fetchDefaultEngineInfos(defaultEngineDir: string): EngineInfo[] {

/** エンジンの情報を管理するクラス */
export class EngineInfoManager {
configManager: BaseConfigManager;
defaultEngineDir: string;
vvppEngineDir: string;

/** 代替ポート情報 */
public altPortInfos: AltPortInfos = {};

constructor(payload: {
configManager: BaseConfigManager;
defaultEngineDir: string;
vvppEngineDir: string;
}) {
this.configManager = payload.configManager;
constructor(payload: { defaultEngineDir: string; vvppEngineDir: string }) {
this.defaultEngineDir = payload.defaultEngineDir;
this.vvppEngineDir = payload.vvppEngineDir;
}
Expand Down Expand Up @@ -114,8 +108,9 @@ export class EngineInfoManager {
log.log(`Failed to load engine: ${result}, ${engineDir}`);
}
}
const configManager = getConfigManager();
// FIXME: この関数の引数でregisteredEngineDirsを受け取り、動かないエンジンをreturnして、EngineManager外でconfig.setする
for (const engineDir of this.configManager.get("registeredEngineDirs")) {
for (const engineDir of configManager.get("registeredEngineDirs")) {
const result = addEngine(engineDir, "path");
if (result !== "ok") {
log.log(`Failed to load engine: ${result}, ${engineDir}`);
Expand All @@ -125,9 +120,9 @@ export class EngineInfoManager {
"エンジンの読み込みに失敗しました。",
`${engineDir}を読み込めませんでした。このエンジンは削除されます。`,
);
this.configManager.set(
configManager.set(
"registeredEngineDirs",
this.configManager
configManager
.get("registeredEngineDirs")
.filter((p) => p !== engineDir),
);
Expand Down Expand Up @@ -221,4 +216,18 @@ export class EngineInfoManager {
}
}

export default EngineInfoManager;
let manager: EngineInfoManager | undefined;

export function initializeEngineInfoManager(payload: {
defaultEngineDir: string;
vvppEngineDir: string;
}) {
manager = new EngineInfoManager(payload);
}

export function getEngineInfoManager() {
if (manager == undefined) {
throw new Error("EngineInfoManager is not initialized");
}
return manager;
}
Loading

0 comments on commit 5a1bfbe

Please sign in to comment.