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

Updates Redesign #281

Merged
merged 4 commits into from
Jan 22, 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
27 changes: 27 additions & 0 deletions src/DBus/SystemUpdate.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[DBus (name="io.elementary.settings_daemon.SystemUpdate")]
public interface SystemUpdate : Object {
public enum State {
UP_TO_DATE,
CHECKING,
AVAILABLE,
DOWNLOADING,
RESTART_REQUIRED
}

public struct CurrentState {
State state;
string message;
}

public struct UpdateDetails {
string[] packages;
int size;
}

public signal void state_changed ();

public abstract async CurrentState get_current_state () throws DBusError, IOError;
public abstract async UpdateDetails get_update_details () throws DBusError, IOError;
public abstract async void update () throws DBusError, IOError;
public abstract async void check_for_updates (bool force = false) throws DBusError, IOError;
}
3 changes: 0 additions & 3 deletions src/Plug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ public class About.Plug : Switchboard.Plug {

var firmware_view = new FirmwareView ();

var update_view = new UpdatesView ();

stack = new Gtk.Stack () {
vexpand = true
};
stack.add_titled (operating_system_view, OPERATING_SYSTEM, _("Operating System"));
stack.add_titled (hardware_view, HARDWARE, _("Hardware"));
stack.add_titled (firmware_view, FIRMWARE, _("Firmware"));
stack.add_titled (update_view, "updates", _("Updates"));

var stack_switcher = new Gtk.StackSwitcher () {
halign = Gtk.Align.CENTER,
Expand Down
189 changes: 165 additions & 24 deletions src/Views/OperatingSystemView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
public class About.OperatingSystemView : Gtk.Box {
private string support_url;

private Gtk.StringList updates;
private SystemUpdate? update_proxy = null;
private Gtk.Grid software_grid;
private Gtk.Button check_button;
private Gtk.Image updates_image;
private Gtk.Label updates_title;
private Gtk.Label updates_description;
private Gtk.Revealer update_button_revealer;

construct {
var style_provider = new Gtk.CssProvider ();
Expand Down Expand Up @@ -84,7 +91,6 @@ public class About.OperatingSystemView : Gtk.Box {

var title = new Gtk.Label (pretty_name) {
ellipsize = Pango.EllipsizeMode.END,
margin_bottom = 12,
selectable = true,
use_markup = true,
xalign = 0
Expand All @@ -95,40 +101,91 @@ public class About.OperatingSystemView : Gtk.Box {
selectable = true,
xalign = 0
};
kernel_version_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);
kernel_version_label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var website_url = Environment.get_os_info (GLib.OsInfoKey.HOME_URL);
if (website_url == "" || website_url == null) {
website_url = "https://elementary.io";
}

var website_label = new Gtk.LinkButton.with_label (website_url, _("Website")) {
margin_top = 12
};
var website_label = new Gtk.LinkButton.with_label (website_url, _("Website"));


var help_button = new Gtk.LinkButton.with_label (support_url, _("Get Support")) {
halign = Gtk.Align.CENTER,
hexpand = true,
margin_top = 12
hexpand = true
};

var translate_button = new Gtk.LinkButton.with_label (
"https://l10n.elementary.io/projects/",
_("Suggest Translations")
) {
margin_top = 12
};
);

var bug_button = new Gtk.Button.with_label (_("Send Feedback"));

Gtk.Button? update_button = null;
var appcenter_info = new GLib.DesktopAppInfo ("io.elementary.appcenter.desktop");
if (appcenter_info != null) {
update_button = new Gtk.Button.with_label (_("Check for Updates"));
update_button.clicked.connect (() => {
appcenter_info.launch_action ("ShowUpdates", new GLib.AppLaunchContext ());
});
}
updates = new Gtk.StringList (null);

var update_list = new Gtk.ListBox () {
vexpand = true,
selection_mode = Gtk.SelectionMode.SINGLE
};
update_list.bind_model (updates, (obj) => {
var str = ((Gtk.StringObject) obj).string;
return new Gtk.Label (str);
});

var update_scrolled = new Gtk.ScrolledWindow () {
child = update_list
};

updates_image = new Gtk.Image () {
icon_size = LARGE
};

updates_title = new Gtk.Label (null) {
hexpand = true,
margin_end = 6,
xalign = 0
};

updates_description = new Gtk.Label (null) {
xalign = 0
};
updates_description.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);
updates_description.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var update_button = new Gtk.Button.with_label (_("Download")) {
margin_end = 6,
valign = CENTER
};

update_button_revealer = new Gtk.Revealer () {
child = update_button,
overflow = VISIBLE,
transition_type = SLIDE_LEFT
};

var updates_grid = new Gtk.Grid () {
column_spacing = 6,
margin_top = 6,
margin_bottom = 6,
margin_start = 6
};
updates_grid.attach (updates_image, 0, 0, 1, 2);
updates_grid.attach (updates_title, 1, 0);
updates_grid.attach (updates_description, 1, 1);
updates_grid.attach (update_button_revealer, 2, 0, 1, 2);

var frame = new Gtk.Frame (null) {
child = updates_grid,
margin_bottom = 12,
margin_top = 12,
valign = CENTER
};
frame.add_css_class (Granite.STYLE_CLASS_VIEW);

check_button = new Gtk.Button.with_label (_("Check for Updates"));

var settings_restore_button = new Gtk.Button.with_label (_("Restore Default Settings"));

Expand All @@ -138,9 +195,7 @@ public class About.OperatingSystemView : Gtk.Box {
homogeneous = true
};
primary_button_box.append (bug_button);
if (update_button != null) {
primary_button_box.append (update_button);
}
primary_button_box.append (check_button);

var button_grid = new Gtk.Box (HORIZONTAL, 6);
button_grid.append (settings_restore_button);
Expand All @@ -149,17 +204,17 @@ public class About.OperatingSystemView : Gtk.Box {
software_grid = new Gtk.Grid () {
column_spacing = 32,
halign = Gtk.Align.CENTER,
row_spacing = 6,
valign = Gtk.Align.CENTER,
vexpand = true
};
software_grid.attach (logo_overlay, 0, 0, 1, 4);
software_grid.attach (title, 1, 0, 3);

software_grid.attach (kernel_version_label, 1, 2, 3);
software_grid.attach (website_label, 1, 3);
software_grid.attach (help_button, 2, 3);
software_grid.attach (translate_button, 3, 3);
software_grid.attach (frame, 1, 3, 3);
software_grid.attach (website_label, 1, 4);
software_grid.attach (help_button, 2, 4);
software_grid.attach (translate_button, 3, 4);

margin_top = 12;
margin_end = 12;
Expand Down Expand Up @@ -187,6 +242,27 @@ public class About.OperatingSystemView : Gtk.Box {
});

get_upstream_release.begin ();

Bus.get_proxy.begin<SystemUpdate> (SESSION, "io.elementary.settings-daemon", "/io/elementary/settings_daemon", 0, null, (obj, res) => {
try {
update_proxy = Bus.get_proxy.end (res);

update_proxy.state_changed.connect (update_state);
update_state.begin ();
} catch (Error e) {
critical ("Failed to get updates proxy");
}
});

check_button.clicked.connect (() => {
if (update_proxy != null) {
try {
update_proxy.check_for_updates.begin ();
} catch (Error e) {
warning ("Failed to check for updates: %s", e.message);
}
}
});
}

private async void get_upstream_release () {
Expand Down Expand Up @@ -222,10 +298,75 @@ public class About.OperatingSystemView : Gtk.Box {
selectable = true,
xalign = 0
};
based_off.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);
based_off.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);
software_grid.attach (based_off, 1, 1, 3);
}
}

