Skip to content
Merged
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
65 changes: 23 additions & 42 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -470,36 +470,20 @@ public class AppCenterCore.Package : Object {
return yield perform_operation (State.UPDATING, State.INSTALLED, State.UPDATE_AVAILABLE);
}

public async bool install () {
public async bool install () throws Error {
if (state != State.NOT_INSTALLED) {
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) {
flatpak_backend.operation_finished (this, State.INSTALLING, null);
}

return success;
} catch (Error e) {
flatpak_backend.operation_finished (this, State.INSTALLING, e);
return false;
}
return yield perform_operation (State.INSTALLING, State.INSTALLED, State.NOT_INSTALLED);
}

public async bool uninstall () throws Error {
if (state == State.INSTALLED || state == State.UPDATE_AVAILABLE) {
try {
return yield perform_operation (State.REMOVING, State.NOT_INSTALLED, state);
} catch (Error e) {
throw e;
}
if (state != INSTALLED && state != State.UPDATE_AVAILABLE) {
throw new PackageUninstallError.APP_STATE_NOT_INSTALLED (_("Application state not set as installed in AppCenter for package: %s").printf (name));
}

throw new PackageUninstallError.APP_STATE_NOT_INSTALLED (_("Application state not set as installed in AppCenter for package: %s").printf (name));
return yield perform_operation (State.REMOVING, State.NOT_INSTALLED, state);
}

public void launch () throws Error {
Expand All @@ -516,24 +500,33 @@ public class AppCenterCore.Package : Object {

private async bool perform_operation (State performing, State after_success, State after_fail) throws GLib.Error {
bool success = false;
prepare_package_operation (performing);

change_information.start ();
state = performing;

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

try {
success = yield perform_package_operation ();
flatpak_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);
throw e;
} finally {
clean_up_package_operation (success, after_success, after_fail);
}
change_information.complete ();

return success;
}
if (success) {
state = after_success;
} else {
state = after_fail;
}

private void prepare_package_operation (State initial_state) {
change_information.start ();
state = initial_state;
flatpak_backend.notify_package_changed (this);
}

FlatpakBackend.get_default ().notify_package_changed (this);
return success;
}

private async bool perform_package_operation () throws GLib.Error {
Expand Down Expand Up @@ -563,18 +556,6 @@ public class AppCenterCore.Package : Object {
}
}

private void clean_up_package_operation (bool success, State success_state, State fail_state) {
change_information.complete ();

if (success) {
state = success_state;
} else {
state = fail_state;
}

FlatpakBackend.get_default ().notify_package_changed (this);
}

public uint cached_search_score = 0;
public uint matches_search (string[] queries) {
// TODO: We don't use AppStream.Component.search_matches_all because it has some broken vapi
Expand Down