Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove OS updates #2111

Merged
merged 8 commits into from
Feb 11, 2024
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
2 changes: 1 addition & 1 deletion src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class AppCenterCore.Client : Object {
var application = Application.get_default ();
if (was_empty && updates_number != 0U) {
string title = ngettext ("Update Available", "Updates Available", updates_number);
string body = ngettext ("%u update is available for your system", "%u updates are available for your system", updates_number).printf (updates_number);
string body = ngettext ("%u app update is available", "%u app updates are available", updates_number).printf (updates_number);

var notification = new Notification (title);
notification.set_body (body);
Expand Down
15 changes: 4 additions & 11 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public class AppCenterCore.Package : Object {
X11
}

public const string OS_UPDATES_ID = "xxx-os-updates";
public const string RUNTIME_UPDATES_ID = "xxx-runtime-updates";
public const string LOCAL_ID_SUFFIX = ".appcenter-local";
public const string DEFAULT_PRICE_DOLLARS = "1";
Expand All @@ -127,7 +126,7 @@ public class AppCenterCore.Package : Object {
private bool _installed = false;
public bool installed {
get {
if (is_os_updates || is_runtime_updates) {
if (is_runtime_updates) {
return true;
}

Expand Down Expand Up @@ -207,12 +206,6 @@ public class AppCenterCore.Package : Object {
}
}

public bool is_os_updates {
get {
return component.id == OS_UPDATES_ID;
}
}

public bool is_runtime_updates {
get {
return component.id == RUNTIME_UPDATES_ID;
Expand All @@ -233,7 +226,7 @@ public class AppCenterCore.Package : Object {

public bool is_shareable {
get {
return is_native && component.get_kind () != AppStream.ComponentKind.DRIVER && !is_os_updates && !is_runtime_updates;
return is_native && component.get_kind () != AppStream.ComponentKind.DRIVER && !is_runtime_updates;
}
}

Expand Down Expand Up @@ -874,7 +867,7 @@ public class AppCenterCore.Package : Object {
}

private string convert_version (string version) {
if (is_os_updates || is_runtime_updates) {
if (is_runtime_updates) {
return version;
}

Expand Down Expand Up @@ -965,7 +958,7 @@ public class AppCenterCore.Package : Object {
}

private void populate_backend_details_sync () {
if (is_os_updates || is_runtime_updates || is_local) {
if (is_runtime_updates || is_local) {
backend_details = new PackageDetails ();
return;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Core/PackageKitBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ public class AppCenterCore.PackageKitBackend : Backend, Object {

private void updates_changed_callback () {
if (!working) {
UpdateManager.get_default ().update_restart_state ();

var time_since_last_action = (new DateTime.now_local ()).difference (last_action) / GLib.TimeSpan.MILLISECOND;
if (time_since_last_action >= PACKAGEKIT_ACTIVITY_TIMEOUT_MS) {
info ("packages possibly changed by external program, refreshing cache");
Expand Down
119 changes: 0 additions & 119 deletions src/Core/UpdateManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,11 @@
*/

public class AppCenterCore.UpdateManager : Object {
public bool restart_required { public get; private set; default = false; }
public Package os_updates { public get; private set; }
public Package runtime_updates { public get; private set; }
public int unpaid_apps_number { get; private set; default = 0; }
public uint64 updates_size { get; private set; default = 0ULL; }
public bool has_flatpak_updates { get; private set; default = false; }

private const string RESTART_REQUIRED_FILE = "/var/run/reboot-required";

private File restart_file;

construct {
restart_file = File.new_for_path (RESTART_REQUIRED_FILE);

var os_icon = new AppStream.Icon ();
os_icon.set_name ("distributor-logo");
os_icon.set_kind (AppStream.IconKind.STOCK);

var os_updates_component = new AppStream.Component ();
os_updates_component.id = AppCenterCore.Package.OS_UPDATES_ID;
os_updates_component.name = _("Operating System Updates");
os_updates_component.summary = _("Updates to system components");
os_updates_component.add_icon (os_icon);

os_updates = new AppCenterCore.Package (BackendAggregator.get_default (), os_updates_component);

var runtime_icon = new AppStream.Icon ();
runtime_icon.set_name ("application-vnd.flatpak");
runtime_icon.set_kind (AppStream.IconKind.STOCK);
Expand All @@ -60,7 +39,6 @@ public class AppCenterCore.UpdateManager : Object {
public async uint get_updates (Cancellable? cancellable = null) {
var apps_with_updates = new Gee.TreeSet<Package> ();
uint count = 0;
has_flatpak_updates = false;
unpaid_apps_number = 0;
updates_size = 0ULL;

Expand All @@ -71,41 +49,6 @@ 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 {
pk_updates = yield client.get_updates (cancellable);
} catch (Error e) {
warning ("Unable to get updates from PackageKit backend: %s", e.message);
return 0;
}

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

package_array.foreach ((pk_package) => {
var pkg_name = pk_package.get_name ();
debug ("Added %s to OS updates", pkg_name);
os_count++;
unowned string pkg_summary = pk_package.get_summary ();
unowned string pkg_version = pk_package.get_version ();
os_desc += Markup.printf_escaped (
" • %s\n\t%s\n\t%s\n",
pkg_name,
pkg_summary,
_("Version: %s").printf (pkg_version)
);
});
#endif

os_updates.component.set_pkgnames ({});
os_updates.change_information.clear_update_info ();

uint runtime_count = 0;
string runtime_desc = "";

Expand All @@ -125,7 +68,6 @@ public class AppCenterCore.UpdateManager : Object {

count++;
updates_size += appcenter_package.change_information.size;
has_flatpak_updates = true;

appcenter_package.change_information.updatable_packages.@set (fp_client, flatpak_update);
appcenter_package.update_state ();
Expand All @@ -150,7 +92,6 @@ public class AppCenterCore.UpdateManager : Object {
}

runtime_count++;
has_flatpak_updates = true;

runtime_desc += Markup.printf_escaped (
" • %s\n\t%s\n",
Expand All @@ -171,18 +112,6 @@ public class AppCenterCore.UpdateManager : Object {
}
}

if (os_count == 0) {
debug ("No OS updates found");
var latest_version = _("No components with updates");
os_updates.latest_version = latest_version;
os_updates.description = GLib.Markup.printf_escaped ("%s\n", latest_version);
} else {
debug ("%u OS updates found", os_count);
var latest_version = ngettext ("%u component with updates", "%u components with updates", os_count).printf (os_count);
os_updates.latest_version = latest_version;
os_updates.description = "%s\n%s\n".printf (GLib.Markup.printf_escaped (_("%s:"), latest_version), os_desc);
}

if (runtime_count == 0) {
debug ("No runtime updates found");
var latest_version = _("No runtimes with updates");
Expand All @@ -196,63 +125,15 @@ public class AppCenterCore.UpdateManager : Object {
}

debug ("%u app updates found", count);
if (os_count > 0) {
count += 1;
}

if (runtime_count > 0) {
count += 1;
}

#if PACKAGEKIT_BACKEND
pk_updates.get_details_array ().foreach ((pk_detail) => {
var pk_package = new Pk.Package ();
try {
pk_package.set_id (pk_detail.get_package_id ());
var pkg_name = pk_package.get_name ();

var pkgnames = os_updates.component.pkgnames;
pkgnames += pkg_name;
os_updates.component.pkgnames = pkgnames;

os_updates.change_information.updatable_packages.@set (client, pk_package.get_id ());
os_updates.change_information.size += pk_detail.size;
} catch (Error e) {
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) {
string title = _("Restart Required");
string body = _("Please restart your system to finalize updates");
var notification = new Notification (title);
notification.set_body (body);
notification.set_icon (new ThemedIcon ("system-reboot"));
notification.set_priority (NotificationPriority.URGENT);
notification.set_default_action ("app.open-application");
Application.get_default ().send_notification ("restart", notification);
}

restart_required = true;
} else if (restart_required) {
restart_required = false;
}
}

private static GLib.Once<UpdateManager> instance;
public static unowned UpdateManager get_default () {
return instance.once (() => { return new UpdateManager (); });
Expand Down
4 changes: 2 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
child = search_entry
};

var automatic_updates_button = new Granite.SwitchModelButton (_("Automatic App Updates")) {
description = _("System updates and unpaid apps will not update automatically")
var automatic_updates_button = new Granite.SwitchModelButton (_("Automatically Update Free & Purchased Apps")) {
description = _("Apps being tried for free will not update automatically")
};

var refresh_accellabel = new Granite.AccelLabel.from_action_name (
Expand Down
10 changes: 5 additions & 5 deletions src/Views/AppInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
} else {
app_icon.gicon = package.get_icon (app_icon.pixel_size, scale_factor);

if (package.is_os_updates || package.is_runtime_updates) {
if (package.is_runtime_updates) {
badge_image.icon_name = "system-software-update";
app_icon_overlay.add_overlay (badge_image);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
maximum_size = MAX_WIDTH
};

if (!package.is_os_updates && !package.is_runtime_updates) {
if (!package.is_runtime_updates) {
#if CURATED
if (!package.is_native) {
var uncurated = new ContentType (
Expand Down Expand Up @@ -852,10 +852,10 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
uninstall_button_revealer.reveal_child = false;
break;
case AppCenterCore.Package.State.INSTALLED:
uninstall_button_revealer.reveal_child = !package.is_os_updates && !package.is_runtime_updates && !package.is_compulsory;
uninstall_button_revealer.reveal_child = !package.is_runtime_updates && !package.is_compulsory;
break;
case AppCenterCore.Package.State.UPDATE_AVAILABLE:
uninstall_button_revealer.reveal_child = !package.is_os_updates && !package.is_runtime_updates && !package.is_compulsory;
uninstall_button_revealer.reveal_child = !package.is_runtime_updates && !package.is_compulsory;
break;
default:
break;
Expand Down Expand Up @@ -884,7 +884,7 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
}

var size = yield package.get_download_size_including_deps ();
size_label.update (size, package.is_flatpak);
size_label.update (size);

ContentType? runtime_warning = null;
switch (package.runtime_status) {
Expand Down
25 changes: 7 additions & 18 deletions src/Views/AppListUpdateView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -247,31 +247,22 @@ namespace AppCenter.Views {
client.updates_number
).printf (client.updates_number);

size_label.update (update_manager.updates_size, update_manager.has_flatpak_updates);
size_label.update (update_manager.updates_size);
} else {
header_revealer.reveal_child = false;

if (!update_manager.restart_required) {
updated_revealer.reveal_child = true;
updated_label.label = _("Everything is up to date. Last checked %s.").printf (
Granite.DateTime.get_relative_datetime (
new DateTime.from_unix_local (AppCenter.App.settings.get_int64 ("last-refresh-time"))
)
);
}
updated_revealer.reveal_child = true;
updated_label.label = _("Everything is up to date. Last checked %s.").printf (
Granite.DateTime.get_relative_datetime (
new DateTime.from_unix_local (AppCenter.App.settings.get_int64 ("last-refresh-time"))
)
);
}

var installed_apps = yield client.get_installed_applications (refresh_cancellable);

if (!refresh_cancellable.is_cancelled ()) {
clear ();

var os_updates = AppCenterCore.UpdateManager.get_default ().os_updates;
var os_updates_size = yield os_updates.get_download_size_including_deps ();
if (os_updates_size > 0) {
updates_liststore.insert_sorted (os_updates, compare_package_func);
}

var runtime_updates = AppCenterCore.UpdateManager.get_default ().runtime_updates;
var runtime_updates_size = yield runtime_updates.get_download_size_including_deps ();
if (runtime_updates_size > 0) {
Expand Down Expand Up @@ -316,7 +307,6 @@ namespace AppCenter.Views {
string a_package_name = "";
if (package1 != null) {
a_is_driver = package1.kind == AppStream.ComponentKind.DRIVER;
a_is_os = package1.is_os_updates;
a_is_runtime = package1.is_runtime_updates;
a_is_updating = package1.is_updating;
a_package_name = package1.get_name ();
Expand All @@ -329,7 +319,6 @@ namespace AppCenter.Views {
string b_package_name = "";
if (package2 != null) {
b_is_driver = package2.kind == AppStream.ComponentKind.DRIVER;
b_is_os = package2.is_os_updates;
b_is_runtime = package2.is_runtime_updates;
b_is_updating = package2.is_updating;
b_package_name = package2.get_name ();
Expand Down
8 changes: 2 additions & 6 deletions src/Widgets/AppContainers/AbstractAppContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public abstract class AppCenter.AbstractAppContainer : Gtk.Box {
}

protected void update_action () {
if (package == null || package.component == null || !package.is_native || package.is_os_updates || package.is_runtime_updates) {
if (package == null || package.component == null || !package.is_native || package.is_runtime_updates) {
action_button.can_purchase = false;
} else {
var can_purchase = package.get_payments_key () != null;
Expand Down Expand Up @@ -191,7 +191,7 @@ public abstract class AppCenter.AbstractAppContainer : Gtk.Box {
action_button.amount = 0;
}

action_button_revealer.reveal_child = !(package.is_os_updates || package.is_runtime_updates);
action_button_revealer.reveal_child = !package.is_runtime_updates;
open_button_revealer.reveal_child = false;

break;
Expand All @@ -204,10 +204,6 @@ public abstract class AppCenter.AbstractAppContainer : Gtk.Box {
case AppCenterCore.Package.State.UPDATE_AVAILABLE:
action_button.free_string = _("Update");

if (package.is_os_updates) {
action_button.free_string = _("Download");
}

if (!package.should_pay) {
action_button.amount = 0;
}
Expand Down
Loading