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

Throw toast when app is installed #1456

Merged
merged 17 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 2 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ public class AppCenter.App : Gtk.Application {
if (main_window != null) {
var win = main_window.get_window ();
if (win != null && (win.get_state () & Gdk.WindowState.FOCUSED) != 0) {
main_window.send_installed_toast (package);

break;
}
}
Expand Down
43 changes: 42 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
private Gee.LinkedList<string> return_button_history;
private Gtk.Label updates_badge;
private Gtk.Revealer updates_badge_revealer;
private Gtk.Overlay overlay;
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
public Granite.Widgets.Toast toast;
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved

private AppCenterCore.Package? last_installed_package;
private AppCenterCore.Package? selected_package;

private uint configure_id;
private int homepage_view_id;
Expand Down Expand Up @@ -103,8 +108,11 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {

return_button.clicked.connect (view_return);

homepage.package_selected.connect (package_selected);
homepage.subview_entered.connect (view_opened);
installed_view.package_selected.connect (package_selected);
installed_view.subview_entered.connect (view_opened);
search_view.package_selected.connect (package_selected);
search_view.subview_entered.connect (view_opened);
search_view.home_return_clicked.connect (show_homepage);

Expand All @@ -126,6 +134,19 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {

title = _(Build.APP_NAME);

toast = new Granite.Widgets.Toast ("");
toast.set_default_action (_("Open"));

toast.default_action.connect (() => {
if (last_installed_package != null) {
try {
last_installed_package.launch ();
} catch (Error e) {
warning ("Failed to launch %s: %s".printf (last_installed_package.get_name (), e.message));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I wonder if this should throw a dialog. If a user clicked the open button and then nothing happened, that seems bad. Thoughts @cassidyjames?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: This code is mostly a copy from AbstractAppContainer.launch_package_app()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danrabbit I'm indifferent. It probably makes sense to do what we do in other instances in AppCenter, and then we can file an issue to throw a dialog on failure.

}
}
});

return_button = new Gtk.Button ();
return_button.no_show_all = true;
return_button.valign = Gtk.Align.CENTER;
Expand Down Expand Up @@ -198,14 +219,18 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
stack.add (installed_view);
stack.add (search_view);

overlay = new Gtk.Overlay ();
overlay.add_overlay (toast);
overlay.add (stack);

var network_info_bar = new AppCenter.Widgets.NetworkInfoBar ();

var grid = new Gtk.Grid () {
orientation = Gtk.Orientation.VERTICAL
};
grid.add (headerbar);
grid.add (network_info_bar);
grid.add (stack);
grid.add (overlay);

add (grid);

Expand Down Expand Up @@ -306,6 +331,16 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
search_entry.text = term;
}

public void send_installed_toast (AppCenterCore.Package package) {
last_installed_package = package;

if (selected_package == null || (selected_package != null && selected_package.get_name () != package.get_name ())) {
cassidyjames marked this conversation as resolved.
Show resolved Hide resolved
toast.title = _("“%s” has been installed").printf (package.get_name ());

toast.send_notification ();
}
}

private void trigger_search () {
unowned string query = search_entry.text;
uint query_length = query.length;
Expand Down Expand Up @@ -337,6 +372,10 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
}
}

private void package_selected (AppCenterCore.Package package) {
selected_package = package;
}

private void view_opened (string? return_name, bool allow_search, string? custom_header = null, string? custom_search_placeholder = null) {
if (return_name != null) {
if (return_button_history.peek_head () != return_name) {
Expand Down Expand Up @@ -369,6 +408,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
}

private void view_return () {
selected_package = null;

if (stack.visible_child == search_view && !search_view.viewing_package && homepage.currently_viewed_category != null) {
homepage.return_clicked ();

Expand Down
3 changes: 3 additions & 0 deletions src/Views/View.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public abstract class AppCenter.View : Gtk.Stack {
public signal void subview_entered (string? return_name, bool allow_search, string? custom_header = null, string? custom_search_placeholder = null);
public signal void package_selected (AppCenterCore.Package package);

protected AppCenterCore.Package? previous_package = null;

Expand Down Expand Up @@ -48,6 +49,8 @@ public abstract class AppCenter.View : Gtk.Stack {

previous_package = null;

package_selected (package);

var package_hash = package.hash;

var pk_child = get_child_by_name (package_hash) as Views.AppInfoView;
Expand Down