Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify an action on notifications to activate the tab #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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 @@ -368,6 +372,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