[chrome-gnome-shell] Improved error handling when GNOME Shell is not installed or not running.



commit 61315cbb9948f29ccdd236a8387d57a4fadd25a8
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Wed Mar 8 22:00:52 2017 +0400

    Improved error handling when GNOME Shell is not installed or not running.
    
    1. Added check for GNOME Shell settings schema presense to avoid connector
    crash.
    2. Report that initialization is failed in case GNOME Shell version
    property is missing on Shell bus. This is happens eg with Unity.
    
    See-Also: https://git.gnome.org/browse/extensions-web/commit/?id=06fdd11a7be2fe29b49a1297bc281a51c28f96a0
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=779739

 connector/chrome-gnome-shell.py     |   47 +++++++++++++++++++++-------------
 extension/_locales/en/messages.json |    4 +++
 extension/include/constants.js      |    1 +
 extension/include/sweettooth-api.js |   20 +++++++++-----
 po/template.pot                     |   10 ++++++-
 5 files changed, 56 insertions(+), 26 deletions(-)
---
diff --git a/connector/chrome-gnome-shell.py b/connector/chrome-gnome-shell.py
index 0244881..ff9834b 100755
--- a/connector/chrome-gnome-shell.py
+++ b/connector/chrome-gnome-shell.py
@@ -354,27 +354,38 @@ class ChromeGNOMEShell(Gio.Application):
         debug('Execute: to %s' % request['execute'])
 
         if request['execute'] == 'initialize':
-            settings = Gio.Settings.new(SHELL_SCHEMA)
+            source = Gio.SettingsSchemaSource.get_default()
             shell_version = self.shell_proxy.get_cached_property("ShellVersion")
-            if EXTENSION_DISABLE_VERSION_CHECK_KEY in settings.keys():
-                disable_version_check = settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY)
-            else:
-                disable_version_check = False
 
-            self.send_message(
-                {
-                    'success': True,
-                    'properties': {
-                        'connectorVersion': CONNECTOR_VERSION,
-                        'shellVersion': shell_version.unpack() if shell_version is not None else None,
-                        'versionValidationEnabled': not disable_version_check,
-                        'supports': [
-                            'notifications',
-                            'update-check'
-                        ]
+            if source.lookup(SHELL_SCHEMA, False) is not None and shell_version is not None:
+                settings = Gio.Settings.new(SHELL_SCHEMA)
+
+                if EXTENSION_DISABLE_VERSION_CHECK_KEY in settings.keys():
+                    disable_version_check = settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY)
+                else:
+                    disable_version_check = False
+
+                self.send_message(
+                    {
+                        'success': True,
+                        'properties': {
+                            'connectorVersion': CONNECTOR_VERSION,
+                            'shellVersion': shell_version.unpack() if shell_version is not None else None,
+                            'versionValidationEnabled': not disable_version_check,
+                            'supports': [
+                                'notifications',
+                                'update-check'
+                            ]
+                        }
                     }
-                }
-            )
+                )
+            else:
+                self.send_message(
+                    {
+                        'success': False,
+                        'message': "no_gnome_shell"
+                    }
+                )
 
         elif request['execute'] == 'subscribeSignals':
             if not self.shellAppearedId:
diff --git a/extension/_locales/en/messages.json b/extension/_locales/en/messages.json
index e087551..6e508a1 100644
--- a/extension/_locales/en/messages.json
+++ b/extension/_locales/en/messages.json
@@ -43,6 +43,10 @@
        "network_error": {
                "message": "A network error has occurred. Please check your Internet connection and/or proxy 
settings."
        },
+       "no_gnome_shell": {
+               "message": "Unable to locate GNOME Shell settings or version. Make sure it is installed and 
running.",
+               "description": "Shown to user when native connector unable to query GNOME Shell version or 
settings"
+       },
        "no_host_response": {
                "message": "No host response",
                "description": "Means 'Web extension does not received answer from native messaging host 
application.'"
diff --git a/extension/include/constants.js b/extension/include/constants.js
index 115966f..45dd91b 100644
--- a/extension/include/constants.js
+++ b/extension/include/constants.js
@@ -51,6 +51,7 @@ DEFAULT_LOCAL_OPTIONS                 = {
 EXTERNAL_MESSAGES                      = [
        "connecting_host_app",
        "error_extension_response",
+       "no_gnome_shell",
        "no_host_connector",
        "warning_apis_missing"
 ];
diff --git a/extension/include/sweettooth-api.js b/extension/include/sweettooth-api.js
index f1edc2f..0a52e07 100644
--- a/extension/include/sweettooth-api.js
+++ b/extension/include/sweettooth-api.js
@@ -70,15 +70,21 @@ window.SweetTooth = function () {
                                return Promise.resolve(apiObject);
                        }
 
-                       var ready = sendResolveExtensionMessage("initialize", "properties", null);
+                       var ready = new Promise(function(resolve, reject) {
+                               sendExtensionMessage("initialize", response => {
+                                       if (response && response.success && response.properties && 
response.properties.shellVersion)
+                                       {
+                                               resolve(response.properties);
+                                       }
+                                       else
+                                       {
+                                               var message = response && response.message ? 
GSC.getMessage(response.message) : GSC.getMessage('error_extension_response');
+                                               reject(message);
+                                       }
+                               });
+                       });
 
                        ready.then(function (response) {
-                               if(!response.shellVersion)
-                               {
-                                       apiObject.apiVersion = null;
-                                       return;
-                               }
-
                                apiObject.shellVersion = response.shellVersion;
                                apiObject.versionValidationEnabled = response.versionValidationEnabled;
 
diff --git a/po/template.pot b/po/template.pot
index 61d8d1a..a088855 100644
--- a/po/template.pot
+++ b/po/template.pot
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: 1.0\n"
 "Report-Msgid-Bugs-To: ykonotopov gnome org\n"
-"POT-Creation-Date: 2017-02-12 19:03+0000\n"
+"POT-Creation-Date: 2017-03-08 18:00+0000\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
@@ -99,6 +99,14 @@ msgstr ""
 msgid "No"
 msgstr ""
 
+#. Shown to user when native connector unable to query GNOME Shell version or
+#. settings
+#: chrome-gnome-shell-key-no_gnome_shell:1
+msgid ""
+"Unable to locate GNOME Shell settings or version. Make sure it is installed "
+"and running."
+msgstr ""
+
 #: chrome-gnome-shell-key-no_host_connector:1
 msgid ""
 "Although GNOME Shell integration extension is running, native host connector"


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