Skip to content

Commit

Permalink
Client: remove cache update type (#2157)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Jun 12, 2024
1 parent 6671435 commit 339e03b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
};

Expand Down
39 changes: 13 additions & 26 deletions src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()) {
Expand Down Expand Up @@ -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 ());
}
Expand All @@ -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;
Expand All @@ -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")) {
Expand Down Expand Up @@ -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
}
}
8 changes: 3 additions & 5 deletions src/Dialogs/UpdateFailDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand All @@ -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 ();
});
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 339e03b

Please sign in to comment.