A Sibling projects menu item, shown when any are installed, says which have a newer version (from `sibling check --porcelain`, run with each update check). It opens a dialog listing each sibling's version and state, with buttons to run `sibling update` for one or all of them in a terminal. A newer sibling also counts as an available update for the Update pill, the header and the top bar dot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ export const STATE = GLib.build_filenamev([HOME, '.local', 'state', 'coredesktop
|
||||
export const LOGS = GLib.build_filenamev([STATE, 'logs']);
|
||||
export const REBOOT_NEEDED = GLib.build_filenamev([STATE, 'reboot-needed']);
|
||||
export const PACMAN_UPDATE_LOG = GLib.build_filenamev([STATE, 'pacman-update.log']);
|
||||
export const SIBLINGS = GLib.build_filenamev([HOME, '.local', 'share', 'siblings']);
|
||||
export const STATUS_DIR = GLib.build_filenamev([GLib.get_user_runtime_dir(), 'coredesktop-extension']);
|
||||
|
||||
// Terminals and how each runs a command, in the order CoreDesktop's
|
||||
@@ -83,6 +84,46 @@ export async function checkForUpdate(cancellable) {
|
||||
return {state: 'unknown'};
|
||||
}
|
||||
|
||||
// Names of the sibling projects installed with `sibling`, alphabetically. Read
|
||||
// from disk, so it's quick and needs no network.
|
||||
export async function installedSiblings() {
|
||||
const names = [];
|
||||
for (const file of await listFiles(Gio.File.new_for_path(SIBLINGS))) {
|
||||
if (GLib.file_test(GLib.build_filenamev([file.get_path(), '.git']), GLib.FileTest.IS_DIR))
|
||||
names.push(file.get_basename());
|
||||
}
|
||||
return names.sort();
|
||||
}
|
||||
|
||||
// sibling check --porcelain, which fetches each sibling's remote:
|
||||
// [{name, installed, modified, state: 'available' | 'current' | 'unknown', available}]
|
||||
// Throws if sibling itself couldn't run.
|
||||
export async function checkSiblings(cancellable) {
|
||||
const {status, stdout, stderr} = await run([bin('sibling'), 'check', '--porcelain'], cancellable);
|
||||
if (status !== 0)
|
||||
throw new Error(stripAnsi(stderr || stdout).trim() || `sibling exited with status ${status}`);
|
||||
const siblings = [];
|
||||
for (const line of stdout.split('\n')) {
|
||||
const [name, installedField, available = ''] = line.split('\t');
|
||||
if (!name || installedField === undefined)
|
||||
continue;
|
||||
const modified = installedField.endsWith(', modified');
|
||||
let state = 'available';
|
||||
if (available === '')
|
||||
state = 'current';
|
||||
else if (available === '?')
|
||||
state = 'unknown';
|
||||
siblings.push({
|
||||
name,
|
||||
installed: modified ? installedField.slice(0, -', modified'.length) : installedField,
|
||||
modified,
|
||||
state,
|
||||
available: state === 'available' ? available : null,
|
||||
});
|
||||
}
|
||||
return siblings;
|
||||
}
|
||||
|
||||
// configure --list, with each item's description from its configure.d file:
|
||||
// [{name, title, description, done}]
|
||||
export async function configureItems() {
|
||||
@@ -187,7 +228,8 @@ export function runInTerminal(extensionPath, preference, name, argv) {
|
||||
return false;
|
||||
const tracked = GLib.build_filenamev([extensionPath, 'bin', 'run-tracked']);
|
||||
const command = ['systemd-run', '--user', '--quiet', '--collect',
|
||||
`--unit=coredesktop-${name}-${Date.now()}`, '--',
|
||||
// A sibling's name can hold characters a unit name can't
|
||||
`--unit=coredesktop-${name.replace(/[^A-Za-z0-9:_.-]/g, '_')}-${Date.now()}`, '--',
|
||||
...terminal, 'bash', tracked, name, ...argv];
|
||||
GLib.mkdir_with_parents(STATUS_DIR, 0o700);
|
||||
Gio.Subprocess.new(command, Gio.SubprocessFlags.NONE);
|
||||
|
||||
@@ -98,6 +98,150 @@ class ConfigureDialog extends ModalDialog.ModalDialog {
|
||||
}
|
||||
});
|
||||
|
||||
// The sibling projects on this machine, each with its version and whether a
|
||||
// newer one is out, and buttons to update them. Checks afresh when it opens.
|
||||
// siblings: what's already known, shown while checking (or [] for nothing)
|
||||
// isRunning(name): whether `sibling update` is running for that sibling
|
||||
// onChecked(siblings): called with each check's result
|
||||
// onUpdate(name): update one sibling; onUpdateAll(): update every one
|
||||
export const SiblingsDialog = GObject.registerClass(
|
||||
class SiblingsDialog extends ModalDialog.ModalDialog {
|
||||
_init({siblings, isRunning, onChecked, onUpdate, onUpdateAll}) {
|
||||
super._init({styleClass: 'coredesktop-dialog coredesktop-configure-dialog'});
|
||||
this._isRunning = isRunning;
|
||||
this._onChecked = onChecked;
|
||||
this._onUpdate = onUpdate;
|
||||
this._onUpdateAll = onUpdateAll;
|
||||
this._cancellable = new Gio.Cancellable();
|
||||
|
||||
this._content = new Dialog.MessageDialogContent({title: 'Sibling projects', description: ''});
|
||||
this.contentLayout.add_child(this._content);
|
||||
|
||||
this._list = new St.BoxLayout({orientation: Clutter.Orientation.VERTICAL, style_class: 'coredesktop-configure-list'});
|
||||
const scroll = new St.ScrollView({
|
||||
style_class: 'coredesktop-configure-scroll',
|
||||
hscrollbar_policy: St.PolicyType.NEVER,
|
||||
vscrollbar_policy: St.PolicyType.AUTOMATIC,
|
||||
overlay_scrollbars: true,
|
||||
});
|
||||
scroll.set_child(this._list);
|
||||
this.contentLayout.add_child(scroll);
|
||||
|
||||
this.connect('destroy', () => this._cancellable.cancel());
|
||||
this._show(siblings, true);
|
||||
this._load();
|
||||
}
|
||||
|
||||
async _load() {
|
||||
let siblings;
|
||||
try {
|
||||
siblings = await Cli.checkSiblings(this._cancellable);
|
||||
} catch (e) {
|
||||
if (e.matches?.(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
|
||||
return;
|
||||
this._content.description = `Couldn't check for newer versions: ${e.message}`;
|
||||
this._setButtons([]);
|
||||
return;
|
||||
}
|
||||
this._onChecked(siblings);
|
||||
this._show(siblings, false);
|
||||
}
|
||||
|
||||
_show(siblings, checking) {
|
||||
const newer = siblings.filter(s => s.state === 'available');
|
||||
const unknown = siblings.filter(s => s.state === 'unknown');
|
||||
if (checking)
|
||||
this._content.description = 'Checking for newer versions…';
|
||||
else if (siblings.length === 0)
|
||||
this._content.description = 'No sibling projects are installed. Add one in a terminal with: sibling add <url>';
|
||||
else if (newer.length > 0)
|
||||
this._content.description = `${newer.length} of ${siblings.length} ${newer.length === 1 ? 'has' : 'have'} a newer version. Update also updates them.`;
|
||||
else if (unknown.length > 0)
|
||||
this._content.description = `Couldn't check ${unknown.length} of ${siblings.length} for a newer version. The rest are up to date.`;
|
||||
else
|
||||
this._content.description = siblings.length === 1
|
||||
? 'It\'s up to date.' : `All ${siblings.length} are up to date.`;
|
||||
|
||||
this._list.remove_all_children();
|
||||
for (const sibling of siblings)
|
||||
this._list.add_child(this._row(sibling, checking));
|
||||
this._setButtons(checking ? [] : newer);
|
||||
}
|
||||
|
||||
_row(sibling, checking) {
|
||||
const row = new St.BoxLayout({style_class: 'coredesktop-configure-row'});
|
||||
row.add_child(new St.Icon({
|
||||
icon_name: 'application-x-addon-symbolic',
|
||||
style_class: 'coredesktop-configure-icon',
|
||||
y_align: Clutter.ActorAlign.CENTER,
|
||||
}));
|
||||
const text = new St.BoxLayout({
|
||||
orientation: Clutter.Orientation.VERTICAL,
|
||||
x_expand: true,
|
||||
y_align: Clutter.ActorAlign.CENTER,
|
||||
});
|
||||
text.add_child(new St.Label({text: sibling.name, style_class: 'coredesktop-item-title'}));
|
||||
let description = sibling.installed ? `Installed: ${sibling.installed}` : 'Checking…';
|
||||
if (sibling.modified)
|
||||
description += ', with local changes';
|
||||
if (sibling.available)
|
||||
description += ` · ${sibling.available} is available`;
|
||||
text.add_child(new St.Label({text: description, style_class: 'coredesktop-item-description'}));
|
||||
row.add_child(text);
|
||||
|
||||
const running = this._isRunning(sibling.name);
|
||||
let state = null, kind;
|
||||
if (running)
|
||||
[state, kind] = ['Running…', 'running'];
|
||||
else if (checking)
|
||||
state = null;
|
||||
else if (sibling.state === 'available')
|
||||
[state, kind] = ['New version', 'accent'];
|
||||
else if (sibling.state === 'current')
|
||||
[state, kind] = ['Up to date', 'success'];
|
||||
else
|
||||
[state, kind] = ['Couldn\'t check', 'warning'];
|
||||
if (state) {
|
||||
row.add_child(new St.Label({
|
||||
text: state,
|
||||
style_class: `coredesktop-pill ${kind}`,
|
||||
y_align: Clutter.ActorAlign.CENTER,
|
||||
}));
|
||||
}
|
||||
|
||||
if (sibling.state === 'available' && !checking) {
|
||||
const button = new St.Button({
|
||||
label: 'Update',
|
||||
style_class: 'button coredesktop-configure-button default',
|
||||
y_align: Clutter.ActorAlign.CENTER,
|
||||
can_focus: true,
|
||||
reactive: !running,
|
||||
});
|
||||
button.connect('clicked', () => {
|
||||
this.close();
|
||||
this._onUpdate(sibling.name);
|
||||
});
|
||||
row.add_child(button);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
_setButtons(newer) {
|
||||
const buttons = [];
|
||||
if (newer.length > 1) {
|
||||
buttons.push({
|
||||
label: 'Update all',
|
||||
action: () => {
|
||||
this.close();
|
||||
this._onUpdateAll();
|
||||
},
|
||||
});
|
||||
}
|
||||
buttons.push({label: 'Close', action: () => this.close(), key: Clutter.KEY_Escape, default: true});
|
||||
this.setButtons(buttons);
|
||||
}
|
||||
});
|
||||
|
||||
// Ask before running something. onConfirm runs if the user agrees.
|
||||
export const ConfirmDialog = GObject.registerClass(
|
||||
class ConfirmDialog extends ModalDialog.ModalDialog {
|
||||
|
||||
Reference in New Issue
Block a user