Skip to content

Commit

Permalink
Adapt to the HTTP-based Progress API (#1103)
Browse files Browse the repository at this point in the history
Adapt the `WithProgress` to the HTTP-based implementation of the D-Bus
progress interface (#1092).
  • Loading branch information
imobachgs authored Mar 19, 2024
2 parents 744b680 + 1eada08 commit 3f13f6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
3 changes: 2 additions & 1 deletion web/src/client/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ class ManagerBaseClient {
*/
class ManagerClient extends WithProgress(
WithStatus(ManagerBaseClient, "/manager/status", MANAGER_SERVICE),
MANAGER_PATH,
"/manager/progress",
MANAGER_SERVICE,
) {}

export { ManagerClient };
41 changes: 24 additions & 17 deletions web/src/client/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
};
}

Expand All @@ -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);
});
}
};
Expand Down

0 comments on commit 3f13f6f

Please sign in to comment.