Skip to content

Commit

Permalink
Add meson options to disable backends (#1994)
Browse files Browse the repository at this point in the history
* meson: Add flags for backends

* Use flags to enable PackageKit and Ubuntu  Driver functions

* BackendInterface: Remove unused code

* MainWindow: Update label early

* CI: Add job to build AppCenter Flatpak-only

* CI: Fix add job to build AppCenter Flatpak-only

* Update src/Core/Package.vala

* Homepage: Only load placeholder banner if packagekit is enabled

---------

Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
  • Loading branch information
meisenzahl and zeebok committed May 18, 2023
1 parent dc35f3d commit d49be61
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 52 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
meson configure -Dcurated=false -Dpayments=false -Dsharing=false -Dname=Pop\!_Shop build
ninja -C build install
- name: Build (Flatpak-only)
env:
DESTDIR: out
run: |
meson configure -Dpackagekit_backend=false -Dubuntu_drivers_backend=false build
ninja -C build install
lint:

runs-on: ubuntu-22.04
Expand Down
6 changes: 4 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ gee = dependency ('gee-0.8')
gtk = dependency ('gtk+-3.0', version: '>=3.10')
granite = dependency ('granite', version: '>=6.0.0')
handy = dependency('libhandy-1', version: '>=1.4.0')
packagekit = dependency ('packagekit-glib2')
appstream = dependency ('appstream', version: '>=0.15.2')
libsoup = dependency ('libsoup-2.4')
json = dependency ('json-glib-1.0')
Expand All @@ -41,7 +40,6 @@ dependencies = [
gtk,
granite,
handy,
packagekit,
appstream,
libsoup,
json,
Expand All @@ -51,6 +49,10 @@ dependencies = [
posix
]

if get_option('packagekit_backend')
dependencies += [dependency ('packagekit-glib2')]
endif

config_dir = join_paths(get_option('sysconfdir'), meson.project_name())
conf_data = configuration_data()
conf_data.set('PROJECT_NAME', meson.project_name())
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ option('payments', type : 'boolean', value : true, description : 'Enable payment
option('sharing', type : 'boolean', value : true, description : 'Display sharing features, i.e. copyable URLs to appcenter.elementary.io')
option('hide_upstream_distro_apps', type : 'boolean', value : true, description : 'Used for hiding Ubuntu repo apps on elementary OS')
option('runtime_name', type : 'string', value : 'io.elementary.Platform', description : 'The name of the distributor runtime')
option('packagekit_backend', type : 'boolean', value : true, description : 'Use PackageKit as a backend')
option('ubuntu_drivers_backend', type : 'boolean', value : true, description : 'Use Ubuntu Drivers as a backend (requires packagekit_backend)')
13 changes: 12 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ public class AppCenter.App : Gtk.Application {
}

public override void activate () {
#if PACKAGEKIT_BACKEND
if (fake_update_packages != null) {
AppCenterCore.PackageKitBackend.get_default ().fake_packages = fake_update_packages;
}
#endif

var client = AppCenterCore.Client.get_default ();

Expand All @@ -221,6 +223,7 @@ public class AppCenter.App : Gtk.Application {
return;
}

#if PACKAGEKIT_BACKEND
if (local_path != null) {
var file = File.new_for_commandline_arg (local_path);

Expand All @@ -230,6 +233,7 @@ public class AppCenter.App : Gtk.Application {
warning ("Failed to load local AppStream XML file: %s", e.message);
}
}
#endif

if (active_window == null) {
// Force a Flatpak cache refresh when the window is created, so we get new apps
Expand Down Expand Up @@ -326,10 +330,17 @@ public class AppCenter.App : Gtk.Application {
}
} else {
// Check if permission was denied or the operation was cancelled
if (error.matches (IOError.quark (), 19) || error.matches (Pk.ClientError.quark (), 303)) {
if (error.matches (IOError.quark (), 19)) {
break;
}

#if PACKAGEKIT_BACKEND
// Check if permission was denied or the operation was cancelled
if (error.matches (Pk.ClientError.quark (), 303)) {
break;
}
#endif

var dialog = new InstallFailDialog (package, (owned) error.message);
dialog.present ();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Core/BackendAggregator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public class AppCenterCore.BackendAggregator : Backend, Object {

construct {
backends = new Gee.ArrayList<unowned Backend> ();
#if PACKAGEKIT_BACKEND
backends.add (PackageKitBackend.get_default ());
#endif
#if UBUNTU_DRIVERS_BACKEND
backends.add (UbuntuDriversBackend.get_default ());
#endif
backends.add (FlatpakBackend.get_default ());

unowned Gtk.Application app = (Gtk.Application) GLib.Application.get_default ();
Expand Down
5 changes: 0 additions & 5 deletions src/Core/BackendInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
* Authored by: David Hewitt <davidmhewitt@gmail.com>
*/

public enum BackendType {
PACKAGEKIT,
UBUNTU_DRIVERS
}

public interface AppCenterCore.Backend : Object {
public abstract Job.Type job_type { get; protected set; }
public abstract bool working { public get; protected set; }
Expand Down
26 changes: 17 additions & 9 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -348,24 +348,30 @@ public class AppCenterCore.Package : Object {
public string origin_description {
owned get {
unowned string origin = component.get_origin ();
if (backend is PackageKitBackend) {
if (backend is FlatpakBackend) {
var fp_package = this as FlatpakPackage;
if (fp_package == null) {
return origin;
}

return fp_package.remote_title;
}
#if PACKAGEKIT_BACKEND
else if (backend is PackageKitBackend) {
if (origin == APPCENTER_PACKAGE_ORIGIN) {
return _("AppCenter");
} else if (origin == ELEMENTARY_STABLE_PACKAGE_ORIGIN) {
return _("elementary Updates");
} else if (origin.has_prefix ("ubuntu-")) {
return _("Ubuntu (non-curated)");
}
} else if (backend is FlatpakBackend) {
var fp_package = this as FlatpakPackage;
if (fp_package == null) {
return origin;
}

return fp_package.remote_title;
} else if (backend is UbuntuDriversBackend) {
}
#endif
#if UBUNTU_DRIVERS_BACKEND
else if (backend is UbuntuDriversBackend) {
return _("Ubuntu Drivers");
}
#endif

return _("Unknown Origin (non-curated)");
}
Expand Down Expand Up @@ -454,11 +460,13 @@ public class AppCenterCore.Package : Object {
_author_title = null;
backend_details = null;

#if PACKAGEKIT_BACKEND
// The version on a PackageKit package comes from the package not AppStream, so only reset the version
// on other backends
if (!(backend is PackageKitBackend)) {
_latest_version = null;
}
#endif

this.component = component;
}
Expand Down
15 changes: 12 additions & 3 deletions src/Core/UpdateManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class AppCenterCore.UpdateManager : Object {
installed_package.update_state ();
}


uint os_count = 0;
string os_desc = "";

#if PACKAGEKIT_BACKEND
Pk.Results pk_updates;
unowned PackageKitBackend client = PackageKitBackend.get_default ();
try {
Expand All @@ -80,9 +85,6 @@ public class AppCenterCore.UpdateManager : Object {
return 0;
}

uint os_count = 0;
string os_desc = "";

var package_array = pk_updates.get_package_array ();
debug ("PackageKit backend reports %d updates", package_array.length);

Expand All @@ -99,6 +101,7 @@ public class AppCenterCore.UpdateManager : Object {
_("Version: %s").printf (pkg_version)
);
});
#endif

os_updates.component.set_pkgnames ({});
os_updates.change_information.clear_update_info ();
Expand Down Expand Up @@ -207,6 +210,7 @@ public class AppCenterCore.UpdateManager : Object {
count += 1;
}

#if PACKAGEKIT_BACKEND
pk_updates.get_details_array ().foreach ((pk_detail) => {
var pk_package = new Pk.Package ();
try {
Expand All @@ -223,14 +227,19 @@ public class AppCenterCore.UpdateManager : Object {
critical (e.message);
}
});
#endif

os_updates.update_state ();
runtime_updates.update_state ();
return count;
}

public void update_restart_state () {
#if PACKAGEKIT_BACKEND
var should_restart = restart_file.query_exists () || PackageKitBackend.get_default ().is_restart_required ();
#else
var should_restart = restart_file.query_exists ();
#endif

if (should_restart) {
if (!restart_required) {
Expand Down
64 changes: 35 additions & 29 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,7 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
aggregator.bind_property ("working", overlaybar, "active", GLib.BindingFlags.SYNC_CREATE);

aggregator.notify ["job-type"].connect (() => {
switch (aggregator.job_type) {
case GET_DETAILS_FOR_PACKAGE_IDS:
case GET_PACKAGE_DEPENDENCIES:
case GET_PACKAGE_DETAILS:
case IS_PACKAGE_INSTALLED:
overlaybar.label = _("Getting app information…");
break;
case GET_DOWNLOAD_SIZE:
overlaybar.label = _("Getting download size…");
break;
case GET_PREPARED_PACKAGES:
case GET_INSTALLED_PACKAGES:
case GET_UPDATES:
case REFRESH_CACHE:
overlaybar.label = _("Checking for updates…");
break;
case INSTALL_PACKAGE:
overlaybar.label = _("Installing…");
break;
case UPDATE_PACKAGE:
overlaybar.label = _("Installing updates…");
break;
case REMOVE_PACKAGE:
overlaybar.label = _("Uninstalling…");
break;
case REPAIR:
overlaybar.label = _("Repairing…");
break;
}
update_overlaybar_label (aggregator.job_type);
});

notify["working"].connect (() => {
Expand All @@ -123,6 +95,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
return GLib.Source.REMOVE;
});
});

update_overlaybar_label (aggregator.job_type);
}

construct {
Expand Down Expand Up @@ -651,4 +625,36 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
set_return_name (category.name);
});
}

private void update_overlaybar_label (AppCenterCore.Job.Type job_type) {
switch (job_type) {
case GET_DETAILS_FOR_PACKAGE_IDS:
case GET_PACKAGE_DEPENDENCIES:
case GET_PACKAGE_DETAILS:
case IS_PACKAGE_INSTALLED:
overlaybar.label = _("Getting app information…");
break;
case GET_DOWNLOAD_SIZE:
overlaybar.label = _("Getting download size…");
break;
case GET_PREPARED_PACKAGES:
case GET_INSTALLED_PACKAGES:
case GET_UPDATES:
case REFRESH_CACHE:
overlaybar.label = _("Checking for updates…");
break;
case INSTALL_PACKAGE:
overlaybar.label = _("Installing…");
break;
case UPDATE_PACKAGE:
overlaybar.label = _("Installing updates…");
break;
case REMOVE_PACKAGE:
overlaybar.label = _("Uninstalling…");
break;
case REPAIR:
overlaybar.label = _("Repairing…");
break;
}
}
}
2 changes: 2 additions & 0 deletions src/Services/DBusServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ public class DBusServer : Object {
try {
package.uninstall.end (res);
} catch (Error e) {
#if PACKAGEKIT_BACKEND
// Disable error dialog for if user clicks cancel. Reason: Failed to obtain authentication
// Pk ErrorEnums are mapped to the error code at an offset of 0xFF (see packagekit-glib2/pk-client.h)
if (!(e is Pk.ClientError) || e.code != Pk.ErrorEnum.NOT_AUTHORIZED + 0xFF) {
new UninstallFailDialog (package, (owned) e.message).present ();
}
#endif
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace Utils {
return (uint) (now - mtime);
}

#if PACKAGEKIT_BACKEND
public static unowned string pk_status_to_string (Pk.Status status) {
switch (status) {
case Pk.Status.SETUP:
Expand Down Expand Up @@ -132,6 +133,7 @@ namespace Utils {
return _("Unknown state");
}
}
#endif

public static string unescape_markup (string escaped_text) {
return escaped_text.replace ("&amp;", "&")
Expand Down
2 changes: 2 additions & 0 deletions src/Views/AppInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,13 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
try {
package.uninstall.end (res);
} catch (Error e) {
#if PACKAGEKIT_BACKEND
// Disable error dialog for if user clicks cancel. Reason: Failed to obtain authentication
// Pk ErrorEnums are mapped to the error code at an offset of 0xFF (see packagekit-glib2/pk-client.h)
if (!(e is Pk.ClientError) || e.code != Pk.ErrorEnum.NOT_AUTHORIZED + 0xFF) {
new UninstallFailDialog (package, (owned) e.message).present ();
}
#endif
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/Views/Homepage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,13 @@ public class AppCenter.Homepage : Gtk.Box {
show_package (local_package);
});
} else {
#if PACKAGEKIT_BACKEND
appcenter_banner = new Widgets.Banner (
AppCenterCore.PackageKitBackend.get_default ().lookup_package_by_id ("appcenter")
);
banner_carousel.add (appcenter_banner);
#endif

banner_carousel.page_changed.connect (page_changed_handler );
}

Expand Down

0 comments on commit d49be61

Please sign in to comment.