Skip to content

Commit

Permalink
サードパーティがエンジンへのアクセス情報を得るための設定書き出し機能(ref VOICEVOX#1738)
Browse files Browse the repository at this point in the history
* ファイルは runtime-info.json に書き出し
* エンジン全起動もしくは個別起動/終了のタイミングで更新
  • Loading branch information
nmori committed Jan 26, 2024
1 parent a37c7a2 commit 80008bc
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/background/engineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export class EngineManager {
log.info(`ENGINE ${engineInfo.uuid}: Start launching`);
await this.runEngine(engineInfo.uuid);
}

await this.makeEngineInfoFor3rdParty();
}

/**
Expand Down Expand Up @@ -469,6 +471,7 @@ export class EngineManager {
);

this.runEngine(engineId);
this.makeEngineInfoFor3rdParty();
resolve();
return;
}
Expand All @@ -482,6 +485,7 @@ export class EngineManager {
log.info(`ENGINE ${engineId}: Process killed. Restarting process...`);

this.runEngine(engineId);
this.makeEngineInfoFor3rdParty();
resolve();
};

Expand Down Expand Up @@ -544,6 +548,41 @@ export class EngineManager {
}
return "ok";
}

/**
* サードパーティ向けの設定ファイルを書き出す
*/
async makeEngineInfoFor3rdParty() {
const exportEngineInfoFilename = path.join(
app.getPath("userData"),
"runtime-info.json"
);
const engineInfos = this.fetchEngineInfos();

log.info(`Update list of engines...` + exportEngineInfoFilename);

const engineInfoList = engineInfos.map((engineInfo) => {
return {
uuid: engineInfo.uuid,
host: engineInfo.host,
name: engineInfo.name,
path: engineInfo.path,
executionEnabled: engineInfo.executionEnabled,
executionFilePath: engineInfo.executionFilePath,
executionArgs: engineInfo.executionArgs,
type: engineInfo.type,
};
});

try {
fs.writeFileSync(
exportEngineInfoFilename,
JSON.stringify(engineInfoList)
);
} catch (e) {
return "failedToWriteFile";
}
}
}

export default EngineManager;

0 comments on commit 80008bc

Please sign in to comment.