Skip to content

Commit

Permalink
Move Client class functions to UpdateManager (#2160)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Jun 12, 2024
1 parent 6708806 commit 7831acc
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 192 deletions.
1 change: 0 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ src/MainWindow.vala
src/SuspendControl.vala
src/Utils.vala
src/Core/ChangeInformation.vala
src/Core/Client.vala
src/Core/FlatpakBackend.vala
src/Core/Job.vala
src/Core/Package.vala
Expand Down
22 changes: 11 additions & 11 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ public class AppCenter.App : Gtk.Application {
activate ();
});

var client = AppCenterCore.Client.get_default ();
client.operation_finished.connect (on_operation_finished);
client.cache_update_failed.connect (on_cache_update_failed);

var flatpak_backend = AppCenterCore.FlatpakBackend.get_default ();
flatpak_backend.operation_finished.connect (on_operation_finished);

var update_manager = AppCenterCore.UpdateManager.get_default ();
update_manager.cache_update_failed.connect (on_cache_update_failed);

refresh_action = new SimpleAction ("refresh", null);
refresh_action.set_enabled (!Utils.is_running_in_guest_session ());
refresh_action.activate.connect (() => {
client.update_cache.begin (true);
update_manager.update_cache.begin (true);
});

repair_action = new SimpleAction ("repair", null);
Expand Down Expand Up @@ -181,7 +181,7 @@ public class AppCenter.App : Gtk.Application {
}

public override void activate () {
var client = AppCenterCore.Client.get_default ();
unowned var update_manager = AppCenterCore.UpdateManager.get_default ();

if (first_activation) {
first_activation = false;
Expand All @@ -196,14 +196,14 @@ public class AppCenter.App : Gtk.Application {
});

// Don't force a cache refresh for the silent daemon, it'll run if it was >24 hours since the last one
client.update_cache.begin (false);
update_manager.update_cache.begin (false);
silent = false;
return;
}

if (active_window == null) {
// Force a Flatpak cache refresh when the window is created, so we get new apps
client.update_cache.begin (true);
update_manager.update_cache.begin (true);

var main_window = new MainWindow (this);
add_window (main_window);
Expand Down Expand Up @@ -295,19 +295,19 @@ public class AppCenter.App : Gtk.Application {

private uint cache_update_timeout_id = 0;
private void schedule_cache_update (bool cancel = false) {
var client = AppCenterCore.Client.get_default ();
unowned var update_manager = AppCenterCore.UpdateManager.get_default ();

if (cache_update_timeout_id > 0) {
Source.remove (cache_update_timeout_id);
cache_update_timeout_id = 0;
}

if (cancel) {
client.cancel_updates (true); // Also stops timeouts.
update_manager.cancel_updates (true); // Also stops timeouts.
return;
} else {
cache_update_timeout_id = Timeout.add_seconds (SECONDS_AFTER_NETWORK_UP, () => {
client.update_cache.begin ();
update_manager.update_cache.begin ();
cache_update_timeout_id = 0;
return false;
});
Expand Down
153 changes: 0 additions & 153 deletions src/Core/Client.vala

This file was deleted.

3 changes: 2 additions & 1 deletion src/Core/FlatpakBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class AppCenterCore.FlatpakPackage : Package {
}

public class AppCenterCore.FlatpakBackend : Object {
public signal void operation_finished (Package package, Package.State operation, Error? error);
public signal void cache_flush_needed ();

// Based on https://github.com/flatpak/flatpak/blob/417e3949c0ecc314e69311e3ee8248320d3e3d52/common/flatpak-run-private.h
Expand Down Expand Up @@ -251,7 +252,7 @@ public class AppCenterCore.FlatpakBackend : Object {
warning ("Unable to refresh cache after external change: %s", e.message);
}

yield Client.get_default ().refresh_updates ();
yield UpdateManager.get_default ().get_updates ();
}

static construct {
Expand Down
17 changes: 8 additions & 9 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ public class AppCenterCore.Package : Object {

var success = yield perform_operation (State.UPDATING, State.INSTALLED, State.UPDATE_AVAILABLE);
if (success && refresh_updates_after) {
unowned Client client = Client.get_default ();
yield client.refresh_updates ();
yield UpdateManager.get_default ().get_updates ();
}

return success;
Expand All @@ -471,17 +470,17 @@ public class AppCenterCore.Package : Object {
return false;
}

unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default ();

try {
bool success = yield perform_operation (State.INSTALLING, State.INSTALLED, State.NOT_INSTALLED);
if (success) {
var client = AppCenterCore.Client.get_default ();
client.operation_finished (this, State.INSTALLING, null);
flatpak_backend.operation_finished (this, State.INSTALLING, null);
}

return success;
} catch (Error e) {
var client = AppCenterCore.Client.get_default ();
client.operation_finished (this, State.INSTALLING, e);
flatpak_backend.operation_finished (this, State.INSTALLING, e);
return false;
}
}
Expand Down Expand Up @@ -539,8 +538,8 @@ public class AppCenterCore.Package : Object {
}

private async bool perform_package_operation () throws GLib.Error {
var backend = AppCenterCore.FlatpakBackend.get_default ();
var client = AppCenterCore.Client.get_default ();
unowned var backend = AppCenterCore.FlatpakBackend.get_default ();
unowned var update_manager = AppCenterCore.UpdateManager.get_default ();

switch (state) {
case State.UPDATING:
Expand All @@ -560,7 +559,7 @@ public class AppCenterCore.Package : Object {
var success = yield backend.remove_package (this, change_information, action_cancellable);
_installed = !success;
update_state ();
yield client.refresh_updates ();
yield update_manager.get_updates ();
return success;
default:
return false;
Expand Down
Loading

0 comments on commit 7831acc

Please sign in to comment.