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

Automatically install curated Flatpak updates #1793

Merged
merged 30 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
95da976
Client: Automatically install Flatpak updates if cache is old
meisenzahl Dec 12, 2021
6015e1b
Add setting to automatically install Flatpak updates
meisenzahl Dec 12, 2021
de7415e
MainWindow: Add menu with setting to toggle if Flatpak updates should…
meisenzahl Dec 12, 2021
1cb614e
Client: Fix automatic installtion of Flatpak packages
meisenzahl Dec 12, 2021
c695112
Settings: Disable automatically-install-flatpak-updates by default
meisenzahl Dec 13, 2021
cabffd7
Client: Only automatically install native Flatpak apps
meisenzahl Dec 13, 2021
a285d32
Update wording
meisenzahl Dec 13, 2021
c9d9f16
MainWindow: Use even margins
meisenzahl Dec 13, 2021
a5830d7
MainWindow: Use LARGE_TOOLBAR
meisenzahl Dec 13, 2021
6909fba
CSS: Use 3px as rem
meisenzahl Dec 13, 2021
6204e5c
CSS: Add comment about calculation
meisenzahl Dec 13, 2021
34c7a9d
UpdateManager: Filter automatically installed Flatpak apps
meisenzahl Dec 13, 2021
1c42d4b
UpdateManager: Don't count automatic updates
meisenzahl Dec 13, 2021
3b6cb36
Merge branch 'master' into automatically-install-flatpak-updates
meisenzahl Dec 17, 2021
8cb6f7c
MainWindow: Update cache and install updates when setting is turned on
meisenzahl Dec 17, 2021
2d9a199
MainWindow: Cancel updates when setting is turned off
meisenzahl Dec 17, 2021
9c9ee9c
Merge branch 'master' into automatically-install-flatpak-updates
meisenzahl Dec 19, 2021
a77c534
Merge branch 'master' into automatically-install-flatpak-updates
meisenzahl Dec 29, 2021
815594b
Merge branch 'master' into automatically-install-flatpak-updates
meisenzahl Jan 2, 2022
bfecf2f
Merge branch 'master' into automatically-install-flatpak-updates
cassidyjames Jan 3, 2022
9bb46f1
Merge branch 'master' into automatically-install-flatpak-updates
cassidyjames Jan 4, 2022
6571359
Apply suggestions from code review
meisenzahl Jan 6, 2022
460638e
Merge branch 'master' into automatically-install-flatpak-updates
meisenzahl Jan 6, 2022
14835d4
Merge branch 'master' into automatically-install-flatpak-updates
cassidyjames Jan 6, 2022
a8cbb2e
Merge branch 'master' into automatically-install-flatpak-updates
cassidyjames Jan 6, 2022
7905c52
Update io.elementary.appcenter.appdata.xml.in
cassidyjames Jan 6, 2022
cf48758
MainWindow: Update auto update description
cassidyjames Jan 6, 2022
6674929
Client: Exclude `should_pay` apps
cassidyjames Jan 6, 2022
ffa039b
Merge branch 'master' into automatically-install-flatpak-updates
cassidyjames Jan 6, 2022
0d066fb
Merge branch 'master' into automatically-install-flatpak-updates
cassidyjames Jan 6, 2022
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
5 changes: 5 additions & 0 deletions data/io.elementary.appcenter.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
<summary>Unix UTC time of last cache refresh</summary>
<description>Used to determine when AppCenter last refreshed its caches and checked for package updates</description>
</key>
<key type="b" name="automatically-install-flatpak-updates">
<default>false</default>
<summary>Automatically install Flatpak updates</summary>
<description>Whether to automatically install updates to curated Flatpaks</description>
</key>
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
</schema>
</schemalist>
4 changes: 2 additions & 2 deletions data/styles/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
*/

