From 339e03b1391eb584bceff25a4e391db3ea1081a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 11 Jun 2024 18:00:25 -0700 Subject: [PATCH] Client: remove cache update type (#2157) --- src/Application.vala | 6 ++--- src/Core/Client.vala | 39 +++++++++++-------------------- src/Dialogs/UpdateFailDialog.vala | 8 +++---- src/MainWindow.vala | 2 +- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 3590c57c2..7bde187f5 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -202,7 +202,7 @@ public class AppCenter.App : Gtk.Application { if (active_window == null) { // Force a Flatpak cache refresh when the window is created, so we get new apps - client.update_cache.begin (true, AppCenterCore.Client.CacheUpdateType.FLATPAK); + client.update_cache.begin (true); var main_window = new MainWindow (this); add_window (main_window); @@ -347,13 +347,13 @@ public class AppCenter.App : Gtk.Application { } } - private void on_cache_update_failed (Error error, AppCenterCore.Client.CacheUpdateType cache_update_type) { + private void on_cache_update_failed (Error error) { if (active_window == null) { return; } if (update_fail_dialog == null) { - update_fail_dialog = new UpdateFailDialog (format_error_message (error.message), cache_update_type) { + update_fail_dialog = new UpdateFailDialog (format_error_message (error.message)) { transient_for = active_window }; diff --git a/src/Core/Client.vala b/src/Core/Client.vala index 4a0ece98f..9572a207d 100644 --- a/src/Core/Client.vala +++ b/src/Core/Client.vala @@ -16,7 +16,7 @@ public class AppCenterCore.Client : Object { public signal void operation_finished (Package package, Package.State operation, Error? error); - public signal void cache_update_failed (Error error, CacheUpdateType cache_update_type); + public signal void cache_update_failed (Error error); /** * This signal is likely to be fired from a non-main thread. Ensure any UI * logic driven from this runs on the GTK thread @@ -104,7 +104,7 @@ public class AppCenterCore.Client : Object { } } - public async void update_cache (bool force = false, CacheUpdateType cache_update_type = CacheUpdateType.ALL) { + public async void update_cache (bool force = false) { cancellable.reset (); if (Utils.is_running_in_demo_mode () || Utils.is_running_in_guest_session ()) { @@ -142,16 +142,9 @@ public class AppCenterCore.Client : Object { refresh_in_progress = true; try { - switch (cache_update_type) { - case CacheUpdateType.FLATPAK: - success = yield FlatpakBackend.get_default ().refresh_cache (cancellable); - break; - case CacheUpdateType.ALL: - success = yield FlatpakBackend.get_default ().refresh_cache (cancellable); - break; - } + success = yield FlatpakBackend.get_default ().refresh_cache (cancellable); - if (success && cache_update_type == CacheUpdateType.ALL) { + if (success) { last_cache_update = new DateTime.now_utc (); AppCenter.App.settings.set_int64 ("last-refresh-time", last_cache_update.to_unix ()); } @@ -160,7 +153,7 @@ public class AppCenterCore.Client : Object { } catch (Error e) { if (!(e is GLib.IOError.CANCELLED)) { critical ("Update_cache: Refesh cache async failed - %s", e.message); - cache_update_failed (e, cache_update_type); + cache_update_failed (e); } } finally { refresh_in_progress = false; @@ -170,16 +163,15 @@ public class AppCenterCore.Client : Object { debug ("Too soon to refresh and not forced"); } - if (cache_update_type == CacheUpdateType.ALL) { - var next_refresh = SECONDS_BETWEEN_REFRESHES - (uint)seconds_since_last_refresh; - debug ("Setting a timeout for a refresh in %f minutes", next_refresh / 60.0f); - update_cache_timeout_id = GLib.Timeout.add_seconds (next_refresh, () => { - update_cache_timeout_id = 0; - update_cache.begin (true); - return GLib.Source.REMOVE; - }); - } + var next_refresh = SECONDS_BETWEEN_REFRESHES - (uint)seconds_since_last_refresh; + debug ("Setting a timeout for a refresh in %f minutes", next_refresh / 60.0f); + update_cache_timeout_id = GLib.Timeout.add_seconds (next_refresh, () => { + update_cache_timeout_id = 0; + update_cache.begin (true); + + return GLib.Source.REMOVE; + }); if (nm.get_network_available ()) { if ((force || last_cache_update_is_old) && AppCenter.App.settings.get_boolean ("automatic-updates")) { @@ -222,9 +214,4 @@ public class AppCenterCore.Client : Object { public static unowned Client get_default () { return instance.once (() => { return new Client (); }); } - - public enum CacheUpdateType { - FLATPAK, - ALL - } } diff --git a/src/Dialogs/UpdateFailDialog.vala b/src/Dialogs/UpdateFailDialog.vala index e023d80ae..a14cc87cc 100644 --- a/src/Dialogs/UpdateFailDialog.vala +++ b/src/Dialogs/UpdateFailDialog.vala @@ -18,17 +18,15 @@ public class UpdateFailDialog : Granite.MessageDialog { private const int TRY_AGAIN_RESPONSE_ID = 1; public string error_message { get; construct; } - public AppCenterCore.Client.CacheUpdateType cache_update_type { get; construct; } - public UpdateFailDialog (string error_message, AppCenterCore.Client.CacheUpdateType cache_update_type) { + public UpdateFailDialog (string error_message) { Object ( title: "", primary_text: _("Failed to Fetch Updates"), secondary_text: _("This may have been caused by external, manually added software repositories or a corrupted sources file."), image_icon: new ThemedIcon ("dialog-error"), buttons: Gtk.ButtonsType.NONE, - error_message: error_message, - cache_update_type: cache_update_type + error_message: error_message ); } @@ -39,7 +37,7 @@ public class UpdateFailDialog : Granite.MessageDialog { response.connect ((response_id) => { if (response_id == TRY_AGAIN_RESPONSE_ID) { - AppCenterCore.Client.get_default ().update_cache.begin (true, cache_update_type); + AppCenterCore.Client.get_default ().update_cache.begin (true); } destroy (); }); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 58bff3f94..5247a8e6b 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -257,7 +257,7 @@ public class AppCenter.MainWindow : Gtk.ApplicationWindow { var client = AppCenterCore.Client.get_default (); automatic_updates_button.notify["active"].connect (() => { if (automatic_updates_button.active) { - client.update_cache.begin (true, AppCenterCore.Client.CacheUpdateType.FLATPAK); + client.update_cache.begin (true); } else { client.cancel_updates (true); }