[gnome-shell] weather: Follow GNOME Weather's location permissions



commit c3428f1efa39f5d096c6f64bac0baf6403f93924
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Mar 19 16:29:35 2017 +0100

    weather: Follow GNOME Weather's location permissions
    
    Our weather integration should follow GNOME Weather as closely as
    possible, which means that we should respect its location permission
    rather than using our own or none at all (which we can as a "system"
    component and as geoclue's authorization agent).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780252

 js/misc/permissionStore.js |    7 +++++++
 js/misc/weather.js         |   36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/js/misc/permissionStore.js b/js/misc/permissionStore.js
index b1dbe86..86c0cd8 100644
--- a/js/misc/permissionStore.js
+++ b/js/misc/permissionStore.js
@@ -17,6 +17,13 @@ const PermissionStoreIface = '<node> \
       <arg name="app_permissions" type="a{sas}" direction="in"/> \
       <arg name="data" type="v" direction="in"/> \
     </method> \
+    <signal name="Changed"> \
+      <arg name="table" type="s" direction="out"/> \
+      <arg name="id" type="s" direction="out"/> \
+      <arg name="deleted" type="b" direction="out"/> \
+      <arg name="data" type="v" direction="out"/> \
+      <arg name="permissions" type="a{sas}" direction="out"/> \
+    </signal> \
   </interface> \
 </node>';
 
diff --git a/js/misc/weather.js b/js/misc/weather.js
index 31ca192..13f29cb 100644
--- a/js/misc/weather.js
+++ b/js/misc/weather.js
@@ -7,6 +7,7 @@ const GWeather = imports.gi.GWeather;
 const Lang = imports.lang;
 const Signals = imports.signals;
 
+const PermissionStore = imports.misc.permissionStore;
 const Util = imports.misc.util;
 
 // Minimum time between updates to show loading indication
@@ -28,6 +29,25 @@ const WeatherClient = new Lang.Class({
         this._gclueStarting = false;
         this._gclueLocationChangedId = 0;
 
+        this._weatherAuthorized = false;
+        this._permStore = new PermissionStore.PermissionStore((proxy, error) => {
+            if (error) {
+                log('Failed to connect to permissionStore: ' + error.message);
+                return;
+            }
+
+            this._permStore.LookupRemote('gnome', 'geolocation', (res, error) => {
+                if (error)
+                    log('Error looking up permission: ' + error.message);
+
+                let [perms, data] = error ? [{}, null] : res;
+                let  params = ['gnome', 'geolocation', false, data, perms];
+                this._onPermStoreChanged(this._permStore, '', params);
+            });
+        });
+        this._permStore.connectSignal('Changed',
+                                      Lang.bind(this, this._onPermStoreChanged));
+
         this._locationSettings = new Gio.Settings({ schema_id: 'org.gnome.system.location' });
         this._locationSettings.connect('changed::enabled',
                                        Lang.bind(this, this._updateAutoLocation));
@@ -87,7 +107,8 @@ const WeatherClient = new Lang.Class({
 
     get _useAutoLocation() {
         return this._autoLocationRequested &&
-               this._locationSettings.get_boolean('enabled');
+               this._locationSettings.get_boolean('enabled') &&
+               this._weatherAuthorized;
     },
 
     _loadInfo: function() {
@@ -205,6 +226,19 @@ const WeatherClient = new Lang.Class({
 
         if (!this._useAutoLocation || !this._gclueStarted)
             this._setLocation(this._mostRecentLocation);
+    },
+
+    _onPermStoreChanged: function(proxy, sender, params) {
+        let [table, id, deleted, data, perms] = params;
+
+        if (table != 'gnome' || id != 'geolocation')
+            return;
+
+        let permission = perms['org.gnome.Weather.Application'] || ['NONE'];
+        let [accuracy] = permission;
+        this._weatherAuthorized = accuracy != 'NONE';
+
+        this._updateAutoLocation();
     }
 });
 Signals.addSignalMethods(WeatherClient.prototype);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]