[gnome-maps] mapSource: Add MAPS_SERVICE environment override



commit 411a7e21ce7d8e139fc74ee228f790d45c097386
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sat Aug 20 20:28:24 2016 +0200

    mapSource: Add MAPS_SERVICE environment override

 src/mapSource.js |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/src/mapSource.js b/src/mapSource.js
index ff18f83..db46ae6 100644
--- a/src/mapSource.js
+++ b/src/mapSource.js
@@ -26,6 +26,7 @@ const Gtk = imports.gi.Gtk;
 const GtkClutter = imports.gi.GtkClutter;
 const Lang = imports.lang;
 const Soup = imports.gi.Soup;
+const System = imports.system;
 
 const Utils = imports.utils;
 
@@ -85,18 +86,30 @@ function _updateAttributionImage(source) {
     _attributionImage.pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
 }
 
-function _createDefaultService() {
-    let filename = GLib.build_filenamev([pkg.pkgdatadir,
-                                         _DEFAULT_SERVICE_FILE]);
+function _getServiceFromFile(filename) {
     let data = Utils.readFile(filename);
+    if (!data) {
+        log('Failed to open service file: ' + filename);
+        System.exit(1);
+    }
     _tileService = JSON.parse(data).tiles;
     return _tileService;
 }
 
+function _createDefaultService() {
+    let filename = GLib.build_filenamev([pkg.pkgdatadir,
+                                         _DEFAULT_SERVICE_FILE]);
+    return _getServiceFromFile(filename);
+}
+
 function _getTileService() {
     if (_tileService)
         return _tileService;
 
+    let serviceOverride = GLib.getenv('MAPS_SERVICE');
+    if (serviceOverride)
+        return _getServiceFromFile(serviceOverride);
+
     let user_agent = 'gnome-maps/' + pkg.version;
     let session = new Soup.Session({ user_agent : user_agent });
     let msg = Soup.Message.new('GET', _TILE_SERVICE_URL);


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