From 45b24122fcd92f10c04d4aa5f35ab5bfebd95cf2 Mon Sep 17 00:00:00 2001 From: Rahul Date: Sat, 16 Apr 2022 23:48:19 +0600 Subject: [PATCH] Adjusted valet default behaviour that removes unmounted parked paths --- extension.js | 28 ++++++++------ metadata.json | 2 +- schemas/gschemas.compiled | Bin 0 -> 464 bytes ...l.extensions.php-laravel-valet.gschema.xml | 20 ++++++++++ utils.js | 35 +++++++++++------- 5 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 schemas/gschemas.compiled create mode 100644 schemas/org.gnome.shell.extensions.php-laravel-valet.gschema.xml diff --git a/extension.js b/extension.js index 93f87e0..39555bb 100644 --- a/extension.js +++ b/extension.js @@ -8,21 +8,24 @@ const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); const Utils = Me.imports.utils; -const Valet = GObject.registerClass( - class Valet extends PanelMenu.Button { +const PhpLaravelValet = GObject.registerClass( + class PhpLaravelValet extends PanelMenu.Button { _init() { super._init(0.0, null, false); + this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.php-laravel-valet'); + this._indicatorText = new St.Label({text: 'Loading...', y_align: Clutter.ActorAlign.CENTER}); this.add_actor(this._indicatorText); - this.menu.connect('open-state-changed', (menu, open) => { - if (open) this._refreshMenu() - }); + // Initialising the menu with demo item + this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Loading...')); this._refreshIndicator(); - this._refreshMenu(); + this.menu.connect('open-state-changed', (menu, open) => { + if (open) this._refreshMenu() + }); } _refreshIndicator() { @@ -76,9 +79,10 @@ const Valet = GObject.registerClass( } _switchPhp(version) { + const terminal = this._settings.get_string('default-shell').split(' '); try { let proc = Gio.Subprocess.new( - ['x-terminal-emulator', '-e', 'valet', 'use', version], + terminal.concat(['valet', 'use', version]), Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE ); @@ -92,14 +96,14 @@ const Valet = GObject.registerClass( } ) -let valetIndicator = null; +let phpLaravelValet = null; function enable() { - valetIndicator = new Valet(); - Main.panel.addToStatusArea('valet', valetIndicator); + phpLaravelValet = new PhpLaravelValet(); + Main.panel.addToStatusArea('php-laravel-valet', phpLaravelValet); } function disable() { - valetIndicator.destroy(); - valetIndicator = null; + phpLaravelValet.destroy(); + phpLaravelValet = null; } diff --git a/metadata.json b/metadata.json index ecfbc45..edfb588 100644 --- a/metadata.json +++ b/metadata.json @@ -7,6 +7,6 @@ "41", "42" ], - "version": 2, + "version": 3, "url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension" } diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled new file mode 100644 index 0000000000000000000000000000000000000000..f8fdeb9d17f4760a708ac9e89c70283a8417582b GIT binary patch literal 464 zcmZWlJxc^J5RJ-KB4Qz2X(fALHl>B7f)*B5VjJ(q-9R>3lH9S4Ru-0)_XDhK{0p{% zg+E1qfasgtih=`=H+eIY`8Yn;!DyGnU?cFw(l1vBZ3SF@ENW(s?THg{3m!ozwuShD zy>L*RidXO(;6q*2&bL&>hODiqPvoNUE>>OBNvngNla+IAiF=m?m&5p*wLf_Jv=6Lt zuMII5CHN5d>B~O%Jp!Kr2a{b+$^I7d8$1H=zW>;=&i*F!JMca5e0{Ud^Rr(-Ux0a+ zDP8HAO)^i9x?UyQ|gC!rqYb7PNxPBg#)U5K$S;OzXw$R4yc5P!$050mT9j5 literal 0 HcmV?d00001 diff --git a/schemas/org.gnome.shell.extensions.php-laravel-valet.gschema.xml b/schemas/org.gnome.shell.extensions.php-laravel-valet.gschema.xml new file mode 100644 index 0000000..3736dab --- /dev/null +++ b/schemas/org.gnome.shell.extensions.php-laravel-valet.gschema.xml @@ -0,0 +1,20 @@ + + + + + 'right' + Position in Panel + 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 + + + \ No newline at end of file diff --git a/utils.js b/utils.js index 7c3bde3..2c96bad 100644 --- a/utils.js +++ b/utils.js @@ -1,7 +1,11 @@ 'use strict'; const Bytes = imports.byteArray; -const GLib = imports.gi.GLib; +const {GLib, Gio} = imports.gi; +const ExtensionUtils = imports.misc.extensionUtils; +const Me = ExtensionUtils.getCurrentExtension(); + +const _settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.php-laravel-valet'); function safeSpawn(cmd) { try { @@ -11,18 +15,9 @@ function safeSpawn(cmd) { } } -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() { - GLib.spawn_command_line_async('x-terminal-emulator -e valet restart'); -} - -function valetStop() { - GLib.spawn_command_line_async('x-terminal-emulator -e valet stop'); +function shellSpawn(cmd) { + const terminal = _settings.get_string('default-shell'); + GLib.spawn_command_line_async(`${terminal} ${cmd}`); } function phpVersion() { @@ -36,3 +31,17 @@ function phpList() { if (res[3] == 0) return Bytes.toString(res[1]).split('\n').filter(item => !!item).reverse(); return false; } + +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() { + shellSpawn('valet restart'); +} + +function valetStop() { + shellSpawn('valet stop'); +}