mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 09:20:18 +08:00
feat(install): 实现安装管理器,支持安装、检查已安装状态和初步卸载功能
This commit is contained in:
@@ -6,7 +6,7 @@ import pino from 'pino';
|
||||
|
||||
const logger = pino({ 'name': 'download-manager' });
|
||||
|
||||
type DownloadTask = {
|
||||
type InstallTask = {
|
||||
id: number;
|
||||
execCommand: string;
|
||||
execParams: string[];
|
||||
@@ -14,7 +14,7 @@ type DownloadTask = {
|
||||
webContents: WebContents | null;
|
||||
};
|
||||
|
||||
const tasks = new Map<number, DownloadTask>();
|
||||
const tasks = new Map<number, InstallTask>();
|
||||
|
||||
let idle = true; // Indicates if the installation manager is idle
|
||||
|
||||
@@ -82,7 +82,7 @@ ipcMain.on('queue-install', async (event, download_json) => {
|
||||
}
|
||||
execParams.push('install', '-y', pkgname);
|
||||
|
||||
const task: DownloadTask = {
|
||||
const task: InstallTask = {
|
||||
id,
|
||||
execCommand,
|
||||
execParams,
|
||||
@@ -166,4 +166,38 @@ function processNextInQueue(index: number) {
|
||||
if (tasks.size > 0)
|
||||
processNextInQueue(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ipcMain.handle('check-installed', async (_event, pkgname: string) => {
|
||||
if (!pkgname) {
|
||||
logger.warn('check-installed missing pkgname');
|
||||
return false;
|
||||
}
|
||||
let isInstalled = false;
|
||||
|
||||
logger.info(`检查应用是否已安装: ${pkgname}`);
|
||||
|
||||
let child = spawn('/usr/bin/apm', ['list', '--installed', pkgname], {
|
||||
shell: true,
|
||||
env: process.env
|
||||
});
|
||||
|
||||
let output = '';
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
output += data.toString();
|
||||
});
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
child.on('close', (code) => {
|
||||
if (code === 0 && output.includes(pkgname)) {
|
||||
isInstalled = true;
|
||||
logger.info(`应用已安装: ${pkgname}`);
|
||||
} else {
|
||||
logger.info(`应用未安装: ${pkgname}`);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
return isInstalled;
|
||||
});
|
||||
@@ -10,7 +10,7 @@ if (!app.requestSingleInstanceLock()) {
|
||||
}
|
||||
|
||||
import './handle-url-scheme.js'
|
||||
import './backend/download-manager.js'
|
||||
import './backend/install-manager.js'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
Reference in New Issue
Block a user