2014-01-28 17:41:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2016-02-15 19:42:09 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2014-02-13 17:50:32 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
2014-01-28 17:41:26 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
|
2017-07-15 04:03:55 +00:00
|
|
|
const Dialog = imports.ui.dialog;
|
2014-03-15 08:01:50 +00:00
|
|
|
const Main = imports.ui.main;
|
2014-01-28 17:41:26 +00:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2014-02-13 17:50:32 +00:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2016-02-15 19:42:09 +00:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2017-03-19 14:37:15 +00:00
|
|
|
const PermissionStore = imports.misc.permissionStore;
|
2014-03-15 08:01:50 +00:00
|
|
|
const Shell = imports.gi.Shell;
|
2016-02-15 19:42:09 +00:00
|
|
|
const Signals = imports.signals;
|
|
|
|
const St = imports.gi.St;
|
2014-01-28 17:41:26 +00:00
|
|
|
|
2014-08-09 15:03:11 +00:00
|
|
|
const LOCATION_SCHEMA = 'org.gnome.system.location';
|
2014-02-16 15:06:55 +00:00
|
|
|
const MAX_ACCURACY_LEVEL = 'max-accuracy-level';
|
2014-08-06 16:04:00 +00:00
|
|
|
const ENABLED = 'enabled';
|
2014-02-16 15:06:55 +00:00
|
|
|
|
2016-02-22 22:43:49 +00:00
|
|
|
const APP_PERMISSIONS_TABLE = 'gnome';
|
2016-02-15 19:45:38 +00:00
|
|
|
const APP_PERMISSIONS_ID = 'geolocation';
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var GeoclueAccuracyLevel = {
|
2014-09-11 13:57:15 +00:00
|
|
|
NONE: 0,
|
|
|
|
COUNTRY: 1,
|
|
|
|
CITY: 4,
|
|
|
|
NEIGHBORHOOD: 5,
|
|
|
|
STREET: 6,
|
|
|
|
EXACT: 8
|
|
|
|
};
|
|
|
|
|
2016-02-15 19:45:38 +00:00
|
|
|
function accuracyLevelToString(accuracyLevel) {
|
|
|
|
for (let key in GeoclueAccuracyLevel) {
|
|
|
|
if (GeoclueAccuracyLevel[key] == accuracyLevel)
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'NONE';
|
|
|
|
}
|
|
|
|
|
2014-01-28 17:41:26 +00:00
|
|
|
var GeoclueIface = '<node> \
|
|
|
|
<interface name="org.freedesktop.GeoClue2.Manager"> \
|
|
|
|
<property name="InUse" type="b" access="read"/> \
|
2014-02-13 17:50:32 +00:00
|
|
|
<property name="AvailableAccuracyLevel" type="u" access="read"/> \
|
|
|
|
<method name="AddAgent"> \
|
|
|
|
<arg name="id" type="s" direction="in"/> \
|
|
|
|
</method> \
|
2014-01-28 17:41:26 +00:00
|
|
|
</interface> \
|
|
|
|
</node>';
|
|
|
|
|
|
|
|
const GeoclueManager = Gio.DBusProxy.makeProxyWrapper(GeoclueIface);
|
|
|
|
|
2014-02-13 17:50:32 +00:00
|
|
|
var AgentIface = '<node> \
|
|
|
|
<interface name="org.freedesktop.GeoClue2.Agent"> \
|
2014-02-16 15:33:51 +00:00
|
|
|
<property name="MaxAccuracyLevel" type="u" access="read"/> \
|
2014-02-13 17:50:32 +00:00
|
|
|
<method name="AuthorizeApp"> \
|
|
|
|
<arg name="desktop_id" type="s" direction="in"/> \
|
|
|
|
<arg name="req_accuracy_level" type="u" direction="in"/> \
|
|
|
|
<arg name="authorized" type="b" direction="out"/> \
|
|
|
|
<arg name="allowed_accuracy_level" type="u" direction="out"/> \
|
|
|
|
</method> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var Indicator = new Lang.Class({
|
2014-01-28 17:41:26 +00:00
|
|
|
Name: 'LocationIndicator',
|
|
|
|
Extends: PanelMenu.SystemIndicator,
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init() {
|
2014-01-28 17:41:26 +00:00
|
|
|
this.parent();
|
|
|
|
|
2014-06-24 19:17:09 +00:00
|
|
|
this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA });
|
2014-08-06 16:04:00 +00:00
|
|
|
this._settings.connect('changed::' + ENABLED,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onMaxAccuracyLevelChanged.bind(this));
|
2014-02-16 15:06:55 +00:00
|
|
|
this._settings.connect('changed::' + MAX_ACCURACY_LEVEL,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onMaxAccuracyLevelChanged.bind(this));
|
2014-02-16 15:06:55 +00:00
|
|
|
|
2014-01-28 17:41:26 +00:00
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'find-location-symbolic';
|
2014-02-13 17:50:32 +00:00
|
|
|
|
2015-08-06 09:19:37 +00:00
|
|
|
this._item = new PopupMenu.PopupSubMenuMenuItem('', true);
|
2014-02-13 17:50:32 +00:00
|
|
|
this._item.icon.icon_name = 'find-location-symbolic';
|
|
|
|
|
|
|
|
this._agent = Gio.DBusExportedObject.wrapJSObject(AgentIface, this);
|
2014-02-24 18:26:46 +00:00
|
|
|
this._agent.export(Gio.DBus.system, '/org/freedesktop/GeoClue2/Agent');
|
2014-02-13 17:50:32 +00:00
|
|
|
|
2015-08-06 09:19:37 +00:00
|
|
|
this._item.label.text = _("Location Enabled");
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onOffAction = this._item.menu.addAction(_("Disable"), this._onOnOffAction.bind(this));
|
2014-09-12 09:33:39 +00:00
|
|
|
this._item.menu.addSettingsAction(_("Privacy Settings"), 'gnome-privacy-panel.desktop');
|
2014-02-13 17:50:32 +00:00
|
|
|
|
|
|
|
this.menu.addMenuItem(this._item);
|
2014-01-28 17:41:26 +00:00
|
|
|
|
|
|
|
this._watchId = Gio.bus_watch_name(Gio.BusType.SYSTEM,
|
|
|
|
'org.freedesktop.GeoClue2',
|
|
|
|
0,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._connectToGeoclue.bind(this),
|
|
|
|
this._onGeoclueVanished.bind(this));
|
|
|
|
Main.sessionMode.connect('updated', this._onSessionUpdated.bind(this));
|
2014-03-15 08:01:50 +00:00
|
|
|
this._onSessionUpdated();
|
2014-02-16 15:06:55 +00:00
|
|
|
this._onMaxAccuracyLevelChanged();
|
2014-02-13 17:50:32 +00:00
|
|
|
this._connectToGeoclue();
|
2016-02-15 19:50:25 +00:00
|
|
|
this._connectToPermissionStore();
|
2014-01-28 17:41:26 +00:00
|
|
|
},
|
|
|
|
|
2014-02-13 17:50:32 +00:00
|
|
|
get MaxAccuracyLevel() {
|
2014-02-16 15:06:55 +00:00
|
|
|
return this._getMaxAccuracyLevel();
|
2014-02-13 17:50:32 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
AuthorizeAppAsync(params, invocation) {
|
2016-02-15 19:50:25 +00:00
|
|
|
let [desktopId, reqAccuracyLevel] = params;
|
2014-02-13 17:50:32 +00:00
|
|
|
|
2016-02-15 19:50:25 +00:00
|
|
|
let authorizer = new AppAuthorizer(desktopId,
|
|
|
|
reqAccuracyLevel,
|
|
|
|
this._permStoreProxy,
|
|
|
|
this._getMaxAccuracyLevel());
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
authorizer.authorize(accuracyLevel => {
|
2016-02-15 19:50:25 +00:00
|
|
|
let ret = (accuracyLevel != GeoclueAccuracyLevel.NONE);
|
|
|
|
invocation.return_value(GLib.Variant.new('(bu)',
|
|
|
|
[ret, accuracyLevel]));
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2014-02-13 17:50:32 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncIndicator() {
|
2016-02-15 19:54:55 +00:00
|
|
|
if (this._managerProxy == null) {
|
2014-01-28 17:41:26 +00:00
|
|
|
this._indicator.visible = false;
|
2014-08-09 15:38:20 +00:00
|
|
|
this._item.actor.visible = false;
|
2014-01-28 17:41:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-15 19:54:55 +00:00
|
|
|
this._indicator.visible = this._managerProxy.InUse;
|
2014-08-09 15:38:20 +00:00
|
|
|
this._item.actor.visible = this._indicator.visible;
|
2014-03-20 13:17:47 +00:00
|
|
|
this._updateMenuLabels();
|
2014-01-28 17:41:26 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectToGeoclue() {
|
2016-02-15 19:54:55 +00:00
|
|
|
if (this._managerProxy != null || this._connecting)
|
2014-02-15 15:17:58 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
this._connecting = true;
|
2014-02-15 13:42:43 +00:00
|
|
|
new GeoclueManager(Gio.DBus.system,
|
|
|
|
'org.freedesktop.GeoClue2',
|
|
|
|
'/org/freedesktop/GeoClue2/Manager',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onManagerProxyReady.bind(this));
|
2014-02-15 15:17:58 +00:00
|
|
|
return true;
|
2014-02-15 13:42:43 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onManagerProxyReady(proxy, error) {
|
2014-02-15 13:42:43 +00:00
|
|
|
if (error != null) {
|
2014-02-16 13:55:17 +00:00
|
|
|
log(error.message);
|
2014-02-13 17:50:32 +00:00
|
|
|
this._connecting = false;
|
2014-02-15 13:42:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-15 19:54:55 +00:00
|
|
|
this._managerProxy = proxy;
|
|
|
|
this._propertiesChangedId = this._managerProxy.connect('g-properties-changed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onGeocluePropsChanged.bind(this));
|
2014-01-28 17:41:26 +00:00
|
|
|
|
2014-02-13 17:50:32 +00:00
|
|
|
this._syncIndicator();
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._managerProxy.AddAgentRemote('gnome-shell', this._onAgentRegistered.bind(this));
|
2014-02-13 17:50:32 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onAgentRegistered(result, error) {
|
2014-02-13 17:50:32 +00:00
|
|
|
this._connecting = false;
|
|
|
|
this._notifyMaxAccuracyLevel();
|
|
|
|
|
|
|
|
if (error != null)
|
2014-02-16 13:55:17 +00:00
|
|
|
log(error.message);
|
2014-01-28 17:41:26 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onGeoclueVanished() {
|
2014-02-17 01:17:46 +00:00
|
|
|
if (this._propertiesChangedId) {
|
2016-02-15 19:54:55 +00:00
|
|
|
this._managerProxy.disconnect(this._propertiesChangedId);
|
2014-02-17 01:17:46 +00:00
|
|
|
this._propertiesChangedId = 0;
|
|
|
|
}
|
2016-02-15 19:54:55 +00:00
|
|
|
this._managerProxy = null;
|
2014-01-28 17:41:26 +00:00
|
|
|
|
2014-02-13 17:50:32 +00:00
|
|
|
this._syncIndicator();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onOnOffAction() {
|
2014-08-06 16:04:00 +00:00
|
|
|
let enabled = this._settings.get_boolean(ENABLED);
|
|
|
|
this._settings.set_boolean(ENABLED, !enabled);
|
2014-02-13 17:50:32 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onSessionUpdated() {
|
2014-03-15 08:01:50 +00:00
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
this.menu.setSensitive(sensitive);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMenuLabels() {
|
2014-08-06 16:04:00 +00:00
|
|
|
if (this._settings.get_boolean(ENABLED)) {
|
2015-08-06 09:19:37 +00:00
|
|
|
this._item.label.text = this._indicator.visible ? _("Location In Use")
|
|
|
|
: _("Location Enabled");
|
2014-03-20 13:17:47 +00:00
|
|
|
this._onOffAction.label.text = _("Disable");
|
2014-08-06 16:04:00 +00:00
|
|
|
} else {
|
2015-08-06 09:19:37 +00:00
|
|
|
this._item.label.text = _("Location Disabled");
|
2014-08-06 16:04:00 +00:00
|
|
|
this._onOffAction.label.text = _("Enable");
|
2014-02-13 17:50:32 +00:00
|
|
|
}
|
2014-03-20 13:17:47 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onMaxAccuracyLevelChanged() {
|
2014-03-20 13:17:47 +00:00
|
|
|
this._updateMenuLabels();
|
2014-02-13 17:50:32 +00:00
|
|
|
|
|
|
|
// Gotta ensure geoclue is up and we are registered as agent to it
|
|
|
|
// before we emit the notify for this property change.
|
|
|
|
if (!this._connectToGeoclue())
|
|
|
|
this._notifyMaxAccuracyLevel();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMaxAccuracyLevel() {
|
2014-09-11 13:57:15 +00:00
|
|
|
if (this._settings.get_boolean(ENABLED)) {
|
|
|
|
let level = this._settings.get_string(MAX_ACCURACY_LEVEL);
|
|
|
|
|
|
|
|
return GeoclueAccuracyLevel[level.toUpperCase()] ||
|
|
|
|
GeoclueAccuracyLevel.NONE;
|
|
|
|
} else {
|
|
|
|
return GeoclueAccuracyLevel.NONE;
|
|
|
|
}
|
2014-02-16 15:06:55 +00:00
|
|
|
},
|
2014-02-13 17:50:32 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_notifyMaxAccuracyLevel() {
|
2014-02-16 15:06:55 +00:00
|
|
|
let variant = new GLib.Variant('u', this._getMaxAccuracyLevel());
|
2014-02-16 13:55:17 +00:00
|
|
|
this._agent.emit_property_changed('MaxAccuracyLevel', variant);
|
2014-02-15 15:46:07 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onGeocluePropsChanged(proxy, properties) {
|
2014-02-15 16:28:58 +00:00
|
|
|
let unpacked = properties.deep_unpack();
|
|
|
|
if ("InUse" in unpacked)
|
|
|
|
this._syncIndicator();
|
2016-02-15 19:50:25 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_connectToPermissionStore() {
|
2016-02-15 19:50:25 +00:00
|
|
|
this._permStoreProxy = null;
|
2017-12-02 00:27:35 +00:00
|
|
|
new PermissionStore.PermissionStore(this._onPermStoreProxyReady.bind(this));
|
2016-02-15 19:50:25 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onPermStoreProxyReady(proxy, error) {
|
2016-02-15 19:50:25 +00:00
|
|
|
if (error != null) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._permStoreProxy = proxy;
|
|
|
|
},
|
2014-01-28 17:41:26 +00:00
|
|
|
});
|
2014-02-13 17:50:32 +00:00
|
|
|
|
|
|
|
function clamp(value, min, max) {
|
|
|
|
return Math.max(min, Math.min(max, value));
|
|
|
|
}
|
2016-02-15 19:42:09 +00:00
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var AppAuthorizer = new Lang.Class({
|
2016-02-15 19:45:38 +00:00
|
|
|
Name: 'LocationAppAuthorizer',
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(desktopId,
|
2016-02-15 19:45:38 +00:00
|
|
|
reqAccuracyLevel,
|
|
|
|
permStoreProxy,
|
|
|
|
maxAccuracyLevel) {
|
|
|
|
this.desktopId = desktopId;
|
|
|
|
this.reqAccuracyLevel = reqAccuracyLevel;
|
|
|
|
this._permStoreProxy = permStoreProxy;
|
|
|
|
this._maxAccuracyLevel = maxAccuracyLevel;
|
2017-02-15 10:47:45 +00:00
|
|
|
this._permissions = {};
|
2016-02-15 19:45:38 +00:00
|
|
|
|
|
|
|
this._accuracyLevel = GeoclueAccuracyLevel.NONE;
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
authorize(onAuthDone) {
|
2016-02-15 19:45:38 +00:00
|
|
|
this._onAuthDone = onAuthDone;
|
|
|
|
|
|
|
|
let appSystem = Shell.AppSystem.get_default();
|
|
|
|
this._app = appSystem.lookup_app(this.desktopId + ".desktop");
|
|
|
|
if (this._app == null || this._permStoreProxy == null) {
|
|
|
|
this._completeAuth();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._permStoreProxy.LookupRemote(APP_PERMISSIONS_TABLE,
|
|
|
|
APP_PERMISSIONS_ID,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onPermLookupDone.bind(this));
|
2016-02-15 19:45:38 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onPermLookupDone(result, error) {
|
2016-02-15 19:45:38 +00:00
|
|
|
if (error != null) {
|
|
|
|
if (error.domain == Gio.DBusError) {
|
|
|
|
// Likely no xdg-app installed, just authorize the app
|
|
|
|
this._accuracyLevel = this.reqAccuracyLevel;
|
|
|
|
this._permStoreProxy = null;
|
|
|
|
this._completeAuth();
|
|
|
|
} else {
|
|
|
|
// Currently xdg-app throws an error if we lookup for
|
|
|
|
// unknown ID (which would be the case first time this code
|
|
|
|
// runs) so we continue with user authorization as normal
|
|
|
|
// and ID is added to the store if user says "yes".
|
|
|
|
log(error.message);
|
|
|
|
this._permissions = {};
|
|
|
|
this._userAuthorizeApp();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[this._permissions] = result;
|
|
|
|
let permission = this._permissions[this.desktopId];
|
|
|
|
|
2016-02-23 17:29:47 +00:00
|
|
|
if (permission == null) {
|
2016-02-15 19:45:38 +00:00
|
|
|
this._userAuthorizeApp();
|
2016-02-23 17:29:47 +00:00
|
|
|
} else {
|
|
|
|
let [levelStr] = permission || ['NONE'];
|
|
|
|
this._accuracyLevel = GeoclueAccuracyLevel[levelStr] ||
|
|
|
|
GeoclueAccuracyLevel.NONE;
|
2016-02-15 19:45:38 +00:00
|
|
|
this._completeAuth();
|
2016-02-23 17:29:47 +00:00
|
|
|
}
|
2016-02-15 19:45:38 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_userAuthorizeApp() {
|
2016-02-15 19:45:38 +00:00
|
|
|
let name = this._app.get_name();
|
|
|
|
let appInfo = this._app.get_app_info();
|
2018-01-08 15:56:43 +00:00
|
|
|
let reason = appInfo.get_locale_string("X-Geoclue-Reason");
|
2016-02-15 19:45:38 +00:00
|
|
|
|
|
|
|
this._showAppAuthDialog(name, reason);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_showAppAuthDialog(name, reason) {
|
2016-02-15 19:45:38 +00:00
|
|
|
this._dialog = new GeolocationDialog(name,
|
|
|
|
reason,
|
|
|
|
this.reqAccuracyLevel);
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
let responseId = this._dialog.connect('response', (dialog, level) => {
|
|
|
|
this._dialog.disconnect(responseId);
|
|
|
|
this._accuracyLevel = level;
|
|
|
|
this._completeAuth();
|
|
|
|
});
|
2016-02-15 19:45:38 +00:00
|
|
|
|
|
|
|
this._dialog.open();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_completeAuth() {
|
2016-02-15 19:45:38 +00:00
|
|
|
if (this._accuracyLevel != GeoclueAccuracyLevel.NONE) {
|
|
|
|
this._accuracyLevel = clamp(this._accuracyLevel,
|
|
|
|
0,
|
|
|
|
this._maxAccuracyLevel);
|
|
|
|
}
|
|
|
|
this._saveToPermissionStore();
|
|
|
|
|
|
|
|
this._onAuthDone(this._accuracyLevel);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_saveToPermissionStore() {
|
2016-02-15 19:45:38 +00:00
|
|
|
if (this._permStoreProxy == null)
|
|
|
|
return;
|
|
|
|
|
2016-02-23 17:29:47 +00:00
|
|
|
let levelStr = accuracyLevelToString(this._accuracyLevel);
|
|
|
|
let dateStr = Math.round(Date.now() / 1000).toString();
|
|
|
|
this._permissions[this.desktopId] = [levelStr, dateStr];
|
|
|
|
|
2016-02-15 19:45:38 +00:00
|
|
|
let data = GLib.Variant.new('av', {});
|
|
|
|
|
|
|
|
this._permStoreProxy.SetRemote(APP_PERMISSIONS_TABLE,
|
|
|
|
true,
|
|
|
|
APP_PERMISSIONS_ID,
|
|
|
|
this._permissions,
|
|
|
|
data,
|
2017-10-31 00:38:18 +00:00
|
|
|
(result, error) => {
|
2016-02-15 19:45:38 +00:00
|
|
|
if (error != null)
|
|
|
|
log(error.message);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var GeolocationDialog = new Lang.Class({
|
2016-02-15 19:42:09 +00:00
|
|
|
Name: 'GeolocationDialog',
|
|
|
|
Extends: ModalDialog.ModalDialog,
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(name, subtitle, reqAccuracyLevel) {
|
2016-02-15 19:42:09 +00:00
|
|
|
this.parent({ styleClass: 'geolocation-dialog' });
|
|
|
|
this.reqAccuracyLevel = reqAccuracyLevel;
|
|
|
|
|
2017-07-15 04:03:55 +00:00
|
|
|
let icon = new Gio.ThemedIcon({ name: 'find-location-symbolic' });
|
2016-02-15 19:42:09 +00:00
|
|
|
|
2017-07-15 04:03:55 +00:00
|
|
|
/* Translators: %s is an application name */
|
|
|
|
let title = _("Give %s access to your location?").format(name);
|
|
|
|
let body = _("Location access can be changed at any time from the privacy settings.");
|
2016-02-15 19:42:09 +00:00
|
|
|
|
2017-07-15 04:03:55 +00:00
|
|
|
let contentParams = { icon, title, subtitle, body };
|
|
|
|
let content = new Dialog.MessageDialogContent(contentParams);
|
|
|
|
this.contentLayout.add_actor(content);
|
2016-03-03 18:57:02 +00:00
|
|
|
|
2016-02-15 19:42:09 +00:00
|
|
|
let button = this.addButton({ label: _("Deny Access"),
|
2017-12-02 00:27:35 +00:00
|
|
|
action: this._onDenyClicked.bind(this),
|
2016-02-15 19:42:09 +00:00
|
|
|
key: Clutter.KEY_Escape });
|
|
|
|
this.addButton({ label: _("Grant Access"),
|
2017-12-02 00:27:35 +00:00
|
|
|
action: this._onGrantClicked.bind(this) });
|
2016-02-15 19:42:09 +00:00
|
|
|
|
|
|
|
this.setInitialKeyFocus(button);
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onGrantClicked() {
|
2016-02-15 19:42:09 +00:00
|
|
|
this.emit('response', this.reqAccuracyLevel);
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onDenyClicked() {
|
2016-02-15 19:42:09 +00:00
|
|
|
this.emit('response', GeoclueAccuracyLevel.NONE);
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(GeolocationDialog.prototype);
|