Skip to content

Commit

Permalink
feat(host): async open_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr committed Dec 19, 2024
1 parent 9a50c1a commit 4710ad9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Services/Accounts/SecretAccountStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Utils/Host.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 4710ad9

Please sign in to comment.