changeset 0:d229e8a4c54f gnome-36

GNOME 36 version
author Brad Greco <brad@bgreco.net>
date Tue, 21 Nov 2023 19:06:23 -0500
parents
children f0acbcf9fada
files extension.js metadata.json prefs.js schemas/gschemas.compiled schemas/org.gnome.shell.extensions.net.bgreco.restartinto.gschema.xml
diffstat 5 files changed, 186 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extension.js	Tue Nov 21 19:06:23 2023 -0500
@@ -0,0 +1,75 @@
+/* extension.js
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/* exported init */
+
+const { AccountsService, Clutter, Gio,
+		GLib, GObject, Pango, Polkit, Shell, St }  = imports.gi;
+const Util = imports.misc.util;
+const EndSessionDialog = imports.ui.endSessionDialog;
+const ExtensionUtils = imports.misc.extensionUtils;
+
+class Extension {
+	constructor() {
+	}
+
+	enable() {
+		EndSessionDialog.EndSessionDialog.prototype._updateButtons = function() {
+			let dialogContent = EndSessionDialog.DialogContent[this._type];
+			let buttons = [{ action: this.cancel.bind(this),
+							 label: _("Cancel"),
+							 key: Clutter.KEY_Escape }];
+
+			for (let i = 0; i < dialogContent.confirmButtons.length; i++) {
+				let signal = dialogContent.confirmButtons[i].signal;
+				let label = dialogContent.confirmButtons[i].label;
+				buttons.push({
+					action: () => {
+						this.close(true);
+						let signalId = this.connect('closed', () => {
+							this.disconnect(signalId);
+							this._confirm(signal);
+						});
+					},
+					label,
+				});
+			}
+			if (this._type != 0) {
+				let settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.net.bgreco.restartinto');
+				let secondaryEntry = settings.get_string('entry');
+				if (secondaryEntry) {
+					buttons.splice(2, 0, {
+						action: () => {
+							this.close(true);
+							Util.spawn(['systemctl', 'reboot', '--boot-loader-entry=' + secondaryEntry]);
+						},
+						label: settings.get_string('label')
+					});
+				}
+			}
+			this.setButtons(buttons);
+		};
+	}
+
+	disable() {
+	}
+}
+
+function init() {
+	return new Extension();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/metadata.json	Tue Nov 21 19:06:23 2023 -0500
@@ -0,0 +1,11 @@
+{
+  "name": "Restart Into...",
+  "description": "Display a list operating systems in the Restart dialog",
+  "uuid": "restartinto@bgreco.net",
+  "url": "https://hg.bgreco.net/restartinto@bgreco.net",
+  "settings-schema": "org.gnome.shell.extensions.net.bgreco.restartinto",
+  "version-name": "36.1.0",
+  "shell-version": [
+    "3.36"
+  ]
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prefs.js	Tue Nov 21 19:06:23 2023 -0500
@@ -0,0 +1,89 @@
+'use strict';
+
+const Gio = imports.gi.Gio;
+const Gtk = imports.gi.Gtk;
+const GLib = imports.gi.GLib;
+const ExtensionUtils = imports.misc.extensionUtils;
+const Me = ExtensionUtils.getCurrentExtension();
+
+function init() {
+}
+
+function buildPrefsWidget() {
+	let entries = imports.byteArray.toString(GLib.spawn_command_line_sync("systemctl reboot --boot-loader-entry=help")[1]);
+	let settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.net.bgreco.restartinto');
+	let currentSecondaryEntry = settings.get_string('entry');
+
+	let prefsWidget = new Gtk.Grid({
+		margin: 18,
+		column_spacing: 12,
+		row_spacing: 12,
+		visible: true
+	});
+
+	let title = new Gtk.Label({
+		label: `<b>${Me.metadata.name} Preferences</b>`,
+		halign: Gtk.Align.START,
+		use_markup: true,
+		visible: true
+	});
+	prefsWidget.attach(title, 0, 0, 2, 1);
+
+	let entryLabel = new Gtk.Label({
+		label: 'Secondary boot menu entry:',
+		halign: Gtk.Align.START,
+		visible: true
+	});
+	prefsWidget.attach(entryLabel, 0, 1, 1, 1);
+
+	let entryBox = new Gtk.ComboBoxText({
+		halign: Gtk.Align.END,
+		visible: true
+	});
+	for (const [i, entry] of entries.split("\n").entries()) {
+		if (entry.trim().length) {
+			entryBox.append_text(entry);
+			if (entry == currentSecondaryEntry) {
+				entryBox.set_active(i);
+			}
+		}
+	}
+	entryBox.connect('changed', function (w) {
+		settings.set_string('entry', w.get_active_text());
+	});
+	prefsWidget.attach(entryBox, 1, 1, 1, 1);
+
+	let labelLabel = new Gtk.Label({
+		label: 'Secondary restart button label:',
+		halign: Gtk.Align.START,
+		valign: Gtk.Align.START,
+		hexpand: false,
+		visible: true,
+		"margin-top": 5,
+	});
+	prefsWidget.attach(labelLabel, 0, 2, 1, 1);
+
+	let labelTextView = new Gtk.TextView({
+		buffer: new Gtk.TextBuffer({
+			text: settings.get_string('label'),
+		}),
+		editable: true,
+		visible: true,
+		"top-margin": 5,
+		"bottom-margin": 5,
+		"left-margin": 5,
+		"right-margin": 5,
+		"height-request": 50,
+	});
+	labelTextView.get_buffer().connect('changed', function (b) {
+		settings.set_string('label', b.text);
+	});
+	prefsWidget.attach(labelTextView, 1, 2, 1, 1);
+
+	prefsWidget.connect('realize', () => {
+		let window = prefsWidget.get_toplevel();
+		window.resize(100, 100);
+	});
+
+	return prefsWidget;
+}
Binary file schemas/gschemas.compiled has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schemas/org.gnome.shell.extensions.net.bgreco.restartinto.gschema.xml	Tue Nov 21 19:06:23 2023 -0500
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+  <schema id="org.gnome.shell.extensions.net.bgreco.restartinto" path="/org/gnome/shell/extensions/net.bgreco.restartinto/">
+    <key name="entry" type="s">
+      <default>""</default>
+    </key>
+    <key name="label" type="s">
+      <default>""</default>
+    </key>
+  </schema>
+</schemalist>