mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
improve pkg manager
This commit is contained in:
parent
51e63bc7e5
commit
9f309feea4
@ -12,6 +12,7 @@ import pkg from "../../package.json"
|
|||||||
import setup from "./setup"
|
import setup from "./setup"
|
||||||
|
|
||||||
import PkgManager from "./pkgManager"
|
import PkgManager from "./pkgManager"
|
||||||
|
import { readManifest } from "./pkgManager"
|
||||||
|
|
||||||
class ElectronApp {
|
class ElectronApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -26,6 +27,9 @@ class ElectronApp {
|
|||||||
"get:installations": async () => {
|
"get:installations": async () => {
|
||||||
return await this.pkgManager.getInstallations()
|
return await this.pkgManager.getInstallations()
|
||||||
},
|
},
|
||||||
|
"bundle:read": async (event, manifest_url) => {
|
||||||
|
return JSON.stringify(await readManifest(manifest_url))
|
||||||
|
},
|
||||||
"bundle:update": (event, manifest_id) => {
|
"bundle:update": (event, manifest_id) => {
|
||||||
this.pkgManager.update(manifest_id)
|
this.pkgManager.update(manifest_id)
|
||||||
},
|
},
|
||||||
@ -98,6 +102,27 @@ class ElectronApp {
|
|||||||
|
|
||||||
await app.whenReady()
|
await app.whenReady()
|
||||||
|
|
||||||
|
// Set app user model id for windows
|
||||||
|
electronApp.setAppUserModelId("com.electron")
|
||||||
|
|
||||||
|
app.on("browser-window-created", (_, window) => {
|
||||||
|
optimizer.watchWindowShortcuts(window)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.createWindow()
|
||||||
|
|
||||||
|
app.on("activate", () => {
|
||||||
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
|
this.createWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.on("window-all-closed", () => {
|
||||||
|
if (process.platform !== "darwin") {
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
autoUpdater.on("update-available", (ev, info) => {
|
autoUpdater.on("update-available", (ev, info) => {
|
||||||
console.log(info)
|
console.log(info)
|
||||||
|
|
||||||
@ -132,27 +157,6 @@ class ElectronApp {
|
|||||||
})
|
})
|
||||||
|
|
||||||
autoUpdater.checkForUpdates()
|
autoUpdater.checkForUpdates()
|
||||||
|
|
||||||
// Set app user model id for windows
|
|
||||||
electronApp.setAppUserModelId("com.electron")
|
|
||||||
|
|
||||||
app.on("browser-window-created", (_, window) => {
|
|
||||||
optimizer.watchWindowShortcuts(window)
|
|
||||||
})
|
|
||||||
|
|
||||||
this.createWindow()
|
|
||||||
|
|
||||||
app.on("activate", () => {
|
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
|
||||||
this.createWindow()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
|
||||||
if (process.platform !== "darwin") {
|
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ function sendToRenderer(event, data) {
|
|||||||
global.win.webContents.send(event, serializeIpc(data))
|
global.win.webContents.send(event, serializeIpc(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAndCreateModule(manifest) {
|
export async function fetchAndCreateModule(manifest) {
|
||||||
console.log(`Fetching ${manifest}...`)
|
console.log(`Fetching ${manifest}...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -63,7 +63,7 @@ async function fetchAndCreateModule(manifest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readManifest(manifest, { just_read = false } = {}) {
|
export async function readManifest(manifest, { just_read = false } = {}) {
|
||||||
// check if manifest is a directory or a url
|
// check if manifest is a directory or a url
|
||||||
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi
|
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi
|
||||||
|
|
||||||
@ -177,25 +177,16 @@ export default class PkgManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async install(manifest) {
|
async initManifest(manifest = {}) {
|
||||||
let pendingTasks = []
|
|
||||||
|
|
||||||
manifest = await readManifest(manifest).catch((error) => {
|
|
||||||
sendToRenderer("runtime:error", "Cannot fetch this manifest")
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!manifest) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const packPath = path.resolve(INSTALLERS_PATH, manifest.id)
|
const packPath = path.resolve(INSTALLERS_PATH, manifest.id)
|
||||||
|
|
||||||
|
const osString = `${os.platform()}-${os.arch()}`
|
||||||
|
|
||||||
if (typeof manifest.init === "function") {
|
if (typeof manifest.init === "function") {
|
||||||
const init_result = await manifest.init({
|
const init_result = await manifest.init({
|
||||||
pack_dir: packPath,
|
pack_dir: packPath,
|
||||||
tmp_dir: TMP_PATH
|
tmp_dir: TMP_PATH,
|
||||||
|
os_string: osString,
|
||||||
})
|
})
|
||||||
|
|
||||||
manifest = {
|
manifest = {
|
||||||
@ -206,18 +197,44 @@ export default class PkgManager {
|
|||||||
delete manifest.init
|
delete manifest.init
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest.status = "installing"
|
return manifest
|
||||||
|
}
|
||||||
console.log(`Starting to install ${manifest.pack_name}...`)
|
|
||||||
console.log(`Installing at >`, packPath)
|
|
||||||
|
|
||||||
sendToRenderer("new:installation", manifest)
|
|
||||||
|
|
||||||
fs.mkdirSync(packPath, { recursive: true })
|
|
||||||
|
|
||||||
await this.appendInstallation(manifest)
|
|
||||||
|
|
||||||
|
async install(manifest) {
|
||||||
try {
|
try {
|
||||||
|
let pendingTasks = []
|
||||||
|
|
||||||
|
manifest = await readManifest(manifest).catch((error) => {
|
||||||
|
sendToRenderer("runtime:error", "Cannot fetch this manifest")
|
||||||
|
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!manifest) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest = await this.initManifest(manifest)
|
||||||
|
|
||||||
|
manifest.status = "installing"
|
||||||
|
|
||||||
|
console.log(`Starting to install ${manifest.pack_name}...`)
|
||||||
|
console.log(`Installing at >`, packPath)
|
||||||
|
|
||||||
|
sendToRenderer("new:installation", manifest)
|
||||||
|
|
||||||
|
fs.mkdirSync(packPath, { recursive: true })
|
||||||
|
|
||||||
|
await this.appendInstallation(manifest)
|
||||||
|
|
||||||
|
if (typeof manifest.on_install === "function") {
|
||||||
|
await manifest.on_install({
|
||||||
|
manifest: manifest,
|
||||||
|
pack_dir: packPath,
|
||||||
|
tmp_dir: TMP_PATH,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof manifest.git_clones_steps !== "undefined" && Array.isArray(manifest.git_clones_steps)) {
|
if (typeof manifest.git_clones_steps !== "undefined" && Array.isArray(manifest.git_clones_steps)) {
|
||||||
for await (const step of manifest.git_clones_steps) {
|
for await (const step of manifest.git_clones_steps) {
|
||||||
const _path = path.resolve(packPath, step.path)
|
const _path = path.resolve(packPath, step.path)
|
||||||
@ -430,19 +447,7 @@ export default class PkgManager {
|
|||||||
|
|
||||||
manifest.status = "updating"
|
manifest.status = "updating"
|
||||||
|
|
||||||
if (typeof manifest.init === "function") {
|
manifest = await this.initManifest(manifest)
|
||||||
const init_result = await manifest.init({
|
|
||||||
pack_dir: packPath,
|
|
||||||
tmp_dir: TMP_PATH
|
|
||||||
})
|
|
||||||
|
|
||||||
manifest = {
|
|
||||||
...manifest,
|
|
||||||
...init_result,
|
|
||||||
}
|
|
||||||
|
|
||||||
delete manifest.init
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof manifest.update === "function") {
|
if (typeof manifest.update === "function") {
|
||||||
sendToRenderer(`installation:status`, {
|
sendToRenderer(`installation:status`, {
|
||||||
@ -614,24 +619,12 @@ export default class PkgManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const packPath = path.resolve(INSTALLERS_PATH, manifest.id)
|
const packPath = path.resolve(INSTALLERS_PATH, manifest.id)
|
||||||
|
|
||||||
if (manifest.remote_url) {
|
if (manifest.remote_url) {
|
||||||
manifest = await readManifest(manifest.remote_url, { just_read: true })
|
manifest = await readManifest(manifest.remote_url, { just_read: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof manifest.init === "function") {
|
manifest = await this.initManifest(manifest)
|
||||||
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") {
|
if (typeof manifest.execute !== "function") {
|
||||||
sendToRenderer("installation:status", {
|
sendToRenderer("installation:status", {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user