From 418a2470418c307ac37e7b4406ea4c2373bf7527 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Fri, 20 Dec 2024 01:33:36 +0200 Subject: [PATCH] feat(host): async open_uri --- src/Services/Accounts/SecretAccountStore.vala | 38 +++++++++++-------- src/Utils/Host.vala | 18 +++++++++ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/Services/Accounts/SecretAccountStore.vala b/src/Services/Accounts/SecretAccountStore.vala index 6221244b7..f618c1169 100644 --- a/src/Services/Accounts/SecretAccountStore.vala +++ b/src/Services/Accounts/SecretAccountStore.vala @@ -25,25 +25,25 @@ public class Tuba.SecretAccountStore : AccountStore { attrs["version"] = VERSION; List secrets = new List (); - try { - secrets = Secret.password_searchv_sync ( - schema, - attrs, - Secret.SearchFlags.ALL | Secret.SearchFlags.UNLOCK, - null - ); - } catch (GLib.Error e) { + // try { + // secrets = Secret.password_searchv_sync ( + // schema, + // attrs, + // Secret.SearchFlags.ALL | Secret.SearchFlags.UNLOCK, + // null + // ); + // } catch (GLib.Error e) { string wiki_page = "https://github.com/GeopJr/Tuba/wiki/keyring-issues"; // Let's leave this untranslated for now string help_msg = "If you didn’t manually cancel it, try creating a password keyring named \"login\" using Passwords and Keys (seahorse) or KWalletManager"; // vala-lint=line-length - if (e.message == "org.freedesktop.DBus.Error.ServiceUnknown") { - wiki_page = "https://github.com/GeopJr/Tuba/wiki/libsecret-issues"; - help_msg = @"$(e.message), $(Build.NAME) might be missing some permissions"; - } + // if (e.message == "org.freedesktop.DBus.Error.ServiceUnknown") { + // wiki_page = "https://github.com/GeopJr/Tuba/wiki/libsecret-issues"; + // help_msg = @"$(e.message), $(Build.NAME) might be missing some permissions"; + // } - critical (@"Error while searching for items in the secret service: $(e.message)"); + // critical (@"Error while searching for items in the secret service: $(e.message)"); warning (@"$help_msg\nread more: $wiki_page"); new Dialogs.NewAccount (); @@ -55,11 +55,17 @@ public class Tuba.SecretAccountStore : AccountStore { null, false, (obj, res) => { - if (app.question.end (res).truthy ()) Host.open_url (wiki_page); - Process.exit (1); + if (app.question.end (res).truthy ()) { + Host.open_url_async.begin (wiki_page, (obj, res) => { + Host.open_url_async.end (res); + Process.exit (1); + }); + } else { + Process.exit (1); + } } ); - } + // } secrets.foreach (item => { // TODO: remove uuid fallback diff --git a/src/Utils/Host.vala b/src/Utils/Host.vala index fa4af4412..3fb6f01b8 100644 --- a/src/Utils/Host.vala +++ b/src/Utils/Host.vala @@ -29,6 +29,24 @@ public class Tuba.Host { return true; } + public static async bool open_url_async (string url) { + debug (@"Opening URL async: $url"); + + try { + yield (new Gtk.UriLauncher (url)).launch (app.active_window, null); + } catch (Error e) { + warning (@"Error opening uri \"$url\": $(e.message)"); + try { + yield AppInfo.launch_default_for_uri_async (url, null, null); + } catch (Error e) { + warning (@"Error opening uri \"$url\": $(e.message)"); + return false; + } + } + + return true; + } + private static void open_in_default_app (string uri) { debug (@"Opening URI: $uri");