Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to the HTTP-based Progress API #1103

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
imobachgs marked this conversation as resolved.
Show resolved Hide resolved
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
Loading