.titlebar {
padding-bottom: 0;
padding-top: 0;
padding-bottom: 0.333rem; /* 3px at 9pt font */
padding-top: 0.333rem; /* 3px at 9pt font */
}
27 changes: 22 additions & 5 deletions src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public class AppCenterCore.Client : Object {

/* One cache update a day, keeps the doctor away! */
var seconds_since_last_refresh = new DateTime.now_utc ().difference (last_cache_update) / GLib.TimeSpan.SECOND;
if (force || seconds_since_last_refresh >= SECONDS_BETWEEN_REFRESHES) {
bool last_cache_update_is_old = seconds_since_last_refresh >= SECONDS_BETWEEN_REFRESHES;
if (force || last_cache_update_is_old) {
if (nm.get_network_available ()) {
debug ("New refresh task");

Expand All @@ -156,10 +157,6 @@ public class AppCenterCore.Client : Object {
debug ("Too soon to refresh and not forced");
}

if (nm.get_network_available ()) {
refresh_updates.begin ();
}

var next_refresh = SECONDS_BETWEEN_REFRESHES - (uint)seconds_since_last_refresh;
debug ("Setting a timeout for a refresh in %f minutes", next_refresh / 60.0f);
update_cache_timeout_id = GLib.Timeout.add_seconds (next_refresh, () => {
Expand All @@ -168,6 +165,26 @@ public class AppCenterCore.Client : Object {

return GLib.Source.REMOVE;
});

if (nm.get_network_available ()) {
if (last_cache_update_is_old && AppCenter.App.settings.get_boolean ("automatically-install-flatpak-updates")) {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
yield refresh_updates ();
debug ("Update Flatpaks");
var installed_apps = yield FlatpakBackend.get_default ().get_installed_applications (cancellable);
foreach (var app in installed_apps) {
if (app.is_native && app.update_available) {
cassidyjames marked this conversation as resolved.
Show resolved Hide resolved
debug ("Update: %s", app.get_name ());
try {
yield app.update (false);
} catch (Error e) {
warning ("Updating %s failed: %s", app.get_name (), e.message);
}
}
}
}

refresh_updates.begin ();
}
}

public Package? get_package_for_component_id (string id) {
Expand Down
12 changes: 10 additions & 2 deletions src/Core/UpdateManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class AppCenterCore.UpdateManager : Object {
if (appcenter_package != null) {
debug ("Added %s to app updates", pkg_name);
apps_with_updates.add (appcenter_package);
count++;
appcenter_package.latest_version = pk_package.get_version ();
} else {
debug ("Added %s to OS updates", pkg_name);
Expand Down Expand Up @@ -100,6 +101,11 @@ public class AppCenterCore.UpdateManager : Object {
if (appcenter_package != null) {
debug ("Added %s to app updates", flatpak_update);
apps_with_updates.add (appcenter_package);

if (!(AppCenter.App.settings.get_boolean ("automatically-install-flatpak-updates") && appcenter_package.is_native)) {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
count++;
}

appcenter_package.change_information.updatable_packages.@set (fp_client, flatpak_update);
appcenter_package.update_state ();
try {
Expand All @@ -122,7 +128,10 @@ public class AppCenterCore.UpdateManager : Object {
continue;
}

os_count++;
if (!AppCenter.App.settings.get_boolean ("automatically-install-flatpak-updates")) {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
os_count++;
}

os_desc += Markup.printf_escaped (
" • %s\n\t%s\n",
@ref.get_name (),
Expand Down Expand Up @@ -153,7 +162,6 @@ public class AppCenterCore.UpdateManager : Object {
os_updates.description = "%s\n%s\n".printf (GLib.Markup.printf_escaped (_("%s:"), latest_version), os_desc);
}

count = apps_with_updates.size;
debug ("%u app updates found", count);
if (os_count > 0) {
count += 1;
Expand Down
43 changes: 43 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,48 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {

spinner = new Gtk.Spinner ();

var automatically_install_flatpak_updates_button = new Granite.SwitchModelButton (_("Automatic Updates")) {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
description = _("Automatically install updates to curated apps")
cassidyjames marked this conversation as resolved.
Show resolved Hide resolved
};

automatically_install_flatpak_updates_button.notify["active"].connect (() => {
if (automatically_install_flatpak_updates_button.active) {
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
AppCenterCore.Client.get_default ().update_cache.begin (true);
} else {
AppCenterCore.Client.get_default ().cancel_updates (true);
}
});

var menu_popover_grid = new Gtk.Grid () {
column_spacing = 6,
margin_bottom = 6,
margin_top = 6,
orientation = Gtk.Orientation.VERTICAL,
row_spacing = 6
};

menu_popover_grid.add (automatically_install_flatpak_updates_button);
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved

menu_popover_grid.show_all ();

var menu_popover = new Gtk.Popover (null);
menu_popover.add (menu_popover_grid);

var menu_button = new Gtk.MenuButton () {
can_focus = false,
image = new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR),
popover = menu_popover,
tooltip_text = _("Settings"),
valign = Gtk.Align.CENTER
};


var headerbar = new Hdy.HeaderBar () {
show_close_button = true
};
headerbar.set_custom_title (custom_title_stack);
headerbar.pack_start (return_button);
headerbar.pack_end (menu_button);
headerbar.pack_end (search_entry);
headerbar.pack_end (spinner);

Expand Down Expand Up @@ -252,6 +289,12 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow {
int window_width, window_height;
App.settings.get ("window-position", "(ii)", out window_x, out window_y);
App.settings.get ("window-size", "(ii)", out window_width, out window_height);
App.settings.bind (
"automatically-install-flatpak-updates",
automatically_install_flatpak_updates_button,
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
"active",
SettingsBindFlags.DEFAULT
);

if (window_x != -1 || window_y != -1) {
move (window_x, window_y);
Expand Down