From fb15fab2197843f90ba6d5b8d9d8d35add11a85c Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 9 Dec 2020 19:39:34 +0100 Subject: [PATCH 01/12] Throw toast when app is installed --- src/Application.vala | 5 +++++ src/MainWindow.vala | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 1a08a820c..684350702 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -286,6 +286,11 @@ 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.toast.title = _("%s has been successfully installed").printf (package.get_name ()); + main_window.toast.set_default_action (_("Open")); + + main_window.toast.send_notification (); + break; } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 025361f9b..f0d22f346 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -40,6 +40,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { private Gee.LinkedList return_button_history; private Gtk.Label updates_badge; private Gtk.Revealer updates_badge_revealer; + private Gtk.Overlay overlay; + public Granite.Widgets.Toast toast; private uint configure_id; private int homepage_view_id; @@ -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; @@ -198,6 +202,10 @@ 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 () { @@ -205,7 +213,7 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { }; grid.add (headerbar); grid.add (network_info_bar); - grid.add (stack); + grid.add (overlay); add (grid); From 3d5437a1d68e802d32555865305e105e40c77318 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 9 Dec 2020 19:45:58 +0100 Subject: [PATCH 02/12] Update src/Application.vala Co-authored-by: Cassidy James Blaede --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 684350702..08198134d 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -286,7 +286,7 @@ 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.toast.title = _("%s has been successfully installed").printf (package.get_name ()); + main_window.toast.title = _("%s has been installed").printf (package.get_name ()); main_window.toast.set_default_action (_("Open")); main_window.toast.send_notification (); From b48d1bbc104758c9f3c1e698c7318b4e1e62dd53 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 9 Dec 2020 19:51:28 +0100 Subject: [PATCH 03/12] Launch package on click --- src/Application.vala | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 08198134d..aff30a873 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -286,10 +286,19 @@ 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.toast.title = _("%s has been installed").printf (package.get_name ()); - main_window.toast.set_default_action (_("Open")); - - main_window.toast.send_notification (); + var toast = main_window.toast; + toast.title = _("%s has been installed").printf (package.get_name ()); + 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 (); break; } From f75fc536d6c5412a1eac8fa8d0d47bfa3c5c66fc Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 9 Dec 2020 19:54:43 +0100 Subject: [PATCH 04/12] Update src/Application.vala Co-authored-by: Cassidy James Blaede --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 8a331589b..963e6900e 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -287,7 +287,7 @@ public class AppCenter.App : Gtk.Application { 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 ()); + toast.title = _("“%s” has been installed").printf (package.get_name ()); toast.set_default_action (_("Open")); toast.default_action.connect (() => { From 3bace928f80f81cca85ea12e0a7bceb513938cf5 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 9 Dec 2020 20:14:22 +0100 Subject: [PATCH 05/12] Launch last installed package --- src/Application.vala | 12 +++--------- src/MainWindow.vala | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 066700ea4..0fcdb44b9 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -33,6 +33,7 @@ public class AppCenter.App : Gtk.Application { public static bool silent; public static string? local_path; public static AppCenterCore.Package? local_package; + public static AppCenterCore.Package? last_installed_package; // Add "AppCenter" to the translation catalog public const string APPCENTER = N_("AppCenter"); @@ -282,21 +283,14 @@ public class AppCenter.App : Gtk.Application { switch (operation) { case AppCenterCore.Package.State.INSTALLING: if (error == null) { + last_installed_package = package; + // Check if window is focused 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 ()); - 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 (); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f0d22f346..6ee7a620d 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -129,6 +129,18 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { title = _(Build.APP_NAME); toast = new Granite.Widgets.Toast (""); + toast.set_default_action (_("Open")); + + toast.default_action.connect (() => { + var package = AppCenter.App.last_installed_package; + if (package != null) { + try { + package.launch (); + } catch (Error e) { + warning ("Failed to launch %s: %s".printf (package.get_name (), e.message)); + } + } + }); return_button = new Gtk.Button (); return_button.no_show_all = true; From 67cb1ff6bf8fbb9df67cf5ca8adbddd886fa4d96 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 9 Dec 2020 21:35:14 +0100 Subject: [PATCH 06/12] Hide the toast on the app's own app info view --- src/Application.vala | 9 ++++++--- src/Views/Homepage.vala | 1 + src/Views/InstalledView.vala | 1 + src/Views/SearchView.vala | 1 + src/Views/View.vala | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 0fcdb44b9..2f88a3e7b 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -33,6 +33,7 @@ public class AppCenter.App : Gtk.Application { public static bool silent; public static string? local_path; public static AppCenterCore.Package? local_package; + public static AppCenterCore.Package? selected_package; public static AppCenterCore.Package? last_installed_package; // Add "AppCenter" to the translation catalog @@ -289,10 +290,12 @@ 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 ()); + if (selected_package == null || (selected_package != null && selected_package.get_name () != package.get_name ())) { + var toast = main_window.toast; + toast.title = _("“%s” has been installed").printf (package.get_name ()); - toast.send_notification (); + toast.send_notification (); + } break; } diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index d7f6724cc..8c9347713 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -301,6 +301,7 @@ namespace AppCenter { public override void return_clicked () { transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; + AppCenter.App.selected_package = null; if (previous_package != null) { show_package (previous_package); diff --git a/src/Views/InstalledView.vala b/src/Views/InstalledView.vala index 3774abbb9..c1b7331b5 100644 --- a/src/Views/InstalledView.vala +++ b/src/Views/InstalledView.vala @@ -52,6 +52,7 @@ public class AppCenter.Views.InstalledView : View { } public override void return_clicked () { + AppCenter.App.selected_package = null; if (previous_package != null) { show_package (previous_package); subview_entered (C_("view", "Installed"), false, null); diff --git a/src/Views/SearchView.vala b/src/Views/SearchView.vala index 2cf8e103a..a2b151881 100644 --- a/src/Views/SearchView.vala +++ b/src/Views/SearchView.vala @@ -43,6 +43,7 @@ public class AppCenter.Views.SearchView : View { } public override void return_clicked () { + AppCenter.App.selected_package = null; if (viewing_package) { if (previous_package != null) { show_package (previous_package); diff --git a/src/Views/View.vala b/src/Views/View.vala index 68837e1bd..5847d68a9 100644 --- a/src/Views/View.vala +++ b/src/Views/View.vala @@ -47,6 +47,7 @@ public abstract class AppCenter.View : Gtk.Stack { transition_type = transition; previous_package = null; + AppCenter.App.selected_package = package; var package_hash = package.hash; From fd1e8d8877e1df18dfdd2404642fe7bcf076e7f0 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Fri, 11 Dec 2020 17:59:27 +0100 Subject: [PATCH 07/12] Refactor --- src/Application.vala | 11 +---------- src/MainWindow.vala | 22 ++++++++++++++++++---- src/Views/Homepage.vala | 1 - src/Views/InstalledView.vala | 1 - src/Views/SearchView.vala | 1 - src/Views/View.vala | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 2f88a3e7b..186dec7c5 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -33,8 +33,6 @@ public class AppCenter.App : Gtk.Application { public static bool silent; public static string? local_path; public static AppCenterCore.Package? local_package; - public static AppCenterCore.Package? selected_package; - public static AppCenterCore.Package? last_installed_package; // Add "AppCenter" to the translation catalog public const string APPCENTER = N_("AppCenter"); @@ -284,18 +282,11 @@ public class AppCenter.App : Gtk.Application { switch (operation) { case AppCenterCore.Package.State.INSTALLING: if (error == null) { - last_installed_package = package; - // Check if window is focused if (main_window != null) { var win = main_window.get_window (); if (win != null && (win.get_state () & Gdk.WindowState.FOCUSED) != 0) { - if (selected_package == null || (selected_package != null && selected_package.get_name () != package.get_name ())) { - var toast = main_window.toast; - toast.title = _("“%s” has been installed").printf (package.get_name ()); - - toast.send_notification (); - } + main_window.send_installed_toast (package); break; } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 6ee7a620d..909fe908c 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -43,6 +43,9 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { private Gtk.Overlay overlay; public Granite.Widgets.Toast toast; + private AppCenterCore.Package? last_installed_package; + public static AppCenterCore.Package? selected_package; + private uint configure_id; private int homepage_view_id; private int installed_view_id; @@ -132,12 +135,11 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { toast.set_default_action (_("Open")); toast.default_action.connect (() => { - var package = AppCenter.App.last_installed_package; - if (package != null) { + if (last_installed_package != null) { try { - package.launch (); + last_installed_package.launch (); } catch (Error e) { - warning ("Failed to launch %s: %s".printf (package.get_name (), e.message)); + warning ("Failed to launch %s: %s".printf (last_installed_package.get_name (), e.message)); } } }); @@ -326,6 +328,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 ())) { + 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; @@ -389,6 +401,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 (); diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index 8c9347713..d7f6724cc 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -301,7 +301,6 @@ namespace AppCenter { public override void return_clicked () { transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; - AppCenter.App.selected_package = null; if (previous_package != null) { show_package (previous_package); diff --git a/src/Views/InstalledView.vala b/src/Views/InstalledView.vala index c1b7331b5..3774abbb9 100644 --- a/src/Views/InstalledView.vala +++ b/src/Views/InstalledView.vala @@ -52,7 +52,6 @@ public class AppCenter.Views.InstalledView : View { } public override void return_clicked () { - AppCenter.App.selected_package = null; if (previous_package != null) { show_package (previous_package); subview_entered (C_("view", "Installed"), false, null); diff --git a/src/Views/SearchView.vala b/src/Views/SearchView.vala index a2b151881..2cf8e103a 100644 --- a/src/Views/SearchView.vala +++ b/src/Views/SearchView.vala @@ -43,7 +43,6 @@ public class AppCenter.Views.SearchView : View { } public override void return_clicked () { - AppCenter.App.selected_package = null; if (viewing_package) { if (previous_package != null) { show_package (previous_package); diff --git a/src/Views/View.vala b/src/Views/View.vala index 5847d68a9..9c43b0c5a 100644 --- a/src/Views/View.vala +++ b/src/Views/View.vala @@ -47,7 +47,7 @@ public abstract class AppCenter.View : Gtk.Stack { transition_type = transition; previous_package = null; - AppCenter.App.selected_package = package; + AppCenter.MainWindow.selected_package = package; var package_hash = package.hash; From 4de415c42de56789c10f12464bb3961dbecaccab Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 12 Dec 2020 09:30:19 +0100 Subject: [PATCH 08/12] Refactor to use signal --- src/MainWindow.vala | 9 ++++++++- src/Views/View.vala | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 909fe908c..bab480245 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -44,7 +44,7 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { public Granite.Widgets.Toast toast; private AppCenterCore.Package? last_installed_package; - public static AppCenterCore.Package? selected_package; + private AppCenterCore.Package? selected_package; private uint configure_id; private int homepage_view_id; @@ -108,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); @@ -369,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) { diff --git a/src/Views/View.vala b/src/Views/View.vala index 9c43b0c5a..7a4a0cd65 100644 --- a/src/Views/View.vala +++ b/src/Views/View.vala @@ -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; @@ -47,7 +48,8 @@ public abstract class AppCenter.View : Gtk.Stack { transition_type = transition; previous_package = null; - AppCenter.MainWindow.selected_package = package; + + package_selected (package); var package_hash = package.hash; From 3eabf4679cf515d7c78dcc1f155b263bbd503ca4 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 15 Dec 2020 20:13:46 +0100 Subject: [PATCH 09/12] Update src/MainWindow.vala MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Foré --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index bab480245..59ba95a6d 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -41,7 +41,7 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { private Gtk.Label updates_badge; private Gtk.Revealer updates_badge_revealer; private Gtk.Overlay overlay; - public Granite.Widgets.Toast toast; + private Granite.Widgets.Toast toast; private AppCenterCore.Package? last_installed_package; private AppCenterCore.Package? selected_package; From 28b9dc342182f27fe8b62576f57f4e97ebabb98b Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 15 Dec 2020 20:17:29 +0100 Subject: [PATCH 10/12] Create overlay in construct --- src/MainWindow.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 59ba95a6d..7dc4115db 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -40,7 +40,6 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { private Gee.LinkedList return_button_history; private Gtk.Label updates_badge; private Gtk.Revealer updates_badge_revealer; - private Gtk.Overlay overlay; private Granite.Widgets.Toast toast; private AppCenterCore.Package? last_installed_package; @@ -219,7 +218,7 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { stack.add (installed_view); stack.add (search_view); - overlay = new Gtk.Overlay (); + var overlay = new Gtk.Overlay (); overlay.add_overlay (toast); overlay.add (stack); From 58da95b5582fe06ff96021170c84150f2913720f Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 15 Dec 2020 20:23:21 +0100 Subject: [PATCH 11/12] Add comment to explain when to show a toast --- src/MainWindow.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 7dc4115db..315753729 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -333,6 +333,11 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { public void send_installed_toast (AppCenterCore.Package package) { last_installed_package = package; + // Show a toast if + // no package is selected --> we are not on an app page + // or + // a package is selected --> we are on an app page + // but the app's name is not equal to the package's name that should be installed if (selected_package == null || (selected_package != null && selected_package.get_name () != package.get_name ())) { toast.title = _("“%s” has been installed").printf (package.get_name ()); From 6a3766f75b1d96ef2cda0fe79b70fe9dba9ee2c4 Mon Sep 17 00:00:00 2001 From: Cassidy James Blaede Date: Fri, 18 Dec 2020 12:36:04 -0700 Subject: [PATCH 12/12] MainWindow: concise comment --- src/MainWindow.vala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 6633c1934..10f6ca992 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -333,11 +333,9 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { public void send_installed_toast (AppCenterCore.Package package) { last_installed_package = package; - // Show a toast if - // no package is selected --> we are not on an app page - // or - // a package is selected --> we are on an app page - // but the app's name is not equal to the package's name that should be installed + // Only show a toast when we're not on the installed app's page, i.e if + // no package is selected (we are not on an app page), or a package is + // selected but it's not the app we're installing. if (selected_package == null || (selected_package != null && selected_package.get_name () != package.get_name ())) { toast.title = _("“%s” has been installed").printf (package.get_name ());