Last active
April 5, 2023 19:49
-
-
Save andyholmes/a9f123d9c62fe03288ef9c91f91d413b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Gio = imports.gi.Gio; | |
const GLib = imports.gi.GLib; | |
const ifaceXml = ` | |
<node> | |
<interface name="org.gnome.SettingsDaemon.Smartcard.Token"> | |
<property name="Name" type="s" access="read"/> | |
<property name="Driver" type="o" access="read"/> | |
<property name="IsInserted" type="b" access="read"/> | |
<property name="UsedToLogin" type="b" access="read"/> | |
</interface> | |
</node> | |
`; | |
const TestProxy = Gio.DBusProxy.makeProxyWrapper(ifaceXml); | |
let proxy = null; | |
function onNameAppeared(connection, name, _owner) { | |
print(`"${name}" appeared on the session bus`); | |
try { | |
proxy = new TestProxy( | |
Gio.DBus.session, | |
'org.gnome.SettingsDaemon.Smartcard', | |
'/org/gnome/SettingsDaemon/Smartcard/Manager/Tokens/token_from_p11_2d_kit_2d_proxy_2e_so_slot_17' | |
); | |
} catch (err) { | |
logError(err); | |
return; | |
} | |
proxy.connect('g-properties-changed', (proxy_, changed, invalidated) => { | |
for (let [prop, value] of Object.entries(changed.deepUnpack())) | |
print(`Property '${prop}' changed to '${value.deepUnpack()}'`); | |
for (let prop of invalidated) | |
print(`Property '${prop}' invalidated`); | |
}); | |
} | |
function onNameVanished(connection, name) { | |
print(`"${name}" vanished from the session bus`); | |
proxy = null; | |
} | |
let busWatchId = Gio.bus_watch_name( | |
Gio.BusType.SESSION, | |
'org.gnome.SettingsDaemon.Smartcard', // <-- well-known name of the service | |
Gio.BusNameWatcherFlags.NONE, | |
onNameAppeared, | |
onNameVanished | |
); | |
let loop = GLib.MainLoop.new(null, false); | |
loop.run(); | |
Gio.bus_unown_name(busWatchId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment