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 418a247
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Services/Accounts/SecretAccountStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ public class Tuba.SecretAccountStore : AccountStore {
attrs["version"] = VERSION;

List<Secret.Retrievable> secrets = new List<Secret.Retrievable> ();
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 ();
Expand All @@ -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
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 418a247

Please sign in to comment.