From e0add3d4c92b97f70801d9206a2b2a07260cb976 Mon Sep 17 00:00:00 2001 From: Aliaksei Zhuk Date: Tue, 26 Sep 2023 09:59:16 +0300 Subject: [PATCH] Added support of Gnome 45 --- extension.js | 71 ++++++++++++++++++++++++--------------------------- metadata.json | 16 ++++++------ 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/extension.js b/extension.js index d53e639..1e2f552 100644 --- a/extension.js +++ b/extension.js @@ -1,14 +1,15 @@ // Guillotine: a gnome extension designed for efficiently carrying out executions of commands from a customizable menu // Copyright (C) 2021 Christian Klaue (mail@ck76.de) -'use strict'; +import GLib from 'gi://GLib'; +import Gio from 'gi://Gio'; +import St from 'gi://St'; -const UI = imports.ui; -const GLib = imports.gi.GLib; -const Gio = imports.gi.Gio; -const St = imports.gi.St; - -const Me = imports.misc.extensionUtils.getCurrentExtension(); +import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; +import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js'; +import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js'; +import * as Main from 'resource:///org/gnome/shell/ui/main.js'; +const ByteArray = imports.byteArray; // legacy module without ESM equivalent const DEBUG = 0; const INFO = 1; @@ -67,7 +68,7 @@ function error(message, error) { } function notify(message, details) { - UI.main.notify(message, details || ""); + Main.notify(message, details || ""); } /******************************************************************************/ @@ -89,12 +90,12 @@ class Command { parseProperties(properties, self, commandChecks); Object.assign(this, self); // setup UI - this.UI = new UI.popupMenu.PopupMenuItem(this.title); + this.UI = new PopupMenu.PopupMenuItem(this.title); if ("icon" in this) { this.UI.icon = new St.Icon({ style_class: "popup-menu-icon" }); - if (this.icon.toLowerCase() === "guillotine-symbolic") this.UI.icon.gicon = Gio.icon_new_for_string(Me.path + "/guillotine-symbolic.svg"); + if (this.icon.toLowerCase() === "guillotine-symbolic") this.UI.icon.gicon = Gio.icon_new_for_string(this.path + "/guillotine-symbolic.svg"); else if (this.icon.charAt(0) == "/") this.UI.icon.gicon = Gio.icon_new_for_string(this.icon); else if (this.icon.charAt(0) == "~") { let home = GLib.get_home_dir(); @@ -179,13 +180,13 @@ class Switch { parseProperties(properties, self, switchChecks); Object.assign(this, self); - this.UI = new UI.popupMenu.PopupSwitchMenuItem(this.title, false); + this.UI = new PopupMenu.PopupSwitchMenuItem(this.title, false); if ("icon" in this) { this.UI.icon = new St.Icon({ style_class: "popup-menu-icon" }); - if (this.icon.toLowerCase() === "guillotine-symbolic") this.UI.icon.gicon = Gio.icon_new_for_string(Me.path + "/guillotine-symbolic.svg"); + if (this.icon.toLowerCase() === "guillotine-symbolic") this.UI.icon.gicon = Gio.icon_new_for_string(this.path + "/guillotine-symbolic.svg"); else if (this.icon.charAt(0) == "/") this.UI.icon.gicon = Gio.icon_new_for_string(this.icon); else if (this.icon.charAt(0) == "~") { let home = GLib.get_home_dir(); @@ -370,12 +371,12 @@ class SubMenu { // sanity checks parseProperties(properties, self, menuChecks); Object.assign(this, self); - this.UI = new UI.popupMenu.PopupSubMenuMenuItem(this.title); + this.UI = new PopupMenu.PopupSubMenuMenuItem(this.title); if ("icon" in this) { this.UI.icon = new St.Icon({ style_class: "popup-menu-icon" }); - if (this.icon.toLowerCase() === "guillotine-symbolic") this.UI.icon.gicon = Gio.icon_new_for_string(Me.path + "/guillotine-symbolic.svg"); + if (this.icon.toLowerCase() === "guillotine-symbolic") this.UI.icon.gicon = Gio.icon_new_for_string(this.path + "/guillotine-symbolic.svg"); else if (this.icon.charAt(0) == "/") this.UI.icon.gicon = Gio.icon_new_for_string(this.icon); else if (this.icon.charAt(0) == "~") { let home = GLib.get_home_dir(); @@ -404,7 +405,7 @@ class SubMenu { class Separator { constructor(properties) { debug("Separator initialized."); - this.UI = new UI.popupMenu.PopupSeparatorMenuItem(this.title); + this.UI = new PopupMenu.PopupSeparatorMenuItem(this.title); } cancel() { @@ -422,17 +423,19 @@ const settingsChecks = [ { name: "notificationlevel", type: "string", values: ["debug", "info", "warning", "error"] } ]; -class Guillotine { +export default class Guillotine extends Extension { constructor(meta) { - info("Initializing " + Me.metadata.name + " version " + Me.metadata.version); + super(meta); + + info("Initializing " + this.metadata.name + " version " + this.metadata.version); } enable() { if (this.button) { this.disable(); - info("Change of config detected: restarting " + Me.metadata.name); + info("Change of config detected: restarting " + this.metadata.name); } else { - info("Enabling " + Me.metadata.name + " version " + Me.metadata.version); + info("Enabling " + this.metadata.name + " version " + this.metadata.version); } this.menu = []; try { @@ -453,9 +456,9 @@ class Guillotine { }); // button - this.button = new UI.panelMenu.Button(); + this.button = new PanelMenu.Button(); this.button.add_child(this.icon); - UI.main.panel.addToStatusArea(Me.metadata.uuid, this.button); + Main.panel.addToStatusArea(this.metadata.uuid, this.button); return; } @@ -474,7 +477,7 @@ class Guillotine { this.icon = new St.Icon({ style_class: "popup-menu-icon", fallback_icon_name: "dialog-error" }); - if (this.settings.icon.toLowerCase() === "guillotine-symbolic") this.icon.gicon = Gio.icon_new_for_string(Me.path + "/guillotine-symbolic.svg"); + if (this.settings.icon.toLowerCase() === "guillotine-symbolic") this.icon.gicon = Gio.icon_new_for_string(this.path + "/guillotine-symbolic.svg"); else if (this.settings.icon.charAt(0) == "/") this.icon.gicon = Gio.icon_new_for_string(this.settings.icon); else if (this.settings.icon.charAt(0) == "~") { let home = GLib.get_home_dir(); @@ -486,22 +489,22 @@ class Guillotine { // this.UI.insert_child_at_index(this.UI.icon, 1); // if (this.settings.icon.toLowerCase() == "guillotine-symbolic") - // this.icon.gicon = Gio.icon_new_for_string(Me.path + "/guillotine-symbolic.svg"); + // this.icon.gicon = Gio.icon_new_for_string(this.path + "/guillotine-symbolic.svg"); // else // this.icon.icon_name = this.settings.icon; // button - this.button = new UI.panelMenu.Button(0.0, "guillotine", false); + this.button = new PanelMenu.Button(0.0, "guillotine", false); this.button.add_child(this.icon); for (const item in this.menu) { this.button.menu.addMenuItem(this.menu[item].UI); } - UI.main.panel.addToStatusArea("guillotine", this.button); + Main.panel.addToStatusArea("guillotine", this.button); } disable() { - info("Disabling " + Me.metadata.name); + info("Disabling " + this.metadata.name); for (const item in this.menu) { this.menu[item].cancel(); } @@ -520,7 +523,7 @@ class Guillotine { loadConfig() { // determine config location - let configFilename = imports.misc.extensionUtils.getSettings().get_string("config"); + let configFilename = this.getSettings().get_string("config"); configFilename = configFilename || GLib.get_home_dir() + "/.config/guillotine.json"; debug("Config location: " + configFilename); @@ -528,7 +531,7 @@ class Guillotine { // check if custom config exists; restore default config file otherwise this.configFile = Gio.File.new_for_path(configFilename); if (!this.configFile.query_exists(null)) { - let defaultConfig = Gio.File.new_for_path(Me.path + "/default.json"); + let defaultConfig = Gio.File.new_for_path(this.path + "/default.json"); defaultConfig.copy(this.configFile, 0, null, null); info("Config not found @ location: " + configFilename + ". Default config restored."); } @@ -542,7 +545,7 @@ class Guillotine { this.config = {}; let [ok, content] = GLib.file_get_contents(configFilename); if (ok) { - let contentString = imports.byteArray.toString(content); + let contentString = ByteArray.toString(content); this.config = JSON.parse(contentString); } else throw new Error("Could not load config file."); } @@ -602,12 +605,4 @@ function parseMenu(menu) { } } return items; -} - -/******************************************************************************/ -/***** INIT *****/ -/******************************************************************************/ - -function init(meta) { - return new Guillotine(meta); -} +} \ No newline at end of file diff --git a/metadata.json b/metadata.json index 414d717..8601e62 100644 --- a/metadata.json +++ b/metadata.json @@ -1,9 +1,9 @@ { - "uuid": "guillotine@fopdoodle.net", - "name": "Guillotine", - "description": "Guillotine is a gnome extension designed for efficiently carrying out executions of commands from a customizable menu. Simply speaking: it is a highly customizable menu that enables you to launch commands and toggle services.", - "version": 17, - "url": "https://gitlab.com/ente76/guillotine/", - "settings-schema": "org.gnome.shell.extensions.guillotine", - "shell-version": ["40", "41", "42", "43", "44"] -} + "uuid": "guillotine@fopdoodle.net", + "name": "Guillotine", + "description": "Guillotine is a gnome extension designed for efficiently carrying out executions of commands from a customizable menu. Simply speaking: it is a highly customizable menu that enables you to launch commands and toggle services.", + "version": 19, + "url": "https://gitlab.com/ente76/guillotine/", + "settings-schema": "org.gnome.shell.extensions.guillotine", + "shell-version": ["45"] +} \ No newline at end of file -- GitLab