mirror of
https://github.com/ivabus/gui
synced 2025-06-07 15:50:27 +03:00
#186 install package invoke handlr
This commit is contained in:
parent
61ecc1ed42
commit
e61c09b585
4 changed files with 41 additions and 34 deletions
|
@ -8,6 +8,7 @@ import fs from 'fs';
|
|||
import { getInstalledPackages } from './libs/teaDir';
|
||||
import { readSessionData, writeSessionData } from './libs/auth';
|
||||
import type { Session } from '../src/libs/types';
|
||||
import { installPackage } from './libs/cli';
|
||||
|
||||
// try {
|
||||
// //@ts-ignore only used in dev should not be packaged inprod
|
||||
|
@ -127,3 +128,8 @@ ipcMain.handle('get-session', async () => {
|
|||
ipcMain.handle('update-session', async (_, data) => {
|
||||
await writeSessionData(data as Session);
|
||||
});
|
||||
|
||||
ipcMain.handle('install-package', async (_, data) => {
|
||||
const result = await installPackage(data.full_name);
|
||||
return result;
|
||||
});
|
||||
|
|
29
modules/desktop/electron/libs/cli.ts
Normal file
29
modules/desktop/electron/libs/cli.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { spawn } from 'child_process';
|
||||
import { clean } from 'semver';
|
||||
|
||||
export async function installPackage(full_name: string) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
let version = '';
|
||||
let lastError = '';
|
||||
const teaInstallation = spawn('tea', [`+${full_name}`, 'true']);
|
||||
|
||||
teaInstallation.stdout.on('data', (data) => {
|
||||
console.log('stdout:', data);
|
||||
});
|
||||
|
||||
teaInstallation.stderr.on('data', (err) => {
|
||||
lastError = err.toString();
|
||||
if (lastError && lastError.includes('installed') && lastError.includes(full_name)) {
|
||||
version = lastError.split('/').pop() || '';
|
||||
}
|
||||
});
|
||||
|
||||
teaInstallation.on('exit', (code) => {
|
||||
if (code === 0) {
|
||||
resolve({ version: clean(version) });
|
||||
} else {
|
||||
reject(new Error(lastError));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,32 +1,6 @@
|
|||
const { ipcRenderer } = window.require('electron');
|
||||
|
||||
export async function installPackageCommand(full_name: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// const teaInstallCommand = new Command('tea-install', [`+${full_name}`, 'true']);
|
||||
// teaInstallCommand.on('error', reject);
|
||||
|
||||
// const handleLineOutput = async (line: string | { code: number }) => {
|
||||
// const c = await child;
|
||||
// if (
|
||||
// (typeof line === 'string' && line.includes('installed:')) ||
|
||||
// (typeof line !== 'string' && line?.code === 0)
|
||||
// ) {
|
||||
// c.kill();
|
||||
// resolve(c.pid);
|
||||
// } else if (typeof line !== 'string' && line?.code === 1) {
|
||||
// reject();
|
||||
// }
|
||||
// };
|
||||
|
||||
// teaInstallCommand.stdout.on('data', handleLineOutput);
|
||||
// teaInstallCommand.stderr.on('data', handleLineOutput);
|
||||
// teaInstallCommand.on('close', (line: string) => {
|
||||
// console.log('command closed!');
|
||||
// handleLineOutput(line || '');
|
||||
// });
|
||||
// teaInstallCommand.on('error', (line: string) => {
|
||||
// console.log('command error!', line);
|
||||
// handleLineOutput(line || '');
|
||||
// });
|
||||
// const child = teaInstallCommand.spawn();
|
||||
setTimeout(resolve, 10000);
|
||||
});
|
||||
const res = await ipcRenderer.invoke('install-package', { full_name });
|
||||
console.log('install:', res);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { writable } from 'svelte/store';
|
||||
// import { app } from 'electron';
|
||||
// import { join } from 'upath';
|
||||
// import fs from 'fs';
|
||||
import { getDeviceAuth, registerDevice } from '@api';
|
||||
|
||||
import { getDeviceAuth } from '@api';
|
||||
import type { Developer } from '@tea/ui/types';
|
||||
import type { Session } from '$libs/types';
|
||||
|
||||
|
|
Loading…
Reference in a new issue