Skip to content

Commit

Permalink
Adjusted valet default behaviour that removes unmounted parked paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulhaque committed Apr 16, 2022
1 parent 9f2c38c commit 45b2412
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
28 changes: 16 additions & 12 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
);

Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"41",
"42"
],
"version": 2,
"version": 3,
"url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension"
}
Binary file added schemas/gschemas.compiled
Binary file not shown.
20 changes: 20 additions & 0 deletions schemas/org.gnome.shell.extensions.php-laravel-valet.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.gnome.shell.extensions.php-laravel-valet" path="/org/gnome/shell/extensions/php-laravel-valet/">
<key type="s" name="position-in-panel">
<default>'right'</default>
<summary>Position in Panel</summary>
<description>Position in Panel ('left', 'center', 'right')</description>
</key>
<key type="i" name="panel-box-index">
<default>0</default>
<summary>Index in panel box</summary>
<description>Index within the selected panel box (0: first, 1: second, ..., -1: last)</description>
</key>
<key type="s" name="default-shell">
<default>'x-terminal-emulator -e'</default>
<summary>Default shell to execute extension commands</summary>
<description>Default shell to execute extension commands</description>
</key>
</schema>
</schemalist>
35 changes: 22 additions & 13 deletions utils.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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() {
Expand All @@ -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');
}

0 comments on commit 45b2412

Please sign in to comment.