Skip to content

Commit 3f13f6f

Browse files
authored
Adapt to the HTTP-based Progress API (#1103)
Adapt the `WithProgress` to the HTTP-based implementation of the D-Bus progress interface (#1092).
2 parents 744b680 + 1eada08 commit 3f13f6f

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

web/src/client/manager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class ManagerBaseClient {
131131
*/
132132
class ManagerClient extends WithProgress(
133133
WithStatus(ManagerBaseClient, "/manager/status", MANAGER_SERVICE),
134-
MANAGER_PATH,
134+
"/manager/progress",
135+
MANAGER_SERVICE,
135136
) {}
136137

137138
export { ManagerClient };

web/src/client/mixins.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ const WithIssues = (superclass, object_path) => class extends superclass {
143143
};
144144

145145
/**
146-
* Extends the given class with methods to get and track the progress over D-Bus
146+
* Extends the given class with methods to get and track the service status
147147
*
148148
* @template {!WithHTTPClient} T
149+
* @param {T} superclass - superclass to extend
149150
* @param {string} status_path - status resource path (e.g., "/manager/status").
150151
* @param {string} service_name - service name (e.g., "org.opensuse.Agama.Manager1").
151-
* @param {T} superclass - superclass to extend
152152
*/
153153
const WithStatus = (superclass, status_path, service_name) =>
154154
class extends superclass {
@@ -192,12 +192,14 @@ const WithStatus = (superclass, status_path, service_name) =>
192192
*/
193193

194194
/**
195-
* Extends the given class with methods to get and track the progress over D-Bus
196-
* @param {string} object_path - object_path
195+
* Extends the given class with methods to get and track the service progress
196+
*
197+
* @template {!WithHTTPClient} T
197198
* @param {T} superclass - superclass to extend
198-
* @template {!WithDBusClient} T
199+
* @param {string} progress_path - status resource path (e.g., "/manager/status").
200+
* @param {string} service_name - service name (e.g., "org.opensuse.Agama.Manager1").
199201
*/
200-
const WithProgress = (superclass, object_path) =>
202+
const WithProgress = (superclass, progress_path, service_name) =>
201203
class extends superclass {
202204
/**
203205
* Returns the service progress
@@ -206,12 +208,14 @@ const WithProgress = (superclass, object_path) =>
206208
* the current step and whether the service finished or not.
207209
*/
208210
async getProgress() {
209-
const proxy = await this.client.proxy(PROGRESS_IFACE, object_path);
211+
const { current_step, max_steps, current_title, finished } = await this.client.get(
212+
progress_path,
213+
);
210214
return {
211-
total: proxy.TotalSteps,
212-
current: proxy.CurrentStep[0],
213-
message: proxy.CurrentStep[1],
214-
finished: proxy.Finished,
215+
total: max_steps,
216+
current: current_step,
217+
message: current_title,
218+
finished,
215219
};
216220
}
217221

@@ -222,13 +226,16 @@ const WithProgress = (superclass, object_path) =>
222226
* @return {import ("./dbus").RemoveFn} function to disable the callback
223227
*/
224228
onProgressChange(handler) {
225-
return this.client.onObjectChanged(object_path, PROGRESS_IFACE, (changes) => {
226-
const { TotalSteps, CurrentStep, Finished } = changes;
227-
if (TotalSteps === undefined && CurrentStep === undefined && Finished === undefined) {
228-
return;
229+
return this.client.onEvent("Progress", (progress) => {
230+
if (progress?.service === service_name) {
231+
const { current_step, max_steps, current_title, finished } = progress;
232+
handler({
233+
total: max_steps,
234+
current: current_step,
235+
message: current_title,
236+
finished,
237+
});
229238
}
230-
231-
this.getProgress().then(handler);
232239
});
233240
}
234241
};

0 commit comments

Comments
 (0)