From 4710ad9765d41eb871e9a949f07e05d07239d7ed 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 | 10 ++++++++-- src/Utils/Host.vala | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Services/Accounts/SecretAccountStore.vala b/src/Services/Accounts/SecretAccountStore.vala index 6221244b7..a925cdf03 100644 --- a/src/Services/Accounts/SecretAccountStore.vala +++ b/src/Services/Accounts/SecretAccountStore.vala @@ -55,8 +55,14 @@ 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); + } } ); } 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");