From c133ce9b6b5c6b2f2be2ee5687e361024bb4e101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Thu, 28 Mar 2024 15:10:58 +0100 Subject: [PATCH 1/4] Add versioning capability to package manager, custom github repository addition --- src/electron/main.ts | 21 +- src/electron/package/packageManager.ts | 240 +++++++++++++----- src/renderer/App.svelte | 42 ++- .../main/panels/packages/Packages.svelte | 107 +++++++- src/renderer/runtime/app-helper.store.js | 2 +- 5 files changed, 324 insertions(+), 88 deletions(-) diff --git a/src/electron/main.ts b/src/electron/main.ts index 123977282..0661b5179 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -330,7 +330,9 @@ function createWindow() { }); } -function startPackageManager() { +function startPackageManager( + updatePackageOnStartName: string | undefined = undefined +) { const { port1, port2 } = new MessageChannelMain(); mainWindow.webContents.postMessage("package-manager-port", null, [port1]); @@ -346,15 +348,30 @@ function startPackageManager() { type: "init", packageFolder: packageFolder, version: configuration.EDITOR_VERSION, + githubPackages: store.get("githubPackages"), + updatePackageOnStartName, }, [port2] ); + packageManagerProcess.on("message", (message) => { - if (message.type == "shutdown-complete") { + if (message.type === "shutdown-complete") { packageManagerProcess?.kill(); packageManagerProcess = undefined; startPackageManager(); } + if ( + message.type === "delete-package-folder" || + message.type === "update-package-folder" + ) { + packageManagerProcess?.once("exit", () => { + fs.rm(message.path, { recursive: true }, () => + startPackageManager(message.packageName) + ); + }); + packageManagerProcess!.kill(); + packageManagerProcess = undefined; + } }); } else { packageManagerProcess.postMessage( diff --git a/src/electron/package/packageManager.ts b/src/electron/package/packageManager.ts index 491701891..34a912453 100644 --- a/src/electron/package/packageManager.ts +++ b/src/electron/package/packageManager.ts @@ -1,5 +1,5 @@ import path from "path"; -import fs from "fs"; +import fs, { readFile } from "fs"; import { MessagePortMain } from "electron/main"; import AdmZip from "adm-zip"; import os from "os"; @@ -8,18 +8,46 @@ import fetch from "node-fetch"; import semver from "semver"; import chokidar from "chokidar"; +interface GithubPackage { + name: string; + gitHubRepositoryOwner: string; + gitHubRepositoryName: string; + version?: string; +} + enum PackageStatus { Uninstalled = "Uninstalled", Downloading = "Downloading", Downloaded = "Downloaded", Enabled = "Enabled", - MarkedForDeletion = "MarkedForDeletion", } let packageFolder: string = ""; let editorVersion: string = ""; -process.parentPort.on("message", (e) => { +/*const recommendedPackages = { + "package-active-win": { + name: "Active Window", + description: "Short description of Active Window package", + gitHubRepositoryOwner: "intechstudio", + gitHubRepositoryName: "package-active-win", + }, +};*/ + +const recommendedGithubPackageList: Map = new Map([ + [ + "package-active-win", + { + name: "Active Window", + gitHubRepositoryOwner: "intechstudio", + gitHubRepositoryName: "package-active-win", + }, + ], +]); + +let customGithubPackageList: Map = new Map(); + +process.parentPort.on("message", async (e) => { switch (e.data.type) { case "init": { console.log(`Initialize Package Manager...`); @@ -29,8 +57,14 @@ process.parentPort.on("message", (e) => { if (!fs.existsSync(packageFolder)) { fs.mkdirSync(packageFolder, { recursive: true }); } - startPackageDirectoryWatcher(packageFolder); + customGithubPackageList = new Map(Object.entries(e.data.githubPackages)); + + startPackageDirectoryWatcher(packageFolder); + updateGithubPackages(); + if (e.data.updatePackageOnStartName) { + await downloadPackage(e.data.updatePackageOnStartName); + } const port = e.ports[0]; setPackageManagerMessagePort(port); break; @@ -41,11 +75,12 @@ process.parentPort.on("message", (e) => { break; } case "refresh-packages": { - notifyListener(); + updateGithubPackages(); break; } case "stop-package-manager": { - stopPackageManager(); + await stopPackageManager(); + process.parentPort.postMessage({ type: "shutdown-complete" }); break; } default: { @@ -54,21 +89,11 @@ process.parentPort.on("message", (e) => { } }); -const availablePackages = { - "package-active-win": { - name: "Active Window", - description: "Short description of Active Window package", - gitHubRepositoryOwner: "intechstudio", - gitHubRepositoryName: "package-active-win", - }, -}; - const currentlyLoadedPackages = {}; const haveBeenLoadedPackages = new Set(); -const markedForDeletionPackages = new Set(); const downloadingPackages = new Set(); -let messagePort: MessagePortMain; +let messagePort: MessagePortMain | undefined = undefined; function setPackageManagerMessagePort(port: MessagePortMain) { messagePort = port; @@ -85,19 +110,39 @@ function setPackageManagerMessagePort(port: MessagePortMain) { case "download-package": await downloadPackage(data.id); break; + case "update-package": + await updatePackage(data.id); + break; case "uninstall-package": await uninstallPackage(data.id); break; case "refresh-package-list": await notifyListener(); break; + case "add-github-repository": + customGithubPackageList.set(data.id, { + name: data.packageName, + gitHubRepositoryOwner: data.gitHubRepositoryOwner, + gitHubRepositoryName: data.gitHubRepositoryName, + }); + await updateGithubPackages(); + if (customGithubPackageList.has(data.id)) { + messagePort?.postMessage({ + type: "persist-github-package", + id: data.id, + packageName: data.packageName, + gitHubRepositoryOwner: data.gitHubRepositoryOwner, + gitHubRepositoryName: data.gitHubRepositoryName, + }); + } + break; case "send-to-package": //... send data.message through to each plugin for dedicated processing - // add teh following to a codeblock: package_send("package_name", 123.3, 22, "hello") + // add the following to a codeblock: package_send("package_name", 123.3, 22, "hello") let args = JSON.parse(`[${data.message}]`); let packageId = args.shift(); if (!currentlyLoadedPackages[packageId]) { - messagePort.postMessage({ + messagePort?.postMessage({ type: "debug-error", message: "Package not loaded " + @@ -115,7 +160,7 @@ function setPackageManagerMessagePort(port: MessagePortMain) { break; } } catch (e) { - messagePort.postMessage({ type: "debug-error", message: e.message }); + messagePort?.postMessage({ type: "debug-error", message: e.message }); } }); port.start(); @@ -130,7 +175,6 @@ async function stopPackageManager() { if (messagePort) { messagePort.close(); } - process.parentPort.postMessage({ type: "shutdown-complete" }); } async function loadPackage(packageName: string, persistedData: any) { @@ -144,7 +188,7 @@ async function loadPackage(packageName: string, persistedData: any) { await _package.loadPackage( { sendMessageToRuntime: (payload) => { - messagePort.postMessage({ + messagePort?.postMessage({ type: "package-action", packageId: packageName, ...payload, @@ -157,7 +201,7 @@ async function loadPackage(packageName: string, persistedData: any) { haveBeenLoadedPackages.add(packageName); notifyListener(); } catch (e) { - messagePort.postMessage({ + messagePort?.postMessage({ type: "package-error", error: e.message, }); @@ -173,41 +217,12 @@ async function unloadPackage(packageName: string) { } async function downloadPackage(packageName: string) { - if (markedForDeletionPackages.has(packageName)) { - markedForDeletionPackages.delete(packageName); - notifyListener(); - return; - } - if (downloadingPackages.has(packageName)) return; downloadingPackages.add(packageName); notifyListener(); - const gitHubRepositoryName = - availablePackages[packageName].gitHubRepositoryName; - const gitHubRepositoryOwner = - availablePackages[packageName].gitHubRepositoryOwner; - try { - const packageReleasesResponse = await fetch( - `https://api.github.com/repos/${gitHubRepositoryOwner}/${gitHubRepositoryName}/releases`, - { - method: "GET", - headers: { - "User-Agent": "Grid Editor", - }, - } - ); - const packageReleases = await packageReleasesResponse.json(); - const compatibleRelease = packageReleases.find((e) => { - const description = e.body; - const lastLine = description.split("\n").pop() ?? ""; - if (semver.valid(lastLine)) { - return !semver.gt(lastLine, editorVersion); - } else { - return true; - } - }); + const compatibleRelease = await getCompatibleGithubRelease(packageName); if (!compatibleRelease) return; const assets = compatibleRelease.assets; @@ -254,30 +269,61 @@ async function downloadPackage(packageName: string) { zip.extractAllTo(path.join(packageFolder, packageName), true, true); fs.unlinkSync(filePath); } catch (e) { - messagePort.postMessage({ type: "debug-error", message: e.message }); + customGithubPackageList.delete(packageName); + messagePort?.postMessage({ type: "debug-error", message: e.message }); } finally { downloadingPackages.delete(packageName); notifyListener(); } } +async function updatePackage(packageName: string) { + if (currentlyLoadedPackages[packageName]) { + currentlyLoadedPackages[packageName].unloadPackage(); + delete currentlyLoadedPackages[packageName]; + } + const packagePath = path.join(packageFolder, packageName); + if (haveBeenLoadedPackages.has(packageName)) { + await stopPackageManager(); + process.parentPort.postMessage({ + type: "update-package-folder", + path: packagePath, + packageName: packageName, + }); + } else { + fs.rm(packagePath, { recursive: true }, () => { + downloadPackage(packageName); + }); + } +} + async function uninstallPackage(packageName: string) { if (currentlyLoadedPackages[packageName]) { currentlyLoadedPackages[packageName].unloadPackage(); delete currentlyLoadedPackages[packageName]; } + if (customGithubPackageList.has(packageName)) { + customGithubPackageList.delete(packageName); + messagePort?.postMessage({ + type: "remove-github-package", + id: packageName, + }); + } + const packagePath = path.join(packageFolder, packageName); if (haveBeenLoadedPackages.has(packageName)) { - markedForDeletionPackages.add(packageName); - notifyListener(); + await stopPackageManager(); + process.parentPort.postMessage({ + type: "delete-package-folder", + path: packagePath, + }); } else { - const packagePath = path.join(packageFolder, packageName); fs.rm(packagePath, { recursive: true }, notifyListener); } } async function notifyListener() { const packages = await getAvailablePackages(); - messagePort.postMessage({ type: "packages", packages: packages }); + messagePort?.postMessage({ type: "packages", packages: packages }); } async function getInstalledPackages(): Promise< @@ -285,12 +331,14 @@ async function getInstalledPackages(): Promise< packageId: string; packageName: string; packagePreferenceHtml?: string; + packageVersion?: string; }[] > { if (!fs.existsSync(packageFolder)) { return []; } const readdir = util.promisify(fs.readdir); + const readfile = util.promisify(fs.readFile); const folders = await readdir(packageFolder, { withFileTypes: true }); return Promise.all( folders @@ -305,11 +353,14 @@ async function getInstalledPackages(): Promise< let packageName: string | undefined = undefined; let packagePreferenceHtml: string | undefined = undefined; + let packageVersion: string | undefined = undefined; if (fs.statSync(packagePath).isDirectory()) { const packageJsonPath = path.join(packagePath, "package.json"); if (fs.existsSync(packageJsonPath)) { - const packageJson = require(packageJsonPath); + const packageFile = await readfile(packageJsonPath); + const packageJson = JSON.parse(packageFile.toString()); packageName = packageJson.description; + packageVersion = packageJson.version; const preferenceRelativePath = packageJson.grid_editor?.preference; if (preferenceRelativePath) { const preferencePath = path.join( @@ -318,7 +369,6 @@ async function getInstalledPackages(): Promise< ); const readFile = util.promisify(fs.readFile); packagePreferenceHtml = await readFile(preferencePath, "utf-8"); - //packagePreferenceHtml = result.js.code; } } } @@ -327,6 +377,7 @@ async function getInstalledPackages(): Promise< packageId: packageId, packageName: packageName, packagePreferenceHtml: packagePreferenceHtml, + packageVersion: packageVersion, }; }) ); @@ -338,8 +389,6 @@ function getPackageStatus( ): PackageStatus { if (Object.keys(currentlyLoadedPackages).includes(packageId)) { return PackageStatus.Enabled; - } else if (markedForDeletionPackages.has(packageId)) { - return PackageStatus.MarkedForDeletion; } else if ( installedPackages.filter((e) => e.packageId === packageId).length > 0 ) { @@ -359,7 +408,13 @@ async function getAvailablePackages() { name: string; status: PackageStatus; preferenceHtml?: string; + packageVersion?: string; + canUpdate: boolean; }[] = []; + let githubPackageList = new Map([ + ...recommendedGithubPackageList.entries(), + ...customGithubPackageList.entries(), + ]); for (const _package of installedPackages) { if (packageList.filter((e) => e.id === _package.packageId).length > 0) continue; @@ -369,20 +424,79 @@ async function getAvailablePackages() { name: _package.packageName, status: getPackageStatus(_package.packageId, installedPackages), preferenceHtml: _package.packagePreferenceHtml, + packageVersion: _package.packageVersion, + canUpdate: + _package.packageVersion != undefined && + githubPackageList.get(_package.packageId)?.version != undefined && + semver.gt( + githubPackageList.get(_package.packageId)!.version!, + _package.packageVersion + ), }); } - Object.entries(availablePackages).forEach(([key, entry]) => { + githubPackageList.forEach((entry, key) => { if (packageList.filter((e) => e.id === key).length > 0) return; packageList.push({ id: key, name: entry.name, status: getPackageStatus(key, installedPackages), + canUpdate: false, }); }); return packageList; } +async function updateGithubPackages(forceRefreshVersion: boolean = false) { + let githubPackageList = new Map([ + ...recommendedGithubPackageList.entries(), + ...customGithubPackageList.entries(), + ]); + for (const [packageId, githubPackage] of githubPackageList) { + if (!forceRefreshVersion && githubPackage.version != undefined) continue; + + const compatiblePackage = await getCompatibleGithubRelease(packageId); + if (!compatiblePackage) { + customGithubPackageList.delete(packageId); + continue; + } + + let version = + semver.coerce(compatiblePackage.tag_name) ?? + semver.coerce(compatiblePackage.name); + githubPackage.version = version?.version; + } + notifyListener(); +} + +async function getCompatibleGithubRelease(githubPackageName: string) { + let githubPackageList = new Map([ + ...recommendedGithubPackageList.entries(), + ...customGithubPackageList.entries(), + ]); + let githubPackage = githubPackageList.get(githubPackageName); + if (!githubPackage) return; + const packageReleasesResponse = await fetch( + `https://api.github.com/repos/${githubPackage.gitHubRepositoryOwner}/${githubPackage.gitHubRepositoryName}/releases`, + { + method: "GET", + headers: { + "User-Agent": "Grid Editor", + }, + } + ); + const packageReleases = await packageReleasesResponse.json(); + return packageReleases.find((e) => { + const description = e.body; + const lastLine = description.split("\n").pop() ?? ""; + if (semver.coerce(lastLine)) { + return !semver.gt(semver.coerce(lastLine)!, editorVersion); + } else { + return true; + } + }); +} + let directoryWatcher: any = null; function startPackageDirectoryWatcher(path: string): void { diff --git a/src/renderer/App.svelte b/src/renderer/App.svelte index 3f037ff5b..cb46bf5e7 100644 --- a/src/renderer/App.svelte +++ b/src/renderer/App.svelte @@ -101,30 +101,46 @@ s.persistent.packagesDataStorage = newStorage; return s; }); - } - if (data.id == "add-action") { + } else if (data.id == "add-action") { addPackageAction({ ...data.info, packageId: data.packageId, }); - } - if (data.id == "remove-action") { + } else if (data.id == "remove-action") { removePackageAction(data.packageId, data.actionId); } break; } + case "persist-github-package": { + console.log(`PERSIST PACKAGE: ${data.id}`); + appSettings.update((s) => { + let persistent = structuredClone(s.persistent); + persistent.githubPackages[data.id] = { + name: data.packageName, + gitHubRepositoryOwner: data.gitHubRepositoryOwner, + gitHubRepositoryName: data.gitHubRepositoryName, + }; + s.persistent = persistent; + return s; + }); + break; + } + case "remove-github-package": { + appSettings.update((s) => { + let persistent = structuredClone(s.persistent); + delete persistent.githubPackages[data.id]; + s.persistent = persistent; + return s; + }); + break; + } case "packages": { // refresh packagelist - const markedForDeletionPackages = data.packages - .filter((e) => e.status == "MarkedForDeletion") - .map((e) => e.id); const enabledPackages = data.packages .filter((e) => e.status == "Enabled") .map((e) => e.id); appSettings.update((s) => { s.packageList = data.packages; - s.persistent.markedForDeletionPackages = - markedForDeletionPackages; s.persistent.enabledPackages = enabledPackages; return s; }); @@ -141,10 +157,10 @@ } } }; - for (const _package of $appSettings.persistent - .markedForDeletionPackages ?? []) { - port.postMessage({ type: "uninstall-package", id: _package }); - } + port.onclose = () => { + //Clear package list without deleting enabled packages + $appSettings.packageList = []; + }; for (const _package of $appSettings.persistent.enabledPackages ?? []) { port.postMessage({ type: "load-package", diff --git a/src/renderer/main/panels/packages/Packages.svelte b/src/renderer/main/panels/packages/Packages.svelte index e25845971..52765dc46 100644 --- a/src/renderer/main/panels/packages/Packages.svelte +++ b/src/renderer/main/panels/packages/Packages.svelte @@ -3,25 +3,33 @@ import { appSettings } from "../../../runtime/app-helper.store"; import { Analytics } from "../../../runtime/analytics.js"; import MoltenPushButton from "../preferences/MoltenPushButton.svelte"; + import { logger } from "../../../runtime/runtime.store.js"; onMount(async () => { refreshPackageList(); }); - $: $appSettings.persistent.enabledPackages, refreshPackagePreferences(); + $: $appSettings.persistent.enabledPackages, + $appSettings.packageList, + refreshPackagePreferences(); let packageListDiv; let packagePreferenceElements = {}; + let packageRepositoryUrlInput = ""; function refreshPackagePreferences() { const loadedPackages = $appSettings.persistent.enabledPackages; + const packageList = $appSettings.packageList; if (!packageListDiv) { return; } // Remove existing divs not found in the external set of IDs const existingDivIds = Object.keys(packagePreferenceElements); existingDivIds.forEach((existingDivId) => { - if (!loadedPackages.includes(existingDivId)) { + if ( + !loadedPackages.includes(existingDivId) || + !packageList.find((e) => e.id !== existingDivId) + ) { packagePreferenceElements[existingDivId].remove(); delete packagePreferenceElements[existingDivId]; } @@ -44,8 +52,8 @@ } for (const packageId of loadedPackages) { - const _package = $appSettings.packageList.find((e) => e.id == packageId); - if (!_package.preferenceHtml) continue; + const _package = packageList.find((e) => e.id == packageId); + if (!_package || !_package.preferenceHtml) continue; if (existingDivIds.includes(_package.id)) continue; const tempContainer = document.createElement("div"); @@ -117,11 +125,75 @@ }); } - function restartPackageManager() { - if (packageListDiv) { - packageListDiv.innerHTML = ""; + function updatePackage(packageId) { + window.packageManagerPort?.postMessage({ + type: "update-package", + id: packageId, + }); + + Analytics.track({ + event: "Package Manager", + payload: { click: "Update", id: packageId }, + mandatory: false, + }); + } + + async function addPackageRepository() { + const githubLink = packageRepositoryUrlInput; + + const regexPattern = /https?:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?.*/; + const matches = githubLink.match(regexPattern); + + if (matches) { + const owner = matches[1]; + const repositoryName = matches[2]; + + try { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repositoryName}/contents/package.json`, + { + method: "GET", + headers: { + Accept: "application/vnd.github.v3.raw", + "User-Agent": "Grid Editor", + }, + } + ); + + if (response.ok) { + const packageJsonText = await response.text(); + const packageInfo = JSON.parse(packageJsonText); + const packageName = packageInfo.description; + const packageId = packageInfo.name; + window.packageManagerPort?.postMessage({ + type: "add-github-repository", + id: packageId, + packageName, + gitHubRepositoryOwner: owner, + gitHubRepositoryName: repositoryName, + }); + } else { + logger.set({ + type: "fail", + message: `Failed to fetch package.json!`, + }); + } + } catch (error) { + logger.set({ + type: "fail", + message: `Failed to fetch package.json: ${error.message}`, + }); + } + //packageRepositoryUrlInput = ""; + } else { + logger.set({ + type: "fail", + message: "Couldn't detect valid Github repository!", + }); } - packagePreferenceElements = {}; + } + + function restartPackageManager() { window.electron.restartPackageManager(); } @@ -153,13 +225,21 @@ changePackageStatus(_package.id, e.target.checked)} />
{_package.name}
+ {#if _package.packageVersion} +
{_package.packageVersion}
+ {/if}
- {#if _package.status == "Downloading" || _package.status == "Uninstalled" || _package.status == "MarkedForDeletion"} + {#if _package.status == "Downloading" || _package.status == "Uninstalled"} + {:else if _package.canUpdate} + {:else} +
+ + +
+
Date: Thu, 4 Apr 2024 11:53:52 +0200 Subject: [PATCH 2/4] Add package handling in checkSyntax --- src/renderer/main/panels/configuration/Configuration.store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/main/panels/configuration/Configuration.store.js b/src/renderer/main/panels/configuration/Configuration.store.js index 7d0f3bb55..9e9c5edf3 100644 --- a/src/renderer/main/panels/configuration/Configuration.store.js +++ b/src/renderer/main/panels/configuration/Configuration.store.js @@ -100,7 +100,7 @@ export class ConfigObject { //TODO: Rework composite blocks in a way, so this exception //does not occure. let code = this.script; - if (this.short !== "cb") { + if (this.short !== "cb" && !this.short.startsWith("x")) { if (code.startsWith("elseif")) { code = code.replace("elseif", "if"); } From 948daf344e837ee720dd2f05136a1df01ba02196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Thu, 4 Apr 2024 13:29:29 +0200 Subject: [PATCH 3/4] Remove unusable github packages --- src/electron/package/packageManager.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/electron/package/packageManager.ts b/src/electron/package/packageManager.ts index 34a912453..25d31284c 100644 --- a/src/electron/package/packageManager.ts +++ b/src/electron/package/packageManager.ts @@ -270,6 +270,10 @@ async function downloadPackage(packageName: string) { fs.unlinkSync(filePath); } catch (e) { customGithubPackageList.delete(packageName); + messagePort?.postMessage({ + type: "remove-github-package", + id: packageName, + }); messagePort?.postMessage({ type: "debug-error", message: e.message }); } finally { downloadingPackages.delete(packageName); From df414d3cbe3f738b3b592a109036d8011a7007ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1sztor=20D=C3=A1niel?= Date: Wed, 10 Apr 2024 17:42:54 +0200 Subject: [PATCH 4/4] Small fixes, show package manager loading animation --- configuration.json | 9 ++++- src/electron/package/packageManager.ts | 32 ++++++---------- src/renderer/App.svelte | 11 +++++- .../main/panels/packages/Packages.svelte | 37 ++++++++++++++++++- src/renderer/runtime/app-helper.store.js | 1 + 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/configuration.json b/configuration.json index 3c90ec46b..46e43071e 100644 --- a/configuration.json +++ b/configuration.json @@ -41,5 +41,12 @@ "PROFILE_CLOUD_URL_LOCAL": "http://localhost:5200", "PROFILE_CLOUD_URL_DEV": "https://profile-cloud-dev.web.app", "PROFILE_CLOUD_URL_PROD": "https://profile-cloud.web.app", - "PROFILE_CLOUD_EMAIL_REGISTRATION": "https://intech.studio/auth" + "PROFILE_CLOUD_EMAIL_REGISTRATION": "https://intech.studio/auth", + "RECOMMENDED_PACKAGES": { + "package-active-win": { + "name": "Active Window", + "gitHubRepositoryOwner": "intechstudio", + "gitHubRepositoryName": "package-active-win" + } + } } diff --git a/src/electron/package/packageManager.ts b/src/electron/package/packageManager.ts index 25d31284c..e3788bf38 100644 --- a/src/electron/package/packageManager.ts +++ b/src/electron/package/packageManager.ts @@ -7,6 +7,7 @@ import util from "util"; import fetch from "node-fetch"; import semver from "semver"; import chokidar from "chokidar"; +import configuration from "../../../configuration.json"; interface GithubPackage { name: string; @@ -25,25 +26,9 @@ enum PackageStatus { let packageFolder: string = ""; let editorVersion: string = ""; -/*const recommendedPackages = { - "package-active-win": { - name: "Active Window", - description: "Short description of Active Window package", - gitHubRepositoryOwner: "intechstudio", - gitHubRepositoryName: "package-active-win", - }, -};*/ - -const recommendedGithubPackageList: Map = new Map([ - [ - "package-active-win", - { - name: "Active Window", - gitHubRepositoryOwner: "intechstudio", - gitHubRepositoryName: "package-active-win", - }, - ], -]); +const recommendedGithubPackageList: Map = new Map( + Object.entries(configuration.RECOMMENDED_PACKAGES) +); let customGithubPackageList: Map = new Map(); @@ -269,7 +254,14 @@ async function downloadPackage(packageName: string) { zip.extractAllTo(path.join(packageFolder, packageName), true, true); fs.unlinkSync(filePath); } catch (e) { - customGithubPackageList.delete(packageName); + if (customGithubPackageList.has(packageName)) { + customGithubPackageList.delete(packageName); + messagePort?.postMessage({ + type: "show-message", + message: "Couldn't find package archive, removed from list!", + messageType: "fail", + }); + } messagePort?.postMessage({ type: "remove-github-package", id: packageName, diff --git a/src/renderer/App.svelte b/src/renderer/App.svelte index b680d5b5a..cb3094d70 100644 --- a/src/renderer/App.svelte +++ b/src/renderer/App.svelte @@ -30,7 +30,7 @@ import { watchResize } from "svelte-watch-resize"; import { debug_lowlevel_store } from "./main/panels/WebsocketMonitor/WebsocketMonitor.store"; - import { runtime } from "./runtime/runtime.store"; + import { runtime, logger } from "./runtime/runtime.store"; import MiddlePanelContainer from "./main/MiddlePanelContainer.svelte"; import { addPackageAction, removePackageAction } from "./lib/_configs"; @@ -91,6 +91,7 @@ window.packageManagerPort = port; // register message handler port.onmessage = (event) => { + $appSettings.packageManagerRunning = true; const data = event.data; // action towards runtime switch (data.type) { @@ -117,7 +118,6 @@ break; } case "persist-github-package": { - console.log(`PERSIST PACKAGE: ${data.id}`); appSettings.update((s) => { let persistent = structuredClone(s.persistent); persistent.githubPackages[data.id] = { @@ -155,6 +155,12 @@ const env = process.env.NODE_ENV; break; } + case "show-message": { + logger.set({ + message: data.message, + type: data.messageType, + }); + } default: { console.info( `Unhandled message type of ${data.type} received on port ${port}: ${data.message}` @@ -165,6 +171,7 @@ port.onclose = () => { //Clear package list without deleting enabled packages $appSettings.packageList = []; + $appSettings.packageManagerRunning = false; }; for (const _package of $appSettings.persistent.enabledPackages ?? []) { port.postMessage({ diff --git a/src/renderer/main/panels/packages/Packages.svelte b/src/renderer/main/panels/packages/Packages.svelte index 52765dc46..298ad4698 100644 --- a/src/renderer/main/panels/packages/Packages.svelte +++ b/src/renderer/main/panels/packages/Packages.svelte @@ -139,6 +139,12 @@ } async function addPackageRepository() { + Analytics.track({ + event: "Package Manager", + payload: { click: "Add repository", url: packageRepositoryUrlInput }, + mandatory: false, + }); + const githubLink = packageRepositoryUrlInput; const regexPattern = /https?:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?.*/; @@ -251,7 +257,7 @@ {/each}
-
+
+ {#if !$appSettings.packageManagerRunning} +

Restarting package manager

+ {/if} +
+ + diff --git a/src/renderer/runtime/app-helper.store.js b/src/renderer/runtime/app-helper.store.js index b3f0c5a17..b60d20d54 100644 --- a/src/renderer/runtime/app-helper.store.js +++ b/src/renderer/runtime/app-helper.store.js @@ -107,6 +107,7 @@ function createAppSettingsStore(persistent) { owner: { neme: undefined }, }, packageList: [], + packageManagerRunning: false, gridLayoutShift: { x: 0, y: 0 }, persistent: structuredClone(persistent), });