[ Feat] Impl file-based IPC for Aikari installation

This commit is contained in:
Minoricew
2025-12-16 02:04:17 +08:00
parent 1031bf04bb
commit 420f35a5e4
3 changed files with 247 additions and 129 deletions

View File

@@ -9,11 +9,12 @@
<br /> <br />
<center> <center>
<a href="https://campus.seewo.com/iot-public/file/?key=iot_doc_seewoServiceUpdateLog"> <a href="https://forum.smart-teach.cn/d/898-xi-wo-guan-jia-zhe-kuai-zhen-de-shi-zhao-xiao-si-liao">
<img src="https://docs.aurax.cc/static/img/emg_announcement_banner.png" /> <img src="https://docs.aurax.cc/static/img/emg_announcement_banner.png" />
</a> </a>
</center> </center>
<br />
<br /> <br />
> [!TIP] > [!TIP]

View File

@@ -68,8 +68,20 @@ const functions = {
* @param {"stable" | "alpha"} channel * @param {"stable" | "alpha"} channel
* @param {(arg: DownloadTask) => any} callbackFn * @param {(arg: DownloadTask) => any} callbackFn
* @param {string} binPath * @param {string} binPath
* @param {string} logPath
* @param {string} progressFilePath
*/ */
handleAikariDlAndInstall: async (channel, callbackFn, binPath) => { handleAikariDlAndInstall: async (
channel,
callbackFn,
binPath,
logPath,
progressFilePath
) => {
let dlResult = false;
if (fs.existsSync(path.join(path.dirname(binPath), ".force"))) {
dlResult = true;
} else {
// TODO: Channel selection // TODO: Channel selection
const apiInfo = global.__HUGO_AURA_API__; const apiInfo = global.__HUGO_AURA_API__;
@@ -98,7 +110,9 @@ const functions = {
dlUrl: null, dlUrl: null,
savePath: null, savePath: null,
message: `数据解析失败, 正在尝试 API 域名 ${ message: `数据解析失败, 正在尝试 API 域名 ${
apiInfo.domains[apiInfo.domains.indexOf(apiDomain) + 1] apiInfo.domains[
apiInfo.domains.indexOf(apiDomain) + 1
]
} ...`, } ...`,
errorObj: e, errorObj: e,
}); });
@@ -182,7 +196,9 @@ const functions = {
// @ts-expect-error // @ts-expect-error
deviceArch = deviceArch.toLowerCase(); deviceArch = deviceArch.toLowerCase();
if (!Object.keys(aikariVersionInfo.data.downloadUrl).includes(deviceArch)) { if (
!Object.keys(aikariVersionInfo.data.downloadUrl).includes(deviceArch)
) {
callbackFn({ callbackFn({
id: "", id: "",
progress: 0, progress: 0,
@@ -210,7 +226,8 @@ const functions = {
); );
}); });
const dlResult = await downloadFilePromise; dlResult = await downloadFilePromise;
}
if (dlResult) { if (dlResult) {
callbackFn({ callbackFn({
@@ -224,7 +241,7 @@ const functions = {
const runInstPromise = new Promise((resolve) => { const runInstPromise = new Promise((resolve) => {
exec( exec(
`"${binPath}" /VERYSILENT /SUPPRESSMSGBOXES /LOG="${binPath}\\..\\Aikari-Install.log"`, `"${binPath}" /VERYSILENT /SUPPRESSMSGBOXES /LOG="${logPath}" /PROGRESS_FILE="${progressFilePath}"`,
(err, stdout, stderr) => { (err, stdout, stderr) => {
if (err) { if (err) {
console.error( console.error(
@@ -237,6 +254,13 @@ const functions = {
); );
}); });
if (!fs.existsSync(path.dirname(progressFilePath))) {
fs.mkdirSync(path.dirname(progressFilePath));
}
if (!fs.existsSync(progressFilePath)) {
fs.writeFileSync(progressFilePath, "");
}
callbackFn({ callbackFn({
id: "INSTALL_STAGE", id: "INSTALL_STAGE",
progress: 15, progress: 15,
@@ -246,8 +270,87 @@ const functions = {
message: "正在安装 Aikari...", message: "正在安装 Aikari...",
}); });
let instFilesStageLastFakeLoadProgressPercent = -1;
const fileProgressWatcher = fs.watch(progressFilePath, (eventType) => {
if (eventType === "change") {
try {
const content = fs.readFileSync(progressFilePath, "utf-8").trim();
if (content === "") {
callbackFn({
id: "INSTALL_STAGE",
progress: 20,
status: "progressing",
dlUrl: null,
savePath: null,
message: "正在准备安装...",
});
} else {
const contentArr = content.split(";");
switch (contentArr[0]) {
case "DL_VC_REDIST":
callbackFn({
id: "INSTALL_STAGE",
progress:
20 +
Math.round((parseFloat(contentArr[1]) / 10) * 2), // 20 + [0, 20] === 20 ~ 40
status: "progressing",
dlUrl: null,
savePath: null,
message: `正在下载 VC++ 运行时... (${contentArr[1]}%)`,
});
break;
case "INST_FILES":
if (instFilesStageLastFakeLoadProgressPercent === -1) {
instFilesStageLastFakeLoadProgressPercent = 60;
} else if (instFilesStageLastFakeLoadProgressPercent < 85) {
instFilesStageLastFakeLoadProgressPercent +=
Math.random() * (5 - 1) + 1;
}
callbackFn({
id: "INSTALL_STAGE",
progress: instFilesStageLastFakeLoadProgressPercent,
status: "progressing",
dlUrl: null,
savePath: null,
message: `正在解压文件...`,
});
break;
case "INST_VC_REDIST":
callbackFn({
id: "INSTALL_STAGE",
progress: 90,
status: "progressing",
dlUrl: null,
savePath: null,
message: `正在安装 VC++ 运行时...`,
});
break;
case "DONE":
callbackFn({
id: "INSTALL_STAGE",
progress: 99,
status: "progressing",
dlUrl: null,
savePath: null,
message: `即将完成`,
});
break;
}
}
} catch (e) {
// Ignore
}
}
});
const instResult = await runInstPromise; const instResult = await runInstPromise;
fileProgressWatcher.close();
callbackFn({ callbackFn({
id: "INSTALL_STAGE", id: "INSTALL_STAGE",
progress: 100, progress: 100,
@@ -267,6 +370,8 @@ const functions = {
} }
fs.unlinkSync(binPath); fs.unlinkSync(binPath);
fs.unlinkSync(logPath);
fs.unlinkSync(progressFilePath);
} }
}, },
clearHostFileItem: async () => { clearHostFileItem: async () => {
@@ -341,6 +446,14 @@ const applyAikariIpcHandler = (ipcMain) => {
AIKARI_TEMP_DL_DIR, AIKARI_TEMP_DL_DIR,
"Aikari-Installer.exe" "Aikari-Installer.exe"
); );
const AIKARI_INSTALLER_LOG_FILENAME = path.join(
AIKARI_TEMP_DL_DIR,
"install.log"
);
const AIKARI_INSTALLER_PROGRESS_FIPC_FILENAME = path.join(
AIKARI_TEMP_DL_DIR,
"PROGRESS"
);
// Prev PLS Cfg // Prev PLS Cfg
const OLD_PLS_INSTALL_DIR = path.join( const OLD_PLS_INSTALL_DIR = path.join(
@@ -694,6 +807,8 @@ const applyAikariIpcHandler = (ipcMain) => {
async (_evt, arg) => { async (_evt, arg) => {
if (fs.existsSync(AIKARI_TEMP_DL_DIR)) { if (fs.existsSync(AIKARI_TEMP_DL_DIR)) {
try { try {
fs.unlinkSync(AIKARI_INSTALLER_LOG_FILENAME);
fs.unlinkSync(AIKARI_INSTALLER_PROGRESS_FIPC_FILENAME);
fs.unlinkSync(AIKARI_TEMP_DL_DIR); fs.unlinkSync(AIKARI_TEMP_DL_DIR);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@@ -725,7 +840,9 @@ const applyAikariIpcHandler = (ipcMain) => {
status status
); );
}, },
AIKARI_TEMP_INSTALLER_FILENAME AIKARI_TEMP_INSTALLER_FILENAME,
AIKARI_INSTALLER_LOG_FILENAME,
AIKARI_INSTALLER_PROGRESS_FIPC_FILENAME
); );
} }
); );

View File

@@ -31,8 +31,8 @@ if (!global.__HUGO_AURA_UI_REACTIVES__.subConfig)
getRetryStatusDescByErrId: (errIdString) => { getRetryStatusDescByErrId: (errIdString) => {
switch (errIdString) { switch (errIdString) {
case "E_AUTH_TOKEN_GET_FAILED": case "E_AUTH_TOKEN_GET_FAILED":
return `<p>Aikari 注册表访问失败, 这是一个极为罕见的问题</p> return `<p>Aikari 注册表访问失败, 这可能代表 Aikari 在启动后立即发生了崩溃</p>
<p>请检查 HKEY_USERS\\.DEFAULT 是否存在, 并反馈至 GitHub Issues</p>`; <p>请将此情况反馈至 GitHub Issues, 并附上您的系统版本信息</p>`;
case "E_WS_CONN_FAILED_AFT_MULTIPLE_TRIES": case "E_WS_CONN_FAILED_AFT_MULTIPLE_TRIES":
return `<p>在多次尝试连接后仍然失败, 请检查服务是否已启动</p>`; return `<p>在多次尝试连接后仍然失败, 请检查服务是否已启动</p>`;
case "E_IS_LOADING": case "E_IS_LOADING":
@@ -921,7 +921,7 @@ if (!global.__HUGO_AURA_UI_REACTIVES__.subConfig)
} else { } else {
GLOBAL_FUNCTIONS.updatePBarStatus( GLOBAL_FUNCTIONS.updatePBarStatus(
info.progress, info.progress,
`正在安装 Aikari...`, info.message,
"normal", "normal",
false false
); );