Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: electronのカレントディレクトリの変更のロジックを共通化 #2570

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/backend/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ process.on("unhandledRejection", (reason) => {
log.error(reason);
});

function initializeAppPaths() {
function getAppPaths() {
let appDirPath: string;
let __static: string;

Expand All @@ -123,13 +123,12 @@ function initializeAppPaths() {
__static = path.join(appDirPath, "public");
} else {
appDirPath = path.dirname(app.getPath("exe"));
process.chdir(appDirPath);
__static = __dirname;
}

return { appDirPath, __static };
}
const { appDirPath, __static } = initializeAppPaths();
const { appDirPath, __static } = getAppPaths();

protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true, stream: true } },
Expand Down Expand Up @@ -196,7 +195,7 @@ initializeRuntimeInfoManager({
appVersion: app.getVersion(),
});
initializeEngineInfoManager({
defaultEngineDir: appDirPath,
appDirPath,
vvppEngineDir,
Comment on lines 197 to 199
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

引数defaultEngineDirにはappDirPathを渡してたのですが、ややこしいからもうappDirPathのまま受け取るようにしてみました。
VOICEVOXの場合、「デフォルトエンジンディレクトリ」の場所はどっちかというと{appDirPath}/vv-engineだよなぁと思ったので。

});
initializeEngineProcessManager({ onEngineProcessError });
Expand Down
15 changes: 9 additions & 6 deletions src/backend/electron/manager/engineInfoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const log = createLogger("EngineInfoManager");

/** 利用可能なエンジンの情報を管理するクラス */
export class EngineInfoManager {
defaultEngineDir: string;
appDirPath: string;
vvppEngineDir: string;

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

private envEngineInfos = loadEnvEngineInfos();

constructor(payload: { defaultEngineDir: string; vvppEngineDir: string }) {
this.defaultEngineDir = payload.defaultEngineDir;
constructor(payload: { appDirPath: string; vvppEngineDir: string }) {
this.appDirPath = payload.appDirPath;
this.vvppEngineDir = payload.vvppEngineDir;
}

Expand Down Expand Up @@ -93,11 +93,14 @@ export class EngineInfoManager {
pathname: pathname === "/" ? "" : pathname,
isDefault: true,
type: engineInfo.type,
executionFilePath: path.resolve(engineInfo.executionFilePath),
executionFilePath: path.resolve(
this.appDirPath,
engineInfo.executionFilePath,
),
path:
engineInfo.path == undefined
? undefined
: path.resolve(this.defaultEngineDir, engineInfo.path),
: path.resolve(this.appDirPath, engineInfo.path),
} satisfies EngineInfo;
});
}
Expand Down Expand Up @@ -253,7 +256,7 @@ export class EngineInfoManager {
let manager: EngineInfoManager | undefined;

export function initializeEngineInfoManager(payload: {
defaultEngineDir: string;
appDirPath: string;
vvppEngineDir: string;
}) {
manager = new EngineInfoManager(payload);
Expand Down
1 change: 1 addition & 0 deletions src/domain/defaultEngine/envEngineInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const envEngineInfoSchema = z
.and(
z.union([
// エンジンをパス指定する場合
// NOTE: 相対パスの場合はアプリのパスで解決する
z.object({
type: z.literal("path").default("path"),
executionFilePath: z.string(),
Expand Down
Loading