From 35c2c15b3ca997d7770d7a10237bd5aec95ddcf3 Mon Sep 17 00:00:00 2001
From: c4pp4
Date: Sat, 17 Dec 2022 20:41:26 +0100
Subject: [PATCH 1/1] Use unity-control-center as the fallback

Try to use unity-control-center as the fallback when gnome-control-center
is not available.

Signed-off-by: c4pp4
---
 src/contacts-preferences-window.vala |  8 ++++++++
 src/meson.build                      |  1 +
 src/xdg-desktop.vala                 | 12 ++++++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 src/xdg-desktop.vala

diff --git a/src/contacts-preferences-window.vala b/src/contacts-preferences-window.vala
index 9c51210..2428a88 100644
--- a/src/contacts-preferences-window.vala
+++ b/src/contacts-preferences-window.vala
@@ -71,8 +71,16 @@ public class Contacts.PreferencesWindow : Adw.PreferencesWindow {
 
       proxy.call_sync ("Activate", param, DBusCallFlags.NONE, -1);
     } catch (Error e) {
+      if (in_desktop ("Unity")) {
+        try {
+          Process.spawn_command_line_async ("unity-control-center online-accounts");
+        } catch (SpawnError ex) {
+          warning ("Couldn't open Unity Control Center: %s", ex.message);
+        }
+      } else {
       // TODO: Show error dialog
       warning ("Couldn't open online-accounts: %s", e.message);
+      }
     }
   }
 }
diff --git a/src/meson.build b/src/meson.build
index e17fe6c..4ee2318 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -97,6 +97,7 @@ contacts_vala_sources = files(
   'contacts-type-combo.vala',
   'contacts-ui-state.vala',
   'main.vala',
+  'xdg-desktop.vala',
 )
 
 contacts_c_sources = [
diff --git a/src/xdg-desktop.vala b/src/xdg-desktop.vala
new file mode 100644
index 0000000..c9d5623
--- /dev/null
+++ b/src/xdg-desktop.vala
@@ -0,0 +1,12 @@
+private bool in_desktop (string name)
+{
+    var desktop_name_list = (!) Environment.get_variable ("XDG_CURRENT_DESKTOP");
+    if (desktop_name_list == "")
+        return false;
+
+    foreach (var n in desktop_name_list.split (":"))
+        if (n == name)
+            return true;
+
+    return false;
+}
-- 
2.38.2

