From b93cc28372d02e39f723e59eda5199e0c1660f9c Mon Sep 17 00:00:00 2001 From: yolossn Date: Thu, 4 Jul 2024 13:19:38 +0530 Subject: [PATCH 1/3] headlamp-plugin: Add extra meta to plugin install and list this patcha adds extra meta to plugin install and list author and repoName in list response Signed-off-by: yolossn --- plugins/headlamp-plugin/bin/headlamp-plugin.js | 8 +++----- plugins/headlamp-plugin/plugin-management-utils.js | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/headlamp-plugin/bin/headlamp-plugin.js b/plugins/headlamp-plugin/bin/headlamp-plugin.js index bec7666029..1c0dc0fa13 100755 --- a/plugins/headlamp-plugin/bin/headlamp-plugin.js +++ b/plugins/headlamp-plugin/bin/headlamp-plugin.js @@ -1312,16 +1312,14 @@ yargs(process.argv.slice(2)) console.log(JSON.stringify(data.data)); } else { // display table - const rows = [ - ['Name', 'Version', 'Folder Name', 'ArticaftHub URL', 'ArtifactHub Version'], - ]; + const rows = [['Name', 'Version', 'Folder Name', 'Repo', 'Author']]; data.data.forEach(plugin => { rows.push([ plugin.pluginName, plugin.pluginVersion, plugin.folderName, - plugin.artifacthubURL, - plugin.artifacthubVersion, + plugin.repoName, + plugin.author, ]); }); console.log(table(rows)); diff --git a/plugins/headlamp-plugin/plugin-management-utils.js b/plugins/headlamp-plugin/plugin-management-utils.js index 40ca485fbd..074aec2b22 100644 --- a/plugins/headlamp-plugin/plugin-management-utils.js +++ b/plugins/headlamp-plugin/plugin-management-utils.js @@ -204,6 +204,7 @@ class PluginManager { const pluginVersion = packageJson.version || null; const artifacthubURL = packageJson.artifacthub ? packageJson.artifacthub.url : null; const repoName = packageJson.artifacthub ? packageJson.artifacthub.repoName : null; + const author = packageJson.artifacthub ? packageJson.artifacthub.author : null; const artifacthubVersion = packageJson.artifacthub ? packageJson.artifacthub.version : null; @@ -215,6 +216,7 @@ class PluginManager { folderName: pluginFolder.name, artifacthubURL: artifacthubURL, repoName: repoName, + author: author, artifacthubVersion: artifacthubVersion, }); } @@ -371,6 +373,7 @@ async function downloadExtractPlugin(URL, headlampVersion, progressCallback, sig url: `https://artifacthub.io/packages/headlamp/${pluginInfo.repository.name}/${pluginName}`, version: pluginInfo.version, repoName: pluginInfo.repository.name, + author: pluginInfo.repository.user_alias, }; packageJSON.isManagedByHeadlampPlugin = true; fs.writeFileSync(`${tempFolder}/package.json`, JSON.stringify(packageJSON, null, 2)); From 8733edfa0a0ab89e5889f4e6b8232962750625cd Mon Sep 17 00:00:00 2001 From: yolossn Date: Mon, 8 Jul 2024 23:48:53 +0530 Subject: [PATCH 2/3] app: Add user confirmation to plugin install handler this patch adds a user confirmation dialog to the plugin install handler Signed-off-by: yolossn --- app/electron/main.ts | 86 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 19 deletions(-) diff --git a/app/electron/main.ts b/app/electron/main.ts index 3fb18e1278..8b5f418e7b 100644 --- a/app/electron/main.ts +++ b/app/electron/main.ts @@ -2,7 +2,17 @@ import 'regenerator-runtime/runtime'; import { ChildProcessWithoutNullStreams, execSync, spawn } from 'child_process'; import { randomBytes } from 'crypto'; import dotenv from 'dotenv'; -import { app, BrowserWindow, dialog, ipcMain, Menu, MenuItem, screen, shell } from 'electron'; +import { + app, + BrowserWindow, + dialog, + ipcMain, + Menu, + MenuItem, + MessageBoxOptions, + screen, + shell, +} from 'electron'; import { IpcMainEvent, MenuItemConstructorOptions } from 'electron/main'; import log from 'electron-log'; import find_process from 'find-process'; @@ -223,34 +233,72 @@ class PluginManagerEventListeners { * @private */ private handleInstall(eventData: Action, updateCache: (progress: ProgressResp) => void) { - const { identifier, URL, destinationFolder, headlampVersion } = eventData; + const { identifier, URL, destinationFolder, headlampVersion, pluginName } = eventData; + + if (!mainWindow) { + return Promise.resolve({ type: 'error', message: 'Main window is not available' }); + } + if (!URL) { - this.cache[identifier] = { - action: 'INSTALL', - progress: { type: 'error', message: 'URL is required' }, - }; - return; + return Promise.resolve({ type: 'error', message: 'URL is required' }); } + const dialogOptions: MessageBoxOptions = { + type: 'question', + buttons: ['Yes', 'No'], + defaultId: 1, + title: 'Plugin Installation', + message: 'Do you want to install this plugin?', + detail: `You are about to install ${pluginName} plugin from: ${URL}\nDo you want to proceed?`, + }; const controller = new AbortController(); this.cache[identifier] = { action: 'INSTALL', - progress: { type: 'info', message: 'installing plugin' }, - percentage: 10, + progress: { type: 'info', message: 'waiting for user consent' }, + percentage: 0, controller, }; - PluginManager.install( - URL, - destinationFolder, - headlampVersion, - progress => { - updateCache(progress); - }, - controller.signal - ); - } + return dialog + .showMessageBox(mainWindow, dialogOptions) + .then(({ response }) => { + console.log('User response:', response); + if (response === 1) { + // User clicked "No" + this.cache[identifier] = { + action: 'INSTALL', + progress: { type: 'error', message: 'installation cancelled due to user consent' }, + percentage: 0, + controller, + }; + return { type: 'error', message: 'Installation cancelled due to user consent' }; + } + // User clicked "Yes", proceed with installation + this.cache[identifier] = { + action: 'INSTALL', + progress: { type: 'info', message: 'installing plugin' }, + percentage: 10, + controller, + }; + + PluginManager.install( + URL, + destinationFolder, + headlampVersion, + progress => { + updateCache(progress); + }, + controller.signal + ); + + return { type: 'info', message: 'Installation started' }; + }) + .catch(error => { + console.error('Error during installation process:', error); + return { type: 'error', message: 'An error occurred during the installation process' }; + }); + } /** * Handles the update process. * From 2543c95a9b5844a4f5c89130d366f80e2e7d0bac Mon Sep 17 00:00:00 2001 From: yolossn Date: Mon, 8 Jul 2024 23:50:44 +0530 Subject: [PATCH 3/3] headlamp-plugin: Add pluginName to install function this patch adds pluginName to the plugin managers install function Signed-off-by: yolossn --- frontend/src/components/App/pluginManager.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/App/pluginManager.ts b/frontend/src/components/App/pluginManager.ts index b11caf3cd6..c1fe69a61a 100644 --- a/frontend/src/components/App/pluginManager.ts +++ b/frontend/src/components/App/pluginManager.ts @@ -60,18 +60,20 @@ export class PluginManager { * Sends a request to install a plugin from the specified ArtifactHub URL. * * @param {string} identifier - The unique identifier for the plugin. + * @param {string} name - The name of the plugin to be installed. * @param {string} URL - The URL from where the plugin will be installed. * @static * @example * PluginManager.install('pluginID', ' https://artifacthub.io/packages/headlamp//'); */ - static install(identifier: string, URL: string) { + static install(identifier: string, name: string, URL: string) { window.desktopApi.send( 'plugin-manager', JSON.stringify({ action: 'INSTALL', identifier, URL, + pluginName: name, }) ); }