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 7 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>
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
35 changes: 35 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,40 @@ 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
};

var menu_popover_grid = new Gtk.Grid () {
column_spacing = 6,
margin_bottom = 6,
margin_top = 12,
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
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.SMALL_TOOLBAR),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the large toolbar size, but I know that's gonna require some styling fixes as well since we do weird things with margins/padding in CSS here (I think due to the updates badge overlay). I may have started addressing it in #1230 but I also know that PR is pretty outdated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions on how we are going to implement this at this point?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meisenzahl actually in testing, using LARGE_TOOLBAR looks really close; we might just have to tweak the styling here to match other apps; it looks like 3px matches Files, at least, but I'm also not sure how we would get it to scale with the text-size like our rem() sass function in the stylesheet… 🤔 That might be over-thinking it, though, and 3px here might be fine.

.titlebar {
padding-bottom: 0;
padding-top: 0;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using LARGE_TOOLBAR and 0.188rem for padding:

Bildschirmfoto von 2021-12-13 20 35 43

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 +281,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