private async void update_state () {
if (update_proxy == null) {
return;
}

SystemUpdate.CurrentState current_state;
try {
current_state = yield update_proxy.get_current_state ();
} catch (Error e) {
critical ("Failed to get current state from Updates Backend: %s", e.message);
return;
}

update_button_revealer.reveal_child = false;

switch (current_state.state) {
case UP_TO_DATE:
updates_image.icon_name = "process-completed";
updates_title.label = _("Up To Date");
updates_description.label = _("No updates available");
check_button.sensitive = true;
break;
case CHECKING:
updates_image.icon_name = "emblem-synchronized";
updates_title.label = _("Checking for Updates");
updates_description.label = current_state.message;
check_button.sensitive = false;
break;
case AVAILABLE:
updates_image.icon_name = "software-update-available";
updates_title.label = _("Updates Available");
update_button_revealer.reveal_child = true;
check_button.sensitive = true;

try {
var details = yield update_proxy.get_update_details ();
updates_description.label = ngettext (
_("%i update available").printf (details.packages.length),
_("%i updates available").printf (details.packages.length),
details.packages.length
);

updates.splice (0, 0, details.packages);
} catch (Error e) {
updates_description.label = _("Unable to determine number of updates");
warning ("Failed to get updates list from backend: %s", e.message);
}
break;
case DOWNLOADING:
updates_image.icon_name = "browser-download";
updates_title.label = _("Downloading Updates");
updates_description.label = current_state.message;
check_button.sensitive = false;
break;
case RESTART_REQUIRED:
updates_image.icon_name = "system-reboot";
updates_title.label = _("Restart Required");
updates_description.label = _("A restart is required to finish installing updates");
check_button.sensitive = false;
break;
}
}

private void launch_support_url () {
try {
AppInfo.launch_default_for_uri (support_url, null);
Expand Down
Loading
Loading