Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into 指定されているVVPPがなかったら確認…
Browse files Browse the repository at this point in the history
…後にインストールし、使えるようにするようにする
  • Loading branch information
Hiroshiba committed Nov 6, 2024
2 parents 016e142 + 3b6bd19 commit 965cee5
Show file tree
Hide file tree
Showing 15 changed files with 1,060 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
Expand Up @@ -3,11 +3,11 @@ import fs from "fs";
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 @@ -28,13 +28,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 @@ -335,3 +343,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 @@ -114,3 +114,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;
}
34 changes: 22 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 { UnreachableError } from "@/type/utility";
import {
EnvEngineInfoType,
Expand Down Expand Up @@ -95,7 +95,6 @@ function loadEngineInfo(

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

Expand All @@ -104,12 +103,7 @@ export class EngineInfoManager {

private envEngineInfos = loadEnvEngineInfos();

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 @@ -143,8 +137,10 @@ export class EngineInfoManager {
* FIXME: store.get("registeredEngineDirs")への副作用をEngineManager外に移動する
*/
private fetchRegisteredEngineInfos(): EngineInfo[] {
const configManager = getConfigManager();

const engineInfos: EngineInfo[] = [];
for (const engineDir of this.configManager.get("registeredEngineDirs")) {
for (const engineDir of configManager.get("registeredEngineDirs")) {
const result = loadEngineInfo(engineDir, "path");
if (!result.ok) {
log.log(`Failed to load engine: ${result.code}, ${engineDir}`);
Expand All @@ -154,9 +150,9 @@ export class EngineInfoManager {
"エンジンの読み込みに失敗しました。",
`${engineDir}を読み込めませんでした。このエンジンは削除されます。`,
);
this.configManager.set(
configManager.set(
"registeredEngineDirs",
this.configManager
configManager
.get("registeredEngineDirs")
.filter((p) => p !== engineDir),
);
Expand Down Expand Up @@ -288,4 +284,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 965cee5

Please sign in to comment.