Skip to content

Commit

Permalink
Fix obsolete cockpit defer API
Browse files Browse the repository at this point in the history
done/fail/always is the long-obsolete `cockpit.defer()` jQuery promise
API, which will be dropped eventually. Replace them with the standard
`Promise` API.

This requires a little teak in safeDBusCall() -- while `.fail()` also
returns the rejection, `Promise.catch()` handles it and returns nothing.

In `InstalledProducts.handleAutoAttach()`, both handlers in were doing
exactly the same thing, so use finally() instead. Also use an arrow
instead of a function to avoid the `self = this` dance.
  • Loading branch information
martinpitt committed Mar 27, 2024
1 parent 82827d0 commit c5924b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
19 changes: 10 additions & 9 deletions src/subscriptions-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ function parseErrorSeverity(error) {
* Method that calls a method on a dbus service proxy, only if it is available.
*
* If the service does not contain the provided method, we try to restart the rhsm service,
* and if the restart is successful, we call the delegate method; otherwise, we fail gracefully.
* and if the restart is successful, we call the delegate method; otherwise, log the error
* and return a Promise rejection.
*
* @param serviceProxy a dbus service proxy
* @param methodName a method on the provided serviceProxy
* @param delegateMethod the method that we delegate the actual call to dbus
*/
function safeDBusCall(serviceProxy, delegateMethod) {
return serviceProxy.wait()
.then(delegateMethod)
.fail(ex => {
console.debug(ex);
});
const promise = serviceProxy.wait()
.then(delegateMethod);
// we do want the caller to receive the rejection, so don't handle it
promise.catch(console.debug);
return promise;
}

let gettingDetails = false;
Expand Down Expand Up @@ -435,9 +436,9 @@ client.registerSystem = (subscriptionDetails, update_progress) => new Promise((r
client.closeRegisterDialog = true;
isRegistering = false;
console.debug('requesting update of subscription status');
requestSubscriptionStatusUpdate().always(resolve)
requestSubscriptionStatusUpdate().finally(resolve)
console.debug('requesting update of syspurpose status');
requestSyspurposeStatusUpdate().always(resolve)
requestSyspurposeStatusUpdate().finally(resolve)
});
});
});
Expand All @@ -455,7 +456,7 @@ client.unregisterSystem = () => {
'msg': parseErrorMessage(error)
};
})
.always(() => {
.finally(() => {
console.debug('requesting update');
requestSubscriptionStatusUpdate();
});
Expand Down
15 changes: 4 additions & 11 deletions src/subscriptions-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,17 @@ class InstalledProducts extends React.Component {
if (!event || event.button !== 0)
return;
if (this.props.autoAttach) {
let self = this;
this.setState({
attaching_in_progress: true,
attach_button_text: _("Auto-attaching ...")
});
this.props.autoAttach()
.done(function () {
self.setState({
.finally(() =>
this.setState({
attaching_in_progress: false,
attach_button_text: _("Auto-attach")
});
})
.fail(function () {
self.setState({
attaching_in_progress: false,
attach_button_text: _("Auto-attach")
});
});
})
);
}
}

Expand Down

0 comments on commit c5924b2

Please sign in to comment.