From 89aa784326ab7794a7578f74ddaf27b73b6481e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Sat, 16 Mar 2024 14:45:17 +0000 Subject: [PATCH 1/2] Fix WithStatus documentation --- web/src/client/mixins.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/client/mixins.js b/web/src/client/mixins.js index a5f42a6937..9c351af47a 100644 --- a/web/src/client/mixins.js +++ b/web/src/client/mixins.js @@ -143,12 +143,12 @@ const WithIssues = (superclass, object_path) => class extends superclass { }; /** - * Extends the given class with methods to get and track the progress over D-Bus + * Extends the given class with methods to get and track the service status * * @template {!WithHTTPClient} T + * @param {T} superclass - superclass to extend * @param {string} status_path - status resource path (e.g., "/manager/status"). * @param {string} service_name - service name (e.g., "org.opensuse.Agama.Manager1"). - * @param {T} superclass - superclass to extend */ const WithStatus = (superclass, status_path, service_name) => class extends superclass { From 1eada083367b94a9d012741a9cc69355983b4095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Sat, 16 Mar 2024 14:47:07 +0000 Subject: [PATCH 2/2] Adapt WithProress to the HTTP/JSON API --- web/src/client/manager.js | 3 ++- web/src/client/mixins.js | 37 ++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/web/src/client/manager.js b/web/src/client/manager.js index f3915b4d8b..7276eae326 100644 --- a/web/src/client/manager.js +++ b/web/src/client/manager.js @@ -131,7 +131,8 @@ class ManagerBaseClient { */ class ManagerClient extends WithProgress( WithStatus(ManagerBaseClient, "/manager/status", MANAGER_SERVICE), - MANAGER_PATH, + "/manager/progress", + MANAGER_SERVICE, ) {} export { ManagerClient }; diff --git a/web/src/client/mixins.js b/web/src/client/mixins.js index 9c351af47a..9523cdd40e 100644 --- a/web/src/client/mixins.js +++ b/web/src/client/mixins.js @@ -192,12 +192,14 @@ const WithStatus = (superclass, status_path, service_name) => */ /** - * Extends the given class with methods to get and track the progress over D-Bus - * @param {string} object_path - object_path + * Extends the given class with methods to get and track the service progress + * + * @template {!WithHTTPClient} T * @param {T} superclass - superclass to extend - * @template {!WithDBusClient} T + * @param {string} progress_path - status resource path (e.g., "/manager/status"). + * @param {string} service_name - service name (e.g., "org.opensuse.Agama.Manager1"). */ -const WithProgress = (superclass, object_path) => +const WithProgress = (superclass, progress_path, service_name) => class extends superclass { /** * Returns the service progress @@ -206,12 +208,14 @@ const WithProgress = (superclass, object_path) => * the current step and whether the service finished or not. */ async getProgress() { - const proxy = await this.client.proxy(PROGRESS_IFACE, object_path); + const { current_step, max_steps, current_title, finished } = await this.client.get( + progress_path, + ); return { - total: proxy.TotalSteps, - current: proxy.CurrentStep[0], - message: proxy.CurrentStep[1], - finished: proxy.Finished, + total: max_steps, + current: current_step, + message: current_title, + finished, }; } @@ -222,13 +226,16 @@ const WithProgress = (superclass, object_path) => * @return {import ("./dbus").RemoveFn} function to disable the callback */ onProgressChange(handler) { - return this.client.onObjectChanged(object_path, PROGRESS_IFACE, (changes) => { - const { TotalSteps, CurrentStep, Finished } = changes; - if (TotalSteps === undefined && CurrentStep === undefined && Finished === undefined) { - return; + return this.client.onEvent("Progress", (progress) => { + if (progress?.service === service_name) { + const { current_step, max_steps, current_title, finished } = progress; + handler({ + total: max_steps, + current: current_step, + message: current_title, + finished, + }); } - - this.getProgress().then(handler); }); } };