Skip to content

Commit

Permalink
lib: port cockpit.user to use standard promises
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly authored and martinpitt committed Mar 27, 2024
1 parent 9c4cc9b commit 376bfeb
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions pkg/lib/cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2391,29 +2391,25 @@ function factory() {

let the_user = null;
cockpit.user = function () {
const dfd = cockpit.defer();
if (!the_user) {
const dbus = cockpit.dbus(null, { bus: "internal" });
dbus.call("/user", "org.freedesktop.DBus.Properties", "GetAll",
["cockpit.User"], { type: "s" })
.then(([user]) => {
the_user = {
id: user.Id.v,
name: user.Name.v,
full_name: user.Full.v,
groups: user.Groups.v,
home: user.Home.v,
shell: user.Shell.v
};
dfd.resolve(the_user);
})
.catch(ex => dfd.reject(ex))
.finally(() => dbus.close());
} else {
dfd.resolve(the_user);
}

return dfd.promise;
if (!the_user) {
const dbus = cockpit.dbus(null, { bus: "internal" });
return dbus.call("/user", "org.freedesktop.DBus.Properties", "GetAll",
["cockpit.User"], { type: "s" })
.then(([user]) => {
the_user = {
id: user.Id.v,
name: user.Name.v,
full_name: user.Full.v,
groups: user.Groups.v,
home: user.Home.v,
shell: user.Shell.v
};
return the_user;
})
.finally(() => dbus.close());
} else {
return Promise.resolve(the_user);
}
};

/* ------------------------------------------------------------------------
Expand Down

0 comments on commit 376bfeb

Please sign in to comment.