Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions src/Core/Backend.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Leonhard Kargl <leo.kargl@proton.me>
*/

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

public abstract void notify_package_changed (Package package);
public abstract async void install_package (Package package, ChangeInformation change_info) throws Error;
public abstract async void remove_package (Package package, ChangeInformation change_info) throws Error;
public abstract async void update_package (Package package, ChangeInformation change_info) throws Error;
}
6 changes: 3 additions & 3 deletions src/Core/FlatpakBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AppCenterCore.FlatpakPackage : Package {

public FlatpakPackage (string uid, Flatpak.Installation installation, AppStream.Component component) {
Object (
backend: FlatpakBackend.get_default (),
uid: uid,
installation: installation,
component: component
Expand Down Expand Up @@ -49,8 +50,7 @@ public class AppCenterCore.FlatpakPackage : Package {
}
}

public class AppCenterCore.FlatpakBackend : Object {
public signal void operation_finished (Package package, Package.State operation, Error? error);
public class AppCenterCore.FlatpakBackend : Object, Backend {
public signal void on_metadata_remote_preprocessed (string remote_title);
public signal void package_list_changed ();

Expand Down Expand Up @@ -231,7 +231,7 @@ public class AppCenterCore.FlatpakBackend : Object {
runtime_updates_component.summary = _("Updates to app runtimes");
runtime_updates_component.add_icon (runtime_icon);

runtime_updates = new AppCenterCore.Package ("runtime-updates", runtime_updates_component);
runtime_updates = new AppCenterCore.Package (this, "runtime-updates", runtime_updates_component);

additional_updates = new GLib.ListStore (typeof (Package));
additional_updates.append (runtime_updates);
Expand Down
16 changes: 7 additions & 9 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class AppCenterCore.Package : Object {
public const string LOCAL_ID_SUFFIX = ".appcenter-local";
public const string DEFAULT_PRICE_DOLLARS = "1";

public unowned Backend backend { get; construct; }
public string uid { get; construct; }

public AppStream.Component component { get; protected set; }
Expand Down Expand Up @@ -418,8 +419,8 @@ public class AppCenterCore.Package : Object {
change_information = new ChangeInformation ();
}

public Package (string uid, AppStream.Component component) {
Object (uid: uid, component: component);
public Package (Backend backend, string uid, AppStream.Component component) {
Object (backend: backend, uid: uid, component: component);
}

public void replace_component (AppStream.Component component) {
Expand Down Expand Up @@ -455,7 +456,7 @@ public class AppCenterCore.Package : Object {
// Only trigger a notify if the state has changed, quite a lot of things listen to this
if (state != new_state) {
state = new_state;
FlatpakBackend.get_default ().notify_package_changed (this);
backend.notify_package_changed (this);
}
}

Expand Down Expand Up @@ -502,15 +503,14 @@ public class AppCenterCore.Package : Object {
change_information.start ();
state = performing;

unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default ();
flatpak_backend.notify_package_changed (this);
backend.notify_package_changed (this);

try {
yield perform_package_operation ();
flatpak_backend.operation_finished (this, performing, null);
backend.operation_finished (this, performing, null);
} catch (GLib.Error e) {
warning ("Operation failed for package %s - %s", name, e.message);
flatpak_backend.operation_finished (this, performing, e);
backend.operation_finished (this, performing, e);
throw e;
} finally {
change_information.complete ();
Expand All @@ -519,8 +519,6 @@ public class AppCenterCore.Package : Object {
}

private async void perform_package_operation () throws GLib.Error {
unowned var backend = AppCenterCore.FlatpakBackend.get_default ();

switch (state) {
case State.UPDATING:
yield backend.update_package (this, change_information);
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ appcenter_files = files(
'SuspendControl.vala',
'Utils.vala',
'Core' / 'AddonFilter.vala',
'Core' / 'Backend.vala',
'Core/CardUtils.vala',
'Core' / 'CategoryManager.vala',
'Core/ChangeInformation.vala',
Expand Down