-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9f2c38c
Showing
7 changed files
with
862 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# PHP Laravel Valet | ||
|
||
A PHP Laravel Valet status indicator and manager extension (GNOME Panel Applet) for GNOME Shell. | ||
|
||
![Screenshot](./screenshot.png) | ||
|
||
## Supports | ||
|
||
- Tested on Pop!_OS 21.10 and GNOME Shell V40 | ||
|
||
## Prerequisite | ||
|
||
- Properly installed and running [Laravel Valet Linux](https://cpriego.github.io/valet-linux/). | ||
|
||
## Installation | ||
|
||
- Install this extension from [extensions.gnome.org](https://extensions.gnome.org/extension/4985/php-laravel-valet). | ||
|
||
### Or | ||
|
||
- Download the zip from the source. | ||
- Create a folder named `php-laravel-valet@rahulhaque` under `~/.local/share/gnome-shell-extensions` folder and extract all the files in this repo. | ||
- Restart GNOME Shell with **[ALT]** + **[F2]**. Type '**r**' and **[Enter]** | ||
- Or logout and log back in. | ||
|
||
## Credits | ||
|
||
- [Rahul Haque](https://github.com/rahulhaque) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
Licensed under [GNU - General Public License v3](https://www.gnu.org/licenses/gpl-3.0.en.html). Please see the [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'use strict'; | ||
|
||
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; | ||
|
||
const Valet = GObject.registerClass( | ||
class Valet extends PanelMenu.Button { | ||
_init() { | ||
super._init(0.0, null, false); | ||
|
||
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() | ||
}); | ||
|
||
this._refreshIndicator(); | ||
|
||
this._refreshMenu(); | ||
} | ||
|
||
_refreshIndicator() { | ||
const phpVersion = Utils.phpVersion(); | ||
if (phpVersion) { | ||
this._indicatorText.set_text(phpVersion); | ||
} else { | ||
this._indicatorText.set_text('PHP not found'); | ||
} | ||
} | ||
|
||
_refreshMenu() { | ||
this.menu.removeAll(); | ||
|
||
// valet status menu | ||
const valetStatus = Utils.valetStatus(); | ||
if (valetStatus.length > 0) { | ||
valetStatus.forEach(item => { | ||
this.menu.addMenuItem(new PopupMenu.PopupMenuItem(item.replace(/\.\.\./g, ''))); | ||
}) | ||
} else { | ||
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 phpList = Utils.phpList(); | ||
if (phpList.length > 0) { | ||
phpList.forEach(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')); | ||
} | ||
this.menu.addMenuItem(phpSubMenu); | ||
|
||
// valet start/restart menu | ||
const valetRestart = new PopupMenu.PopupMenuItem('Valet start'); | ||
valetRestart.connect('activate', () => Utils.valetRestart()); | ||
this.menu.addMenuItem(valetRestart); | ||
|
||
// valet stop menu | ||
const valetStop = new PopupMenu.PopupMenuItem('Valet stop'); | ||
valetStop.connect('activate', () => Utils.valetStop()); | ||
this.menu.addMenuItem(valetStop); | ||
} | ||
|
||
_switchPhp(version) { | ||
try { | ||
let proc = Gio.Subprocess.new( | ||
['x-terminal-emulator', '-e', 'valet', 'use', version], | ||
Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE | ||
); | ||
|
||
proc.communicate_utf8_async(null, null, (proc, res) => { | ||
if (proc.get_successful()) this._refreshIndicator(); | ||
}); | ||
} catch (e) { | ||
logError(e); | ||
} | ||
} | ||
} | ||
) | ||
|
||
let valetIndicator = null; | ||
|
||
function enable() { | ||
valetIndicator = new Valet(); | ||
Main.panel.addToStatusArea('valet', valetIndicator); | ||
} | ||
|
||
function disable() { | ||
valetIndicator.destroy(); | ||
valetIndicator = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "PHP Laravel Valet", | ||
"description": "A PHP Laravel Valet status indicator and manager.", | ||
"uuid": "php-laravel-valet@rahulhaque", | ||
"shell-version": [ | ||
"40", | ||
"41", | ||
"42" | ||
], | ||
"version": 2, | ||
"url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const Bytes = imports.byteArray; | ||
const GLib = imports.gi.GLib; | ||
|
||
function safeSpawn(cmd) { | ||
try { | ||
return GLib.spawn_command_line_sync(cmd); | ||
} catch (e) { | ||
return [false, Bytes.fromString(''), null, null]; | ||
} | ||
} | ||
|
||
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 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() { | ||
const res = safeSpawn('ls /etc/php'); | ||
if (res[3] == 0) return Bytes.toString(res[1]).split('\n').filter(item => !!item).reverse(); | ||
return false; | ||
} |