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 4 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
14 changes: 14 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ 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) {
var toast = main_window.toast;
toast.title = _("%s has been installed").printf (package.get_name ());
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
toast.set_default_action (_("Open"));

toast.default_action.connect (() => {
try {
package.launch ();
} catch (Error e) {
warning ("Failed to launch %s: %s".printf (package.get_name (), e.message));
}
});

toast.send_notification ();
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to handle sending the toast and saving the package reference inside MainWindow, instead of trying to expose last_installed_package in Application and then accessing it back in MainWindow.

Simply declare a private AppCenterCore.Package? last_installed_package member and a public void send_installed_toast (AppCenterCore.Package package) method in MainWindow and manage sending the toast there instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I now also need selected_package in AppCenter.App to check if a Toast should be sent.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean sure, but that didn't resolve my issue. The toast is still half managed in Application and MainWindow at the same time. And there's also no need to store selected_package globaly inside Application. Notice how MainWindow actually calls show_package and return_clicked where this property could be set within MainWindow as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your feedback. I have refactored that except for selected_package.

The show_package call in MainWindow is not the same as in View.

Copy link
Member Author

Choose a reason for hiding this comment

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

I refactored it using a signal.

@donadigo thanks for being persistent 😃 The code looks much cleaner now 👍


break;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ 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 uint configure_id;
private int homepage_view_id;
Expand Down Expand Up @@ -126,6 +128,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {

title = _(Build.APP_NAME);

toast = new Granite.Widgets.Toast ("");

return_button = new Gtk.Button ();
return_button.no_show_all = true;
return_button.valign = Gtk.Align.CENTER;
Expand Down Expand Up @@ -198,14 +202,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