mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 01:10:16 +08:00
优化启动速度
This commit is contained in:
@@ -138,7 +138,7 @@ const parseUpgradableList = (output: string) => {
|
||||
// Listen for download requests from renderer process
|
||||
ipcMain.on("queue-install", async (event, download_json) => {
|
||||
const download = JSON.parse(download_json);
|
||||
const { id, pkgname, metalinkUrl, filename } = download || {};
|
||||
const { id, pkgname, metalinkUrl, filename, upgradeOnly } = download || {};
|
||||
|
||||
if (!id || !pkgname) {
|
||||
logger.warn("passed arguments missing id or pkgname");
|
||||
@@ -172,17 +172,28 @@ ipcMain.on("queue-install", async (event, download_json) => {
|
||||
const execParams = [];
|
||||
const downloadDir = `/tmp/spark-store/download/${pkgname}`;
|
||||
|
||||
if (superUserCmd.length > 0) {
|
||||
// 升级操作:使用 spark-update-tool
|
||||
if (upgradeOnly) {
|
||||
execCommand = "pkexec";
|
||||
execParams.push("spark-update-tool", pkgname);
|
||||
logger.info(`升级模式: 使用 spark-update-tool 升级 ${pkgname}`);
|
||||
} else if (superUserCmd.length > 0) {
|
||||
execCommand = superUserCmd;
|
||||
execParams.push(SHELL_CALLER_PATH);
|
||||
|
||||
if (metalinkUrl && filename) {
|
||||
execParams.push("ssinstall", `${downloadDir}/${filename}`, "--delete-after-install");
|
||||
} else {
|
||||
execParams.push("aptss", "install", "-y", pkgname);
|
||||
}
|
||||
} else {
|
||||
execCommand = SHELL_CALLER_PATH;
|
||||
}
|
||||
|
||||
if (metalinkUrl && filename) {
|
||||
execParams.push("ssinstall", `${downloadDir}/${filename}` , "--delete-after-install");
|
||||
} else {
|
||||
execParams.push("aptss", "install", "-y", pkgname);
|
||||
if (metalinkUrl && filename) {
|
||||
execParams.push("ssinstall", `${downloadDir}/${filename}`, "--delete-after-install");
|
||||
} else {
|
||||
execParams.push("aptss", "install", "-y", pkgname);
|
||||
}
|
||||
}
|
||||
|
||||
const task: InstallTask = {
|
||||
|
||||
@@ -140,6 +140,26 @@ ipcMain.on("set-theme-source", (event, theme: "system" | "light" | "dark") => {
|
||||
nativeTheme.themeSource = theme;
|
||||
});
|
||||
|
||||
// 启动系统更新工具(使用 pkexec 提升权限)
|
||||
ipcMain.handle("run-update-tool", async () => {
|
||||
try {
|
||||
const { spawn } = await import("node:child_process");
|
||||
const pkexecPath = "/usr/bin/pkexec";
|
||||
const args = ["spark-update-tool"];
|
||||
const child = spawn(pkexecPath, args, {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
});
|
||||
// 让子进程在后台运行且不影响主进程退出
|
||||
child.unref();
|
||||
logger.info("Launched pkexec spark-update-tool");
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
logger.error({ err }, "Failed to launch spark-update-tool");
|
||||
return { success: false, message: (err as Error)?.message || String(err) };
|
||||
}
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
// Set User-Agent for client
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
|
||||
Reference in New Issue
Block a user