Skip to content

Commit 082b279

Browse files
committed
Gnome shell 45 support added ✨
1 parent a8c656c commit 082b279

File tree

8 files changed

+108
-64
lines changed

8 files changed

+108
-64
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ A PHP Laravel Valet status indicator and manager extension (GNOME Panel Applet)
66

77
## Supports
88

9-
- Tested on Pop!_OS 21.10 and GNOME Shell V40
9+
|Extension Version|Gnome Shell Version|
10+
|:-:|:-:|
11+
|6|45|
12+
|5|44, 43, 42, 41, 40|
1013

1114
## Prerequisite
1215

extension.js

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
'use strict';
1+
import GObject from 'gi://GObject';
2+
import Gio from 'gi://Gio';
3+
import St from 'gi://St';
4+
import Clutter from 'gi://Clutter';
25

3-
const {GObject, GLib, Gio, St, Clutter} = imports.gi;
4-
const Main = imports.ui.main;
5-
const PanelMenu = imports.ui.panelMenu;
6-
const PopupMenu = imports.ui.popupMenu;
7-
const ExtensionUtils = imports.misc.extensionUtils;
8-
const Me = ExtensionUtils.getCurrentExtension();
9-
const Utils = Me.imports.utils;
6+
import { Extension, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';
7+
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
8+
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
9+
import * as Utils from './utils.js'
10+
11+
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
1012

1113
const PhpLaravelValet = GObject.registerClass(
1214
class PhpLaravelValet extends PanelMenu.Button {
13-
_init() {
14-
super._init(0.0, null, false);
15+
_init(ext) {
16+
super._init(1.0, null, false);
1517

16-
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.php-laravel-valet');
18+
this._extension = ext;
19+
this._settings = ext.getSettings();
20+
this._settings.connect('changed', () => this._refreshIndicator());
1721

18-
this._indicatorText = new St.Label({text: 'Loading...', y_align: Clutter.ActorAlign.CENTER});
22+
this._indicatorText = new St.Label({ text: _('Loading...'), y_align: Clutter.ActorAlign.CENTER });
1923
this.add_actor(this._indicatorText);
2024

21-
// Initialising the menu with demo item
22-
this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Loading...'));
25+
// initializing the menu with demo item
26+
this.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('Loading...')));
2327

2428
this._refreshIndicator();
2529

2630
this.menu.connect('open-state-changed', (menu, open) => {
27-
if (open) this._refreshMenu()
31+
if (open) this._refreshMenu();
2832
});
2933
}
3034

@@ -33,7 +37,7 @@ const PhpLaravelValet = GObject.registerClass(
3337
if (phpVersion) {
3438
this._indicatorText.set_text(phpVersion);
3539
} else {
36-
this._indicatorText.set_text('PHP not found');
40+
this._indicatorText.set_text(_('PHP not found'));
3741
}
3842
}
3943

@@ -47,35 +51,46 @@ const PhpLaravelValet = GObject.registerClass(
4751
this.menu.addMenuItem(new PopupMenu.PopupMenuItem(item.replace(/\.\.\./g, '')));
4852
})
4953
} else {
50-
this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Valet not found'));
54+
this.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('Valet not found')));
5155
}
5256

5357
// menu separator
5458
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
5559

5660
// switch php sub menu
57-
const phpSubMenu = new PopupMenu.PopupSubMenuMenuItem('Switch PHP');
61+
const phpSubMenu = new PopupMenu.PopupSubMenuMenuItem(_('Switch PHP'));
5862
const phpList = Utils.phpList();
5963
if (phpList.length > 0) {
6064
phpList.forEach(item => {
61-
const subMenu = new PopupMenu.PopupMenuItem('Switch to ' + item);
65+
const subMenu = new PopupMenu.PopupMenuItem(_('Switch to ') + item);
6266
subMenu.connect('activate', () => this._switchPhp(item));
6367
phpSubMenu.menu.addMenuItem(subMenu);
6468
})
6569
} else {
66-
phpSubMenu.menu.addMenuItem(new PopupMenu.PopupMenuItem('PHP not found'));
70+
phpSubMenu.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('PHP not found')));
6771
}
6872
this.menu.addMenuItem(phpSubMenu);
6973

7074
// valet start/restart menu
71-
const valetRestart = new PopupMenu.PopupMenuItem('Valet start/restart');
75+
const valetRestart = new PopupMenu.PopupMenuItem(_('Valet start/restart'));
7276
valetRestart.connect('activate', () => Utils.valetRestart());
7377
this.menu.addMenuItem(valetRestart);
7478

7579
// valet stop menu
76-
const valetStop = new PopupMenu.PopupMenuItem('Valet stop');
80+
const valetStop = new PopupMenu.PopupMenuItem(_('Valet stop'));
7781
valetStop.connect('activate', () => Utils.valetStop());
7882
this.menu.addMenuItem(valetStop);
83+
84+
85+
if (this._settings.get_boolean('show-settings')) {
86+
// menu separator
87+
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
88+
89+
// settings menu
90+
const settings = new PopupMenu.PopupMenuItem(_('Settings'));
91+
settings.connect('activate', () => this._extension.openPreferences());
92+
this.menu.addMenuItem(settings);
93+
}
7994
}
8095

8196
_switchPhp(version) {
@@ -94,16 +109,16 @@ const PhpLaravelValet = GObject.registerClass(
94109
}
95110
}
96111
}
97-
)
112+
);
98113

99-
let phpLaravelValet = null;
100-
101-
function enable() {
102-
phpLaravelValet = new PhpLaravelValet();
103-
Main.panel.addToStatusArea('php-laravel-valet', phpLaravelValet);
104-
}
114+
export default class PhpLaravelValetExtension extends Extension {
115+
enable() {
116+
this._indicator = new PhpLaravelValet(this);
117+
Main.panel.addToStatusArea(this.uuid, this._indicator);
118+
}
105119

106-
function disable() {
107-
phpLaravelValet.destroy();
108-
phpLaravelValet = null;
120+
disable() {
121+
this._indicator.destroy();
122+
this._indicator = null;
123+
}
109124
}

metadata.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
"description": "A PHP Laravel Valet status indicator and manager.",
44
"uuid": "php-laravel-valet@rahulhaque",
55
"shell-version": [
6-
"40",
7-
"41",
8-
"42",
9-
"43",
10-
"44"
6+
"45"
117
],
12-
"version": 5,
13-
"url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension"
8+
"version": 6,
9+
"url": "https://github.com/rahulhaque/php-laravel-valet-gnome-shell-extension",
10+
"settings-schema": "org.gnome.shell.extensions.php-laravel-valet"
1411
}

prefs.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Gio from 'gi://Gio';
2+
import Adw from 'gi://Adw';
3+
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
4+
5+
export default class PhpLaravelValetPreferences extends ExtensionPreferences {
6+
fillPreferencesWindow(window) {
7+
// create a preferences page, with a single group
8+
const page = new Adw.PreferencesPage({
9+
title: _('General'),
10+
icon_name: 'dialog-information-symbolic',
11+
});
12+
window.add(page);
13+
14+
// create a preferences group, add to page
15+
const group = new Adw.PreferencesGroup({
16+
title: _('Settings'),
17+
description: _('Configure the settings of the extension'),
18+
});
19+
page.add(group);
20+
21+
// create a new preferences row
22+
const show_settings = new Adw.SwitchRow({
23+
title: _('Show Settings'),
24+
subtitle: _('Whether to show the settings in menu'),
25+
});
26+
group.add(show_settings);
27+
28+
// create a settings object and bind inputs
29+
window._settings = this.getSettings();
30+
window._settings.bind('show-settings', show_settings, 'active', Gio.SettingsBindFlags.DEFAULT);
31+
32+
window.set_default_size(620, 300);
33+
}
34+
}

schemas/gschemas.compiled

-32 Bytes
Binary file not shown.

schemas/org.gnome.shell.extensions.php-laravel-valet.gschema.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
<key type="s" name="position-in-panel">
55
<default>'right'</default>
66
<summary>Position in Panel</summary>
7-
<description>Position in Panel ('left', 'center', 'right')</description>
7+
<description>Position in Panel ('left', 'center', 'right').</description>
88
</key>
99
<key type="i" name="panel-box-index">
1010
<default>0</default>
1111
<summary>Index in panel box</summary>
12-
<description>Index within the selected panel box (0: first, 1: second, ..., -1: last)</description>
13-
</key>
14-
<key type="s" name="default-shell">
15-
<default>'x-terminal-emulator -e'</default>
16-
<summary>Default shell to execute extension commands</summary>
17-
<description>Default shell to execute extension commands</description>
12+
<description>Index within the selected panel box (0: first, 1: second, ..., -1: last).</description>
1813
</key>
14+
<key type="b" name="show-settings">
15+
<default>true</default>
16+
<summary>Show the settings button</summary>
17+
<description>Whether to show the settings button as last entry in the extensions list.</description>
18+
</key>
1919
</schema>
2020
</schemalist>

stylesheet.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Add your custom extension styling here */

utils.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
1-
'use strict';
1+
import GLib from 'gi://GLib';
2+
import Bytes from 'gi://GLib/Bytes';
23

3-
const Bytes = imports.byteArray;
4-
const GLib = imports.gi.GLib;
5-
const ExtensionUtils = imports.misc.extensionUtils;
6-
const Me = ExtensionUtils.getCurrentExtension();
7-
8-
const _settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.php-laravel-valet');
9-
10-
function safeSpawn(cmd) {
4+
export function safeSpawn(cmd) {
115
try {
126
return GLib.spawn_command_line_sync(cmd);
137
} catch (e) {
148
return [false, Bytes.fromString(''), null, null];
159
}
1610
}
1711

18-
function shellSpawn(cmd) {
19-
const terminal = _settings.get_string('default-shell');
12+
export function shellSpawn(cmd) {
13+
const terminal = 'x-terminal-emulator -e';
2014
GLib.spawn_command_line_async(`${terminal} ${cmd}`);
2115
}
2216

23-
function phpVersion() {
17+
export function phpVersion() {
2418
const res = safeSpawn('/bin/bash -c "php -v | grep -Po \'PHP\\s+\\d+.\\d+(?:(.\\d+))?\'"');
2519
if (res[3] == 0) return Bytes.toString(res[1]).replace(/\n$/, '');
2620
return false;
2721
}
2822

29-
function phpList() {
23+
export function phpList() {
3024
const res = safeSpawn('ls /etc/php');
3125
if (res[3] == 0) return Bytes.toString(res[1]).split('\n').filter(item => !!item).reverse();
3226
return false;
3327
}
3428

35-
function valetStatus() {
29+
export function valetStatus() {
3630
const res = safeSpawn('/bin/bash -c "valet --version && valet status"');
3731
if (res[3] == 0) return Bytes.toString(res[1]).split('\n').filter(item => !!item);
3832
return false;
3933
}
4034

41-
function valetRestart() {
35+
export function valetRestart() {
4236
shellSpawn('valet restart');
4337
}
4438

45-
function valetStop() {
39+
export function valetStop() {
4640
shellSpawn('valet stop');
47-
}
41+
}

0 commit comments

Comments
 (0)