mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 01:10:16 +08:00
feat: implement apm app install and uninstall logic with pkexec elevation
- Modify `queue-install` logic to wrap `apm` commands with `superUserCmd` and `SHELL_CALLER_PATH` when origin is apm. - Update `remove-installed` to correctly execute `apm remove -y pkgname` with required privilege elevation when origin is apm. - Add payload parsing logic in `uninstall-installed` handler to identify origin and apply correct `apm` uninstall command dynamically.
This commit is contained in:
@@ -196,9 +196,11 @@ ipcMain.on("queue-install", async (event, download_json) => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// APM Store logic
|
// APM Store logic
|
||||||
execCommand = "apm"; // apm handles its own sudo if needed or we use pkexec wrap if required
|
execCommand = superUserCmd || SHELL_CALLER_PATH;
|
||||||
// Actually, usually apm is called directly and it might prompt.
|
if (superUserCmd) {
|
||||||
// Let's stick to the pattern of using SHELL_CALLER_PATH if possible or follow apm-app-store demo.
|
execParams.push(SHELL_CALLER_PATH);
|
||||||
|
}
|
||||||
|
execParams.push("apm");
|
||||||
|
|
||||||
if (metalinkUrl && filename) {
|
if (metalinkUrl && filename) {
|
||||||
execParams.push("ssaudit", `${downloadDir}/${filename}`);
|
execParams.push("ssaudit", `${downloadDir}/${filename}`);
|
||||||
@@ -517,14 +519,14 @@ ipcMain.on("remove-installed", async (_event, payload) => {
|
|||||||
let execCommand = "";
|
let execCommand = "";
|
||||||
const execParams = [];
|
const execParams = [];
|
||||||
|
|
||||||
|
const superUserCmd = await checkSuperUserCommand();
|
||||||
|
execCommand = superUserCmd || SHELL_CALLER_PATH;
|
||||||
|
if (superUserCmd) execParams.push(SHELL_CALLER_PATH);
|
||||||
|
|
||||||
if (origin === "spark") {
|
if (origin === "spark") {
|
||||||
const superUserCmd = await checkSuperUserCommand();
|
|
||||||
execCommand = superUserCmd || SHELL_CALLER_PATH;
|
|
||||||
if (superUserCmd) execParams.push(SHELL_CALLER_PATH);
|
|
||||||
execParams.push("aptss", "remove", pkgname);
|
execParams.push("aptss", "remove", pkgname);
|
||||||
} else {
|
} else {
|
||||||
execCommand = "apm";
|
execParams.push("apm", "remove", "-y", pkgname);
|
||||||
execParams.push("remove", pkgname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const child = spawn(execCommand, execParams, {
|
const child = spawn(execCommand, execParams, {
|
||||||
@@ -609,19 +611,25 @@ ipcMain.handle("list-installed", async () => {
|
|||||||
return { success: true, apps };
|
return { success: true, apps };
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("uninstall-installed", async (_event, pkgname: string) => {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
ipcMain.handle("uninstall-installed", async (_event, payload: any) => {
|
||||||
|
const pkgname = typeof payload === "string" ? payload : payload.pkgname;
|
||||||
|
const origin = typeof payload === "string" ? "spark" : payload.origin;
|
||||||
|
|
||||||
if (!pkgname) {
|
if (!pkgname) {
|
||||||
logger.warn("uninstall-installed missing pkgname");
|
logger.warn("uninstall-installed missing pkgname");
|
||||||
return { success: false, message: "missing pkgname" };
|
return { success: false, message: "missing pkgname" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const superUserCmd = await checkSuperUserCommand();
|
const superUserCmd = await checkSuperUserCommand();
|
||||||
const execCommand =
|
const execCommand = superUserCmd || SHELL_CALLER_PATH;
|
||||||
superUserCmd.length > 0 ? superUserCmd : SHELL_CALLER_PATH;
|
const execParams = superUserCmd ? [SHELL_CALLER_PATH] : [];
|
||||||
const execParams =
|
|
||||||
superUserCmd.length > 0
|
if (origin === "apm") {
|
||||||
? [SHELL_CALLER_PATH, "aptss", "remove", "-y", pkgname]
|
execParams.push("apm", "remove", "-y", pkgname);
|
||||||
: ["aptss", "remove", "-y", pkgname];
|
} else {
|
||||||
|
execParams.push("aptss", "remove", "-y", pkgname);
|
||||||
|
}
|
||||||
|
|
||||||
const { code, stdout, stderr } = await runCommandCapture(
|
const { code, stdout, stderr } = await runCommandCapture(
|
||||||
execCommand,
|
execCommand,
|
||||||
|
|||||||
1
package-lock.json
generated
1
package-lock.json
generated
@@ -7028,6 +7028,7 @@
|
|||||||
"version": "2.6.1",
|
"version": "2.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/jiti/-/jiti-2.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/jiti/-/jiti-2.6.1.tgz",
|
||||||
"integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==",
|
"integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==",
|
||||||
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"jiti": "lib/jiti-cli.mjs"
|
"jiti": "lib/jiti-cli.mjs"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user