[gnome-boxes/make-sure-preferred-kbd-doesnt-fail] unnatended-installer: Guard get_preferred_kbd_lang with try/catch



commit fdcd3376f2929d2b3be1106249e17d871b36b47b
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Jun 3 15:36:06 2019 +0200

    unnatended-installer: Guard get_preferred_kbd_lang with try/catch
    
    We shouldn't crash when the GSetting is not available. Instead we
    should map the user language to the libosinfo datamap and go with
    it. That's not 100% ideal because some users have a language which
    doesn't match their keyboard layout, but it is better than
    arbitrarialy setting en_US or crashing.

 src/unattended-installer.vala | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
---
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 8f12b2de..d02dabcc 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -703,18 +703,24 @@ else if (compatibility == CPUArchCompatibility.COMPATIBLE && drivers.lookup (loc
     }
 
     private string get_preferred_keyboard (string lang) {
-        var input_settings = new GLib.Settings ("org.gnome.desktop.input-sources");
-        var sources = input_settings.get_value ("sources");
-
-        string kbd_layout = null;
-        if (sources != null)
-            kbd_layout = sources.get_child_value (0).get_child_value (1).get_string ();
-
         var os_db = MediaManager.get_instance ().os_db;
         var datamap = os_db.get_datamap ("http://x.org/x11-keyboard";);
+        string kbd_layout = null;
 
-        if (datamap.reverse_lookup (kbd_layout) != null)
-            return kbd_layout;
+        try {
+            var input_settings = new GLib.Settings ("org.gnome.desktop.input-sources");
+            var sources = input_settings.get_value ("sources");
+
+            if (sources != null) {
+                kbd_layout = sources.get_child_value (0).get_child_value (1).get_string ();
+            }
+
+            if (datamap.reverse_lookup (kbd_layout) != null) {
+                return kbd_layout;
+            }
+        } catch (GLib.Error error) {
+            warning (error.message);
+        }
 
         kbd_layout = datamap.lookup (lang);
         if (kbd_layout != null)


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