Skip to content

Commit 0eda1fc

Browse files
author
mirkobrombin
committed
first commit
0 parents  commit 0eda1fc

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Vanilla OS On-going Update Check
2+
This GNOME Extension checks if the system is undergoing an update and allows
3+
the user to request a cancelation of the update process.
4+
5+
In Vanilla OS, the update process is handled by ABRoot, each update consists of
6+
multiple stages, and the process can be canceled until the 6th stage is reached.
7+
This extension checks if ABRoot allows the user to cancel the update process and
8+
lets the user request a cancelation by adding a lock file to /tmp.

vso@vanillaos.org/extension.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* License: GPLv3
3+
* Authors:
4+
* Vanilla OS Contributors <https://github.com/vanilla-os/>
5+
* Copyright: 2023
6+
*/
7+
8+
// following imports will be useful once we migrate the extension to GNOME 45
9+
// import St from "gi://St";
10+
// import GObject from "gi://GObject";
11+
// import Gio from "gi://Gio";
12+
// import GLib from "gi://GLib";
13+
14+
// import * as Main from "resource:///org/gnome/shell/ui/main.js";
15+
// import * as ExtensionUtils from "resource:///org/gnome/shell/misc/util.js";
16+
// import * as PanelMenu from "resource:///org/gnome/shell/ui/panelMenu.js";
17+
// import * as PopupMenu from "resource:///org/gnome/shell/ui/popupMenu.js";
18+
19+
// import {
20+
// gettext as _,
21+
// ngettext as __,
22+
// } from "resource:///org/gnome/shell/extensions/extension.js";
23+
24+
const GETTEXT_DOMAIN = "vso-update-check";
25+
26+
const { GObject, St, Gio, GLib, Gtk } = imports.gi;
27+
const ExtensionUtils = imports.misc.extensionUtils;
28+
const Main = imports.ui.main;
29+
const PanelMenu = imports.ui.panelMenu;
30+
const PopupMenu = imports.ui.popupMenu;
31+
32+
const _ = ExtensionUtils.gettext;
33+
34+
/* Defaults */
35+
const FILE_CHECK_TIMEOUT = 60; // seconds
36+
const ABROOT_STAGE_FILE = "/tmp/ABSystem.Upgrade.stage";
37+
const ABROOT_USER_LOCK_FILE = "/tmp/ABSystem.Upgrade.user.lock";
38+
39+
const VSOUpdateCheckIndicator = GObject.registerClass(
40+
class VSOUpdateCheckIndicator extends PanelMenu.Button {
41+
_init() {
42+
super._init(0.0, _("Vanilla OS On-going Update Check"));
43+
44+
this.add_child(
45+
new St.Icon({
46+
icon_name: "folder-download-symbolic",
47+
style_class: "system-status-icon",
48+
})
49+
);
50+
51+
let msgUpdateItem = new PopupMenu.PopupMenuItem(
52+
_("A system update is being applied in the background")
53+
);
54+
msgUpdateItem.setSensitive(false);
55+
this.menu.addMenuItem(msgUpdateItem);
56+
57+
let stopUpdateItem = new PopupMenu.PopupMenuItem(
58+
_("Stop on-going update")
59+
);
60+
stopUpdateItem.connect("activate", this._stopOnGoingUpdate.bind(this));
61+
this.menu.addMenuItem(stopUpdateItem);
62+
63+
// Start checking for the stage file
64+
this._checkUpdateFile();
65+
}
66+
67+
/**
68+
* Stop the update and send the request.
69+
*/
70+
_stopOnGoingUpdate() {
71+
let file = Gio.File.new_for_path(ABROOT_USER_LOCK_FILE);
72+
file.replace_contents("", null, false, Gio.FileCreateFlags.NONE, null);
73+
74+
this.destroy();
75+
76+
Main.notify(
77+
_("Stop Update Request Sent"),
78+
_("The system will attempt to halt the update process if possible.")
79+
);
80+
}
81+
82+
/**
83+
* Checks for the existence of the stage file and shows/hides the
84+
* indicator accordingly and schedules the next check.
85+
*/
86+
_checkUpdateFile() {
87+
let file = Gio.File.new_for_path(ABROOT_STAGE_FILE);
88+
89+
if (file.query_exists(null)) {
90+
this.show();
91+
} else {
92+
this.hide();
93+
}
94+
95+
GLib.timeout_add_seconds(
96+
GLib.PRIORITY_DEFAULT,
97+
FILE_CHECK_TIMEOUT,
98+
this._checkUpdateFile.bind(this)
99+
);
100+
}
101+
}
102+
);
103+
104+
class VSOUpdateCheckExtension {
105+
constructor(uuid) {
106+
this._uuid = uuid;
107+
108+
ExtensionUtils.initTranslations(GETTEXT_DOMAIN);
109+
}
110+
111+
enable() {
112+
this._updateCheckIndicator = new VSOUpdateCheckIndicator();
113+
Main.panel.addToStatusArea(this._uuid, this._updateCheckIndicator);
114+
}
115+
116+
disable() {
117+
this._updateCheckIndicator.destroy();
118+
this._updateCheckIndicator = null;
119+
}
120+
}
121+
122+
function init(meta) {
123+
return new VSOUpdateCheckExtension(meta.uuid);
124+
}

vso@vanillaos.org/metadata.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "Vanilla OS On-going Update Check",
3+
"description": "Show if the system is performing an update in the background.",
4+
"uuid": "vso@vanillaos.org",
5+
"version": 1,
6+
"shell-version": [
7+
"44"
8+
]
9+
}

vso@vanillaos.org/stylesheet.css

Whitespace-only changes.

0 commit comments

Comments
 (0)