.gitlab
.gitlab-ci
.settings
data
docs
js
extensionPrefs
gdm
misc
config.js.in
extensionUtils.js
fileUtils.js
gnomeSession.js
history.js
ibusManager.js
inputMethod.js
introspect.js
jsParse.js
keyboardManager.js
loginManager.js
meson.build
modemManager.js
objectManager.js
params.js
permissionStore.js
smartcardManager.js
systemActions.js
util.js
weather.js
perf
portalHelper
ui
js-resources.gresource.xml
meson.build
portal-resources.gresource.xml
prefs-resources.gresource.xml
lint
man
meson
po
src
subprojects
test
tests
tools
.eslintrc.yml
.gitignore
.gitlab-ci.yml
.gitmodules
COPYING
HACKING.md
NEWS
README.md
README.mdwn
cldr2json.py
config.h.meson
gnome-shell.doap
meson.build
meson_options.txt

Our coding style has always been to avoid braces when all blocks are single-lines. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
117 lines
3.6 KiB
JavaScript
117 lines
3.6 KiB
JavaScript
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
/* exported getSmartcardManager */
|
|
|
|
const Gio = imports.gi.Gio;
|
|
const Signals = imports.signals;
|
|
|
|
const ObjectManager = imports.misc.objectManager;
|
|
|
|
const SmartcardTokenIface = `
|
|
<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>`;
|
|
|
|
let _smartcardManager = null;
|
|
|
|
function getSmartcardManager() {
|
|
if (_smartcardManager == null)
|
|
_smartcardManager = new SmartcardManager();
|
|
|
|
return _smartcardManager;
|
|
}
|
|
|
|
var SmartcardManager = class {
|
|
constructor() {
|
|
this._objectManager = new ObjectManager.ObjectManager({ connection: Gio.DBus.session,
|
|
name: "org.gnome.SettingsDaemon.Smartcard",
|
|
objectPath: '/org/gnome/SettingsDaemon/Smartcard',
|
|
knownInterfaces: [SmartcardTokenIface],
|
|
onLoaded: this._onLoaded.bind(this) });
|
|
this._insertedTokens = {};
|
|
this._loginToken = null;
|
|
}
|
|
|
|
_onLoaded() {
|
|
let tokens = this._objectManager.getProxiesForInterface('org.gnome.SettingsDaemon.Smartcard.Token');
|
|
|
|
for (let i = 0; i < tokens.length; i++)
|
|
this._addToken(tokens[i]);
|
|
|
|
this._objectManager.connect('interface-added', (objectManager, interfaceName, proxy) => {
|
|
if (interfaceName == 'org.gnome.SettingsDaemon.Smartcard.Token')
|
|
this._addToken(proxy);
|
|
});
|
|
|
|
this._objectManager.connect('interface-removed', (objectManager, interfaceName, proxy) => {
|
|
if (interfaceName == 'org.gnome.SettingsDaemon.Smartcard.Token')
|
|
this._removeToken(proxy);
|
|
});
|
|
}
|
|
|
|
_updateToken(token) {
|
|
let objectPath = token.get_object_path();
|
|
|
|
delete this._insertedTokens[objectPath];
|
|
|
|
if (token.IsInserted)
|
|
this._insertedTokens[objectPath] = token;
|
|
|
|
if (token.UsedToLogin)
|
|
this._loginToken = token;
|
|
}
|
|
|
|
_addToken(token) {
|
|
this._updateToken(token);
|
|
|
|
token.connect('g-properties-changed', (proxy, properties) => {
|
|
if ('IsInserted' in properties.deep_unpack()) {
|
|
this._updateToken(token);
|
|
|
|
if (token.IsInserted)
|
|
this.emit('smartcard-inserted', token);
|
|
else
|
|
this.emit('smartcard-removed', token);
|
|
}
|
|
});
|
|
|
|
// Emit a smartcard-inserted at startup if it's already plugged in
|
|
if (token.IsInserted)
|
|
this.emit('smartcard-inserted', token);
|
|
}
|
|
|
|
_removeToken(token) {
|
|
let objectPath = token.get_object_path();
|
|
|
|
if (this._insertedTokens[objectPath] == token) {
|
|
delete this._insertedTokens[objectPath];
|
|
this.emit('smartcard-removed', token);
|
|
}
|
|
|
|
if (this._loginToken == token)
|
|
this._loginToken = null;
|
|
|
|
token.disconnectAll();
|
|
}
|
|
|
|
hasInsertedTokens() {
|
|
return Object.keys(this._insertedTokens).length > 0;
|
|
}
|
|
|
|
hasInsertedLoginToken() {
|
|
if (!this._loginToken)
|
|
return false;
|
|
|
|
if (!this._loginToken.IsInserted)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
};
|
|
Signals.addSignalMethods(SmartcardManager.prototype);
|