Skip to content

Commit

Permalink
Specify an action on notifications to activate the tab
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed May 24, 2023
1 parent 9b84c32 commit b791787
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ namespace Midori {

add_action_entries (actions, this);

var tab_focus_action = new SimpleAction ("tab-focus", VariantType.STRING);
tab_focus_action.activate.connect (tab_focus_activated);
add_action (tab_focus_action);

var action = new SimpleAction ("win-new", VariantType.STRING);
action.activate.connect (win_new_activated);
add_action (action);
Expand Down Expand Up @@ -370,6 +374,20 @@ namespace Midori {
request.unref ();
}

void tab_focus_activated (Action action, Variant? parameter) {
string id = parameter.get_string ();
foreach (var browser in get_windows ()) {
if (!(browser is Browser))
continue;
foreach (var tab in ((Browser)browser).tabs.get_children ()) {
if (((Tab)tab).id == id) {
((Browser)browser).tabs.visible_child = tab;
browser.present ();
}
}
}
}

void win_new_activated (Action action, Variant? parameter) {
var browser = new Browser (this);
if (!browser.default_tab ()) {
Expand Down
1 change: 1 addition & 0 deletions core/tab.vala
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ namespace Midori {
notification.set_body (webkit_notification.body);
// Use a per-host ID to avoid collisions, but neglect the tag
string hostname = new Soup.URI (uri).host;
notification.set_default_action_and_target_value("app.tab-focus", id);
Application.get_default ().send_notification ("web-%s".printf (hostname), notification);
return true;
}
Expand Down

0 comments on commit b791787

Please sign in to comment.