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' ;
2
5
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' ;
10
12
11
13
const PhpLaravelValet = GObject . registerClass (
12
14
class PhpLaravelValet extends PanelMenu . Button {
13
- _init ( ) {
14
- super . _init ( 0 .0, null , false ) ;
15
+ _init ( ext ) {
16
+ super . _init ( 1 .0, null , false ) ;
15
17
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 ( ) ) ;
17
21
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 } ) ;
19
23
this . add_actor ( this . _indicatorText ) ;
20
24
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...' ) ) ) ;
23
27
24
28
this . _refreshIndicator ( ) ;
25
29
26
30
this . menu . connect ( 'open-state-changed' , ( menu , open ) => {
27
- if ( open ) this . _refreshMenu ( )
31
+ if ( open ) this . _refreshMenu ( ) ;
28
32
} ) ;
29
33
}
30
34
@@ -33,7 +37,7 @@ const PhpLaravelValet = GObject.registerClass(
33
37
if ( phpVersion ) {
34
38
this . _indicatorText . set_text ( phpVersion ) ;
35
39
} else {
36
- this . _indicatorText . set_text ( 'PHP not found' ) ;
40
+ this . _indicatorText . set_text ( _ ( 'PHP not found' ) ) ;
37
41
}
38
42
}
39
43
@@ -47,35 +51,46 @@ const PhpLaravelValet = GObject.registerClass(
47
51
this . menu . addMenuItem ( new PopupMenu . PopupMenuItem ( item . replace ( / \. \. \. / g, '' ) ) ) ;
48
52
} )
49
53
} else {
50
- this . menu . addMenuItem ( new PopupMenu . PopupMenuItem ( 'Valet not found' ) ) ;
54
+ this . menu . addMenuItem ( new PopupMenu . PopupMenuItem ( _ ( 'Valet not found' ) ) ) ;
51
55
}
52
56
53
57
// menu separator
54
58
this . menu . addMenuItem ( new PopupMenu . PopupSeparatorMenuItem ( ) ) ;
55
59
56
60
// switch php sub menu
57
- const phpSubMenu = new PopupMenu . PopupSubMenuMenuItem ( 'Switch PHP' ) ;
61
+ const phpSubMenu = new PopupMenu . PopupSubMenuMenuItem ( _ ( 'Switch PHP' ) ) ;
58
62
const phpList = Utils . phpList ( ) ;
59
63
if ( phpList . length > 0 ) {
60
64
phpList . forEach ( item => {
61
- const subMenu = new PopupMenu . PopupMenuItem ( 'Switch to ' + item ) ;
65
+ const subMenu = new PopupMenu . PopupMenuItem ( _ ( 'Switch to ' ) + item ) ;
62
66
subMenu . connect ( 'activate' , ( ) => this . _switchPhp ( item ) ) ;
63
67
phpSubMenu . menu . addMenuItem ( subMenu ) ;
64
68
} )
65
69
} else {
66
- phpSubMenu . menu . addMenuItem ( new PopupMenu . PopupMenuItem ( 'PHP not found' ) ) ;
70
+ phpSubMenu . menu . addMenuItem ( new PopupMenu . PopupMenuItem ( _ ( 'PHP not found' ) ) ) ;
67
71
}
68
72
this . menu . addMenuItem ( phpSubMenu ) ;
69
73
70
74
// valet start/restart menu
71
- const valetRestart = new PopupMenu . PopupMenuItem ( 'Valet start/restart' ) ;
75
+ const valetRestart = new PopupMenu . PopupMenuItem ( _ ( 'Valet start/restart' ) ) ;
72
76
valetRestart . connect ( 'activate' , ( ) => Utils . valetRestart ( ) ) ;
73
77
this . menu . addMenuItem ( valetRestart ) ;
74
78
75
79
// valet stop menu
76
- const valetStop = new PopupMenu . PopupMenuItem ( 'Valet stop' ) ;
80
+ const valetStop = new PopupMenu . PopupMenuItem ( _ ( 'Valet stop' ) ) ;
77
81
valetStop . connect ( 'activate' , ( ) => Utils . valetStop ( ) ) ;
78
82
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
+ }
79
94
}
80
95
81
96
_switchPhp ( version ) {
@@ -94,16 +109,16 @@ const PhpLaravelValet = GObject.registerClass(
94
109
}
95
110
}
96
111
}
97
- )
112
+ ) ;
98
113
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
+ }
105
119
106
- function disable ( ) {
107
- phpLaravelValet . destroy ( ) ;
108
- phpLaravelValet = null ;
120
+ disable ( ) {
121
+ this . _indicator . destroy ( ) ;
122
+ this . _indicator = null ;
123
+ }
109
124
}
0 commit comments