From 082b2795054795b0d5ebc478a6a0f41e2c1083f5 Mon Sep 17 00:00:00 2001 From: Rahul Date: Tue, 12 Dec 2023 13:46:32 +0600 Subject: [PATCH] =?UTF-8?q?Gnome=20shell=2045=20support=20added=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- extension.js | 79 +++++++++++------- metadata.json | 11 +-- prefs.js | 34 ++++++++ schemas/gschemas.compiled | Bin 464 -> 432 bytes ...l.extensions.php-laravel-valet.gschema.xml | 14 ++-- stylesheet.css | 1 + utils.js | 28 +++---- 8 files changed, 108 insertions(+), 64 deletions(-) create mode 100644 prefs.js create mode 100644 stylesheet.css diff --git a/README.md b/README.md index 68e4abc..8cef23e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ A PHP Laravel Valet status indicator and manager extension (GNOME Panel Applet) ## Supports -- Tested on Pop!_OS 21.10 and GNOME Shell V40 +|Extension Version|Gnome Shell Version| +|:-:|:-:| +|6|45| +|5|44, 43, 42, 41, 40| ## Prerequisite diff --git a/extension.js b/extension.js index 899300d..7ac6417 100644 --- a/extension.js +++ b/extension.js @@ -1,30 +1,34 @@ -'use strict'; +import GObject from 'gi://GObject'; +import Gio from 'gi://Gio'; +import St from 'gi://St'; +import Clutter from 'gi://Clutter'; -const {GObject, GLib, Gio, St, Clutter} = imports.gi; -const Main = imports.ui.main; -const PanelMenu = imports.ui.panelMenu; -const PopupMenu = imports.ui.popupMenu; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); -const Utils = Me.imports.utils; +import { Extension, gettext as _ } 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 Utils from './utils.js' + +import * as Main from 'resource:///org/gnome/shell/ui/main.js'; const PhpLaravelValet = GObject.registerClass( class PhpLaravelValet extends PanelMenu.Button { - _init() { - super._init(0.0, null, false); + _init(ext) { + super._init(1.0, null, false); - this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.php-laravel-valet'); + this._extension = ext; + this._settings = ext.getSettings(); + this._settings.connect('changed', () => this._refreshIndicator()); - this._indicatorText = new St.Label({text: 'Loading...', y_align: Clutter.ActorAlign.CENTER}); + this._indicatorText = new St.Label({ text: _('Loading...'), y_align: Clutter.ActorAlign.CENTER }); this.add_actor(this._indicatorText); - // Initialising the menu with demo item - this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Loading...')); + // initializing the menu with demo item + this.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('Loading...'))); this._refreshIndicator(); this.menu.connect('open-state-changed', (menu, open) => { - if (open) this._refreshMenu() + if (open) this._refreshMenu(); }); } @@ -33,7 +37,7 @@ const PhpLaravelValet = GObject.registerClass( if (phpVersion) { this._indicatorText.set_text(phpVersion); } else { - this._indicatorText.set_text('PHP not found'); + this._indicatorText.set_text(_('PHP not found')); } } @@ -47,35 +51,46 @@ const PhpLaravelValet = GObject.registerClass( this.menu.addMenuItem(new PopupMenu.PopupMenuItem(item.replace(/\.\.\./g, ''))); }) } else { - this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Valet not found')); + this.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('Valet not found'))); } // menu separator this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); // switch php sub menu - const phpSubMenu = new PopupMenu.PopupSubMenuMenuItem('Switch PHP'); + const phpSubMenu = new PopupMenu.PopupSubMenuMenuItem(_('Switch PHP')); const phpList = Utils.phpList(); if (phpList.length > 0) { phpList.forEach(item => { - const subMenu = new PopupMenu.PopupMenuItem('Switch to ' + item); + const subMenu = new PopupMenu.PopupMenuItem(_('Switch to ') + item); subMenu.connect('activate', () => this._switchPhp(item)); phpSubMenu.menu.addMenuItem(subMenu); }) } else { - phpSubMenu.menu.addMenuItem(new PopupMenu.PopupMenuItem('PHP not found')); + phpSubMenu.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('PHP not found'))); } this.menu.addMenuItem(phpSubMenu); // valet start/restart menu - const valetRestart = new PopupMenu.PopupMenuItem('Valet start/restart'); + const valetRestart = new PopupMenu.PopupMenuItem(_('Valet start/restart')); valetRestart.connect('activate', () => Utils.valetRestart()); this.menu.addMenuItem(valetRestart); // valet stop menu - const valetStop = new PopupMenu.PopupMenuItem('Valet stop'); + const valetStop = new PopupMenu.PopupMenuItem(_('Valet stop')); valetStop.connect('activate', () => Utils.valetStop()); this.menu.addMenuItem(valetStop); + + + if (this._settings.get_boolean('show-settings')) { + // menu separator + this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); + + // settings menu + const settings = new PopupMenu.PopupMenuItem(_('Settings')); + settings.connect('activate', () => this._extension.openPreferences()); + this.menu.addMenuItem(settings); + } } _switchPhp(version) { @@ -94,16 +109,16 @@ const PhpLaravelValet = GObject.registerClass( } } } -) +); -let phpLaravelValet = null; - -function enable() { - phpLaravelValet = new PhpLaravelValet(); - Main.panel.addToStatusArea('php-laravel-valet', phpLaravelValet); -} +export default class PhpLaravelValetExtension extends Extension { + enable() { + this._indicator = new PhpLaravelValet(this); + Main.panel.addToStatusArea(this.uuid, this._indicator); + } -function disable() { - phpLaravelValet.destroy(); - phpLaravelValet = null; + disable() { + this._indicator.destroy(); + this._indicator = null; + } } diff --git a/metadata.json b/metadata.json index e6c0c46..3a03aee 100644 --- a/metadata.json +++ b/metadata.json @@ -3,12 +3,9 @@ "description": "A PHP Laravel Valet status indicator and manager.", "uuid": "php-laravel-valet@rahulhaque", "shell-version": [ - "40", - "41", - "42", - "43", - "44" + "45" ], - "version": 5, - "url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension" + "version": 6, + "url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension", + "settings-schema": "org.gnome.shell.extensions.php-laravel-valet" } diff --git a/prefs.js b/prefs.js new file mode 100644 index 0000000..5852600 --- /dev/null +++ b/prefs.js @@ -0,0 +1,34 @@ +import Gio from 'gi://Gio'; +import Adw from 'gi://Adw'; +import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; + +export default class PhpLaravelValetPreferences extends ExtensionPreferences { + fillPreferencesWindow(window) { + // create a preferences page, with a single group + const page = new Adw.PreferencesPage({ + title: _('General'), + icon_name: 'dialog-information-symbolic', + }); + window.add(page); + + // create a preferences group, add to page + const group = new Adw.PreferencesGroup({ + title: _('Settings'), + description: _('Configure the settings of the extension'), + }); + page.add(group); + + // create a new preferences row + const show_settings = new Adw.SwitchRow({ + title: _('Show Settings'), + subtitle: _('Whether to show the settings in menu'), + }); + group.add(show_settings); + + // create a settings object and bind inputs + window._settings = this.getSettings(); + window._settings.bind('show-settings', show_settings, 'active', Gio.SettingsBindFlags.DEFAULT); + + window.set_default_size(620, 300); + } +} \ No newline at end of file diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index f8fdeb9d17f4760a708ac9e89c70283a8417582b..0e9404954b5de0abdc12f747bf1eebeb2460e828 100644 GIT binary patch delta 207 zcmcb>yn%Uw2k%No1|aZZSOcUtOboTI2XUF8m>Ed3iZU?#2LcJGLJ+M2#Ma4b8X&bG zwje_pg9VUw0%8}o8+$hJOD_C0`Uj)Rk5St$;o&lr_fcQXd9XH5)5Sx{u zjE|uL$N;$tWI5wxPey5(qRjM+5(Wm1V$I@={Bqsm)RL0Sy!2uQMh1 'right' Position in Panel - Position in Panel ('left', 'center', 'right') + Position in Panel ('left', 'center', 'right'). 0 Index in panel box - Index within the selected panel box (0: first, 1: second, ..., -1: last) - - - 'x-terminal-emulator -e' - Default shell to execute extension commands - Default shell to execute extension commands + Index within the selected panel box (0: first, 1: second, ..., -1: last). + + true + Show the settings button + Whether to show the settings button as last entry in the extensions list. + \ No newline at end of file diff --git a/stylesheet.css b/stylesheet.css new file mode 100644 index 0000000..37b93f2 --- /dev/null +++ b/stylesheet.css @@ -0,0 +1 @@ +/* Add your custom extension styling here */ diff --git a/utils.js b/utils.js index 1c3cf43..e7a5b24 100644 --- a/utils.js +++ b/utils.js @@ -1,13 +1,7 @@ -'use strict'; +import GLib from 'gi://GLib'; +import Bytes from 'gi://GLib/Bytes'; -const Bytes = imports.byteArray; -const GLib = imports.gi.GLib; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); - -const _settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.php-laravel-valet'); - -function safeSpawn(cmd) { +export function safeSpawn(cmd) { try { return GLib.spawn_command_line_sync(cmd); } catch (e) { @@ -15,33 +9,33 @@ function safeSpawn(cmd) { } } -function shellSpawn(cmd) { - const terminal = _settings.get_string('default-shell'); +export function shellSpawn(cmd) { + const terminal = 'x-terminal-emulator -e'; GLib.spawn_command_line_async(`${terminal} ${cmd}`); } -function phpVersion() { +export function phpVersion() { const res = safeSpawn('/bin/bash -c "php -v | grep -Po \'PHP\\s+\\d+.\\d+(?:(.\\d+))?\'"'); if (res[3] == 0) return Bytes.toString(res[1]).replace(/\n$/, ''); return false; } -function phpList() { +export function phpList() { const res = safeSpawn('ls /etc/php'); if (res[3] == 0) return Bytes.toString(res[1]).split('\n').filter(item => !!item).reverse(); return false; } -function valetStatus() { +export function valetStatus() { const res = safeSpawn('/bin/bash -c "valet --version && valet status"'); if (res[3] == 0) return Bytes.toString(res[1]).split('\n').filter(item => !!item); return false; } -function valetRestart() { +export function valetRestart() { shellSpawn('valet restart'); } -function valetStop() { +export function valetStop() { shellSpawn('valet stop'); -} +} \ No newline at end of file