mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 09:20:18 +08:00
feat: enhance install manager to prevent duplicate package installations and improve app launching command
This commit is contained in:
@@ -5,11 +5,13 @@ import { promisify } from 'node:util';
|
|||||||
import pino from 'pino';
|
import pino from 'pino';
|
||||||
|
|
||||||
import { InstalledAppInfo } from '../../typedefinition';
|
import { InstalledAppInfo } from '../../typedefinition';
|
||||||
|
import { lookup } from 'node:dns';
|
||||||
|
|
||||||
const logger = pino({ 'name': 'install-manager' });
|
const logger = pino({ 'name': 'install-manager' });
|
||||||
|
|
||||||
type InstallTask = {
|
type InstallTask = {
|
||||||
id: number;
|
id: number;
|
||||||
|
pkgname: string;
|
||||||
execCommand: string;
|
execCommand: string;
|
||||||
execParams: string[];
|
execParams: string[];
|
||||||
process: ChildProcess | null;
|
process: ChildProcess | null;
|
||||||
@@ -147,6 +149,17 @@ ipcMain.on('queue-install', async (event, download_json) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.forEach((task) => {
|
||||||
|
if (task.pkgname === pkgname) {
|
||||||
|
task.webContents?.send('install-log', {
|
||||||
|
id: task.id,
|
||||||
|
time: Date.now(),
|
||||||
|
message: `软件包 ${pkgname} 已在安装队列中,忽略重复添加`
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const webContents = event.sender;
|
const webContents = event.sender;
|
||||||
|
|
||||||
// 开始组装安装命令
|
// 开始组装安装命令
|
||||||
@@ -163,6 +176,7 @@ ipcMain.on('queue-install', async (event, download_json) => {
|
|||||||
|
|
||||||
const task: InstallTask = {
|
const task: InstallTask = {
|
||||||
id,
|
id,
|
||||||
|
pkgname,
|
||||||
execCommand,
|
execCommand,
|
||||||
execParams,
|
execParams,
|
||||||
process: null,
|
process: null,
|
||||||
@@ -405,8 +419,15 @@ ipcMain.handle('launch-app', async (_event, pkgname: string) => {
|
|||||||
logger.warn('No pkgname provided for launch-app');
|
logger.warn('No pkgname provided for launch-app');
|
||||||
}
|
}
|
||||||
|
|
||||||
const execCommand = 'dbus-launch';
|
const execCommand = '/opt/apm-store/extras/apm-launcher';
|
||||||
const execParams = ['/opt/apm-store/extras/apm-launcher', 'start', pkgname];
|
const execParams = [ 'launch', pkgname ];
|
||||||
|
|
||||||
await runCommandCapture(execCommand, execParams);
|
logger.info(`Launching app: ${pkgname} with command: ${execCommand} ${execParams.join(' ')}`);
|
||||||
|
|
||||||
|
spawn(execCommand, execParams, {
|
||||||
|
shell: false,
|
||||||
|
env: process.env,
|
||||||
|
detached: true,
|
||||||
|
stdio: 'ignore'
|
||||||
|
}).unref();
|
||||||
});
|
});
|
||||||
@@ -53,11 +53,8 @@ function launch_app() {
|
|||||||
exec_cmd=$(grep -m1 '^Exec=' "$desktop_path" | cut -d= -f2- | sed 's/%[fFuUdDnNickvm]*//g; s/^[[:space:]]*//; s/[[:space:]]*$//')
|
exec_cmd=$(grep -m1 '^Exec=' "$desktop_path" | cut -d= -f2- | sed 's/%[fFuUdDnNickvm]*//g; s/^[[:space:]]*//; s/[[:space:]]*$//')
|
||||||
[ -z "$exec_cmd" ] && return 1
|
[ -z "$exec_cmd" ] && return 1
|
||||||
|
|
||||||
# ACE 环境内使用 host-spawn 在宿主显示图形界面
|
|
||||||
[ -n "$IS_ACE_ENV" ] && exec_cmd="host-spawn $exec_cmd"
|
|
||||||
|
|
||||||
log.info "Launching: $exec_cmd"
|
log.info "Launching: $exec_cmd"
|
||||||
${SHELL:-bash} -c "$exec_cmd" &
|
${SHELL:-bash} -i -c "$exec_cmd" &
|
||||||
}
|
}
|
||||||
|
|
||||||
# 导出函数供 ACE 环境调用
|
# 导出函数供 ACE 环境调用
|
||||||
|
|||||||
Reference in New Issue
Block a user