From 0f595eb4b0c11c3da76d0fc88cce58c41c7563d9 Mon Sep 17 00:00:00 2001
From: c4pp4
Date: Sun, 28 Dec 2025 15:48:41 +0100
Subject: [PATCH 1/1] Use gnome-online-accounts-gtk as the fallback

Try to use gnome-online-accounts-gtk 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 3937813..f9ebf49 100644
--- a/src/contacts-preferences-window.vala
+++ b/src/contacts-preferences-window.vala
@@ -58,8 +58,16 @@ public class Contacts.PreferencesWindow : Adw.PreferencesDialog {
 
       proxy.call_sync ("Activate", param, DBusCallFlags.NONE, -1);
     } catch (Error e) {
+      if (in_desktop ("Unity")) {
+        try {
+          Process.spawn_command_line_async ("gnome-online-accounts-gtk");
+        } catch (SpawnError ex) {
+          warning ("Couldn't open GNOME Online Accounts GTK: %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 8beb9b4..97bc37c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -109,6 +109,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.51.2

