Release / release (push) Successful in 14s
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>
412 lines
16 KiB
JavaScript
412 lines
16 KiB
JavaScript
// Dialogs: the version report, and confirmations that say what a command will
|
|
// do before it runs.
|
|
|
|
import Clutter from 'gi://Clutter';
|
|
import Gio from 'gi://Gio';
|
|
import GLib from 'gi://GLib';
|
|
import GObject from 'gi://GObject';
|
|
import Pango from 'gi://Pango';
|
|
import St from 'gi://St';
|
|
|
|
import * as Dialog from 'resource:///org/gnome/shell/ui/dialog.js';
|
|
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';
|
|
|
|
import * as Cli from './cli.js';
|
|
|
|
// Everything configure can set up, whether it's done, and a button to set each
|
|
// one up. items: [{name, title, description, done, icon, running}]
|
|
export const ConfigureDialog = GObject.registerClass(
|
|
class ConfigureDialog extends ModalDialog.ModalDialog {
|
|
_init({items, onConfigure, onOpenAll}) {
|
|
super._init({styleClass: 'coredesktop-dialog coredesktop-configure-dialog'});
|
|
|
|
const todo = items.filter(i => !i.done).length;
|
|
let description;
|
|
if (items.length === 0)
|
|
description = 'Couldn\'t read what configure can set up. Open it in a terminal instead.';
|
|
else if (todo === 0)
|
|
description = `All ${items.length} are set up. You can change any of them.`;
|
|
else
|
|
description = `${todo} of ${items.length} still to set up. Each opens a terminal that walks you through it.`;
|
|
this.contentLayout.add_child(new Dialog.MessageDialogContent({title: 'Configure CoreDesktop', description}));
|
|
|
|
const list = new St.BoxLayout({orientation: Clutter.Orientation.VERTICAL, style_class: 'coredesktop-configure-list'});
|
|
const sorted = [...items].sort((a, b) => Number(a.done) - Number(b.done));
|
|
for (const item of sorted) {
|
|
const row = new St.BoxLayout({style_class: 'coredesktop-configure-row'});
|
|
row.add_child(new St.Icon({
|
|
icon_name: item.icon,
|
|
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: item.title, style_class: 'coredesktop-item-title'}));
|
|
text.add_child(new St.Label({text: item.description, style_class: 'coredesktop-item-description'}));
|
|
row.add_child(text);
|
|
|
|
let state, kind;
|
|
if (item.running)
|
|
[state, kind] = ['Running…', 'running'];
|
|
else if (item.done)
|
|
[state, kind] = ['Done', 'success'];
|
|
else
|
|
[state, kind] = ['To do', 'warning'];
|
|
row.add_child(new St.Label({
|
|
text: state,
|
|
style_class: `coredesktop-pill ${kind}`,
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
}));
|
|
|
|
const button = new St.Button({
|
|
label: item.done ? 'Change' : 'Set up',
|
|
style_class: `button coredesktop-configure-button${item.done ? '' : ' default'}`,
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
can_focus: true,
|
|
reactive: !item.running,
|
|
});
|
|
button.connect('clicked', () => {
|
|
this.close();
|
|
onConfigure(item);
|
|
});
|
|
row.add_child(button);
|
|
list.add_child(row);
|
|
}
|
|
|
|
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(list);
|
|
this.contentLayout.add_child(scroll);
|
|
|
|
this.setButtons([
|
|
{
|
|
label: 'Open in terminal',
|
|
action: () => {
|
|
this.close();
|
|
onOpenAll();
|
|
},
|
|
},
|
|
{label: 'Close', action: () => this.close(), key: Clutter.KEY_Escape, default: true},
|
|
]);
|
|
}
|
|
});
|
|
|
|
// 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 {
|
|
_init({title, description, details = [], confirmLabel, onConfirm}) {
|
|
super._init({styleClass: 'coredesktop-dialog'});
|
|
|
|
const content = new Dialog.MessageDialogContent({title, description});
|
|
this.contentLayout.add_child(content);
|
|
|
|
// What the command does, one line each with an icon, so it's easy to scan
|
|
if (details.length > 0) {
|
|
const list = new St.BoxLayout({
|
|
orientation: Clutter.Orientation.VERTICAL,
|
|
style_class: 'coredesktop-detail-list',
|
|
});
|
|
for (const [iconName, text] of details) {
|
|
const row = new St.BoxLayout({style_class: 'coredesktop-detail-row'});
|
|
row.add_child(new St.Icon({icon_name: iconName, style_class: 'coredesktop-detail-icon'}));
|
|
const label = new St.Label({text, y_align: Clutter.ActorAlign.CENTER, x_expand: true});
|
|
label.clutter_text.line_wrap = true;
|
|
label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
row.add_child(label);
|
|
list.add_child(row);
|
|
}
|
|
this.contentLayout.add_child(list);
|
|
}
|
|
|
|
this.setButtons([
|
|
{label: 'Cancel', action: () => this.close(), key: Clutter.KEY_Escape},
|
|
{
|
|
label: confirmLabel,
|
|
action: () => {
|
|
this.close();
|
|
onConfirm();
|
|
},
|
|
default: true,
|
|
},
|
|
]);
|
|
}
|
|
});
|
|
|
|
// Runs `version` and shows its report, with a button to update when there's
|
|
// something newer
|
|
export const VersionDialog = GObject.registerClass(
|
|
class VersionDialog extends ModalDialog.ModalDialog {
|
|
_init({onUpdate}) {
|
|
super._init({styleClass: 'coredesktop-dialog coredesktop-version-dialog'});
|
|
this._onUpdate = onUpdate;
|
|
this._cancellable = new Gio.Cancellable();
|
|
this._output = '';
|
|
|
|
this._content = new Dialog.MessageDialogContent({
|
|
title: 'CoreDesktop version',
|
|
description: 'Checking for newer versions of CoreDesktop, the kernel, the video driver and sibling projects…',
|
|
});
|
|
this.contentLayout.add_child(this._content);
|
|
|
|
this._report = new St.Label({style_class: 'coredesktop-version-report'});
|
|
this._report.clutter_text.line_wrap = false;
|
|
this._report.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
const scroll = new St.ScrollView({
|
|
style_class: 'coredesktop-version-scroll',
|
|
hscrollbar_policy: St.PolicyType.AUTOMATIC,
|
|
vscrollbar_policy: St.PolicyType.AUTOMATIC,
|
|
overlay_scrollbars: true,
|
|
});
|
|
const box = new St.BoxLayout({orientation: Clutter.Orientation.VERTICAL});
|
|
box.add_child(this._report);
|
|
scroll.set_child(box);
|
|
this.contentLayout.add_child(scroll);
|
|
|
|
this._report.text = 'Checking…';
|
|
this._report.ease({
|
|
opacity: 100, duration: 700, autoReverse: true, repeatCount: -1,
|
|
mode: Clutter.AnimationMode.EASE_IN_OUT_SINE,
|
|
});
|
|
|
|
this._setButtons(false);
|
|
this.connect('destroy', () => this._cancellable.cancel());
|
|
this._load();
|
|
}
|
|
|
|
_setButtons(updateAvailable) {
|
|
const buttons = [];
|
|
if (this._output) {
|
|
buttons.push({
|
|
label: 'Copy',
|
|
action: () => {
|
|
St.Clipboard.get_default().set_text(St.ClipboardType.CLIPBOARD, this._output);
|
|
this._content.description = 'Copied to the clipboard.';
|
|
},
|
|
});
|
|
}
|
|
if (updateAvailable) {
|
|
buttons.push({
|
|
label: 'Update now',
|
|
action: () => {
|
|
this.close();
|
|
this._onUpdate();
|
|
},
|
|
});
|
|
}
|
|
buttons.push({label: 'Close', action: () => this.close(), key: Clutter.KEY_Escape, default: true});
|
|
this.setButtons(buttons);
|
|
}
|
|
|
|
async _load() {
|
|
let text;
|
|
try {
|
|
const {stdout, stderr} = await Cli.run([Cli.bin('version')], this._cancellable);
|
|
text = Cli.stripAnsi(stdout || stderr).trimEnd();
|
|
} catch (e) {
|
|
if (e.matches?.(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
|
|
return;
|
|
text = `Couldn't run version: ${e.message}`;
|
|
}
|
|
this._report.remove_all_transitions();
|
|
this._report.opacity = 255;
|
|
this._output = text;
|
|
|
|
const available = /is available/.test(text);
|
|
const stale = /mirror .* last synced/i.test(text);
|
|
this._content.description = available
|
|
? 'Newer versions are available. Update to install them.'
|
|
: 'Everything is up to date.';
|
|
if (stale)
|
|
this._content.description += ' Your package mirror is out of date; update switches to a fresher one.';
|
|
|
|
this._report.clutter_text.set_markup(markup(text));
|
|
this._setButtons(available);
|
|
}
|
|
});
|
|
|
|
// Bold the "Label value" names and highlight what's newer or needs attention
|
|
function markup(text) {
|
|
return text.split('\n').map(line => {
|
|
// "Video driver" has a single space before its value
|
|
let m = line.match(/^(CoreDesktop|Kernel|Video driver|Last update)(\s+)(.*)$/);
|
|
if (m)
|
|
return `<b>${esc(m[1])}</b>${esc(m[2])}${highlight(m[3])}`;
|
|
m = line.match(/^(\s+\S+)(\s{2,})(.*)$/);
|
|
if (m)
|
|
return `${esc(m[1])}${esc(m[2])}${highlight(m[3])}`;
|
|
if (/^Sibling projects$/.test(line))
|
|
return `<b>${esc(line)}</b>`;
|
|
if (/mirror|newer packages may be missing/.test(line))
|
|
return `<span foreground="#e5a50a">${esc(line)}</span>`;
|
|
return esc(line);
|
|
}).join('\n');
|
|
}
|
|
|
|
function highlight(value) {
|
|
// "2026.11.26 (01d2432), 2026.11.27 (abc1234) is available (run update)"
|
|
// Commas inside parentheses, as in "(newer kernel installed, reboot to use it)", don't split
|
|
const parts = value.split(/,\s*(?![^(]*\))/);
|
|
return parts.map(part => {
|
|
if (/is available/.test(part))
|
|
return `<span foreground="#3584e4" weight="bold">⬆ ${esc(part)}</span>`;
|
|
if (/reboot|couldn't check|modified/.test(part))
|
|
return `<span foreground="#e5a50a">${esc(part)}</span>`;
|
|
return esc(part);
|
|
}).join(', ');
|
|
}
|
|
|
|
function esc(s) {
|
|
return GLib.markup_escape_text(s, -1);
|
|
}
|