support execution

This commit is contained in:
srgooglo 2023-10-31 19:59:58 +01:00
parent c8aa3d7cba
commit ad2d9cc4b3
4 changed files with 72 additions and 11 deletions

View File

@ -29,7 +29,7 @@ class ElectronApp {
this.pkgManager.update(manifest_id) this.pkgManager.update(manifest_id)
}, },
"bundle:exec": (event, manifest_id) => { "bundle:exec": (event, manifest_id) => {
this.pkgManager.exec(manifest_id) this.pkgManager.execute(manifest_id)
}, },
"bundle:install": async (event, manifest) => { "bundle:install": async (event, manifest) => {
this.pkgManager.install(manifest) this.pkgManager.install(manifest)

View File

@ -594,4 +594,67 @@ export default class PkgManager {
console.error(error) console.error(error)
} }
} }
async execute(manifest_id) {
console.log(`Executing ${manifest_id}...`)
sendToRenderer("installation:status", {
status: "starting",
id: manifest_id,
statusText: `Executing ${manifest_id}...`,
})
const db = await this.readDb()
let manifest = db.installations.find((i) => i.id === manifest_id)
if (!manifest) {
sendToRenderer("runtime:error", "Manifest not found")
return false
}
const packPath = path.resolve(INSTALLERS_PATH, manifest.id)
if (manifest.remote_url) {
manifest = await readManifest(manifest.remote_url, { just_read: true })
}
if (typeof manifest.init === "function") {
const init_result = await manifest.init({
pack_dir: packPath,
tmp_dir: TMP_PATH
})
manifest = {
...manifest,
...init_result,
}
delete manifest.init
}
if (typeof manifest.execute !== "function") {
sendToRenderer("installation:status", {
status: "execution_failed",
...manifest,
})
return false
}
await manifest.execute({
manifest,
pack_dir: packPath,
tmp_dir: TMP_PATH
})
sendToRenderer("installation:status", {
status: "installed",
...manifest,
})
console.log(`Successfully executed ${manifest_id}!`)
return true
}
} }

View File

@ -6,8 +6,6 @@ import { pipeline as streamPipeline } from "node:stream/promises"
import unzipper from "unzipper" import unzipper from "unzipper"
import { extractFull } from "node-7z"
import got from "got" import got from "got"
function resolveDestBin(pre, post) { function resolveDestBin(pre, post) {

View File

@ -92,6 +92,14 @@ const InstallationItem = (props) => {
</div> </div>
<div className="installation_item_actions"> <div className="installation_item_actions">
{
isInstalled && manifest.executable && <antd.Button
type="primary"
icon={<MdPlayArrow />}
onClick={onClickPlay}
/>
}
{ {
isFailed && <antd.Button isFailed && <antd.Button
type="primary" type="primary"
@ -108,14 +116,6 @@ const InstallationItem = (props) => {
/> />
} }
{
isInstalled && manifest.exec_path && <antd.Button
type="primary"
icon={<MdPlayArrow />}
onClick={onClickPlay}
/>
}
{ {
isInstalled && <antd.Button isInstalled && <antd.Button
type="primary" type="primary"