@@ -27,6 +27,8 @@ import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Ex
2727import { releaseNotes } from './about.js' ;
2828import { KeybindingRow } from './keybinding.js' ;
2929
30+ import { exportConfiguration } from './backup.js' ;
31+
3032let numButtons = 1 ;
3133
3234export default class CustomCommandTogglePreferences extends ExtensionPreferences {
@@ -55,28 +57,10 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
5557
5658 const groups = [ ] ;
5759
58- // Group 1: Commands
59- const group1 = new Adw . PreferencesGroup ( {
60- title : _ ( 'Commands' ) ,
61- //description: _('Enter commands to run when the toggle button is switched.'),
62- } ) ;
63- page . add ( group1 ) ;
64- groups . push ( group1 ) ;
65-
66- const entryRow1 = new Adw . EntryRow ( {
67- title : _ ( 'Toggle ON command:' ) ,
68- } ) ;
69- group1 . add ( entryRow1 ) ;
70-
71- const entryRow2 = new Adw . EntryRow ( {
72- title : _ ( 'Toggle OFF command:' ) ,
73- } ) ;
74- group1 . add ( entryRow2 ) ;
75-
76- // Group 2: Appearance
60+
61+ //#region Appearance
7762 const group2 = new Adw . PreferencesGroup ( {
7863 title : _ ( 'Appearance' ) ,
79- //description: _('Customize the toggle button name and icon.'),
8064 } ) ;
8165 page . add ( group2 ) ;
8266 groups . push ( group2 ) ;
@@ -90,32 +74,84 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
9074 title : _ ( 'Icon:' ) ,
9175 } ) ;
9276 group2 . add ( entryRow4 ) ;
77+ //#endregion Appearance
78+
79+
80+ //#region Commands
81+ const group1 = new Adw . PreferencesGroup ( {
82+ title : _ ( 'Commands' ) ,
83+ } ) ;
84+ page . add ( group1 ) ;
85+ groups . push ( group1 ) ;
86+
87+ const entryRow1 = new Adw . EntryRow ( {
88+ title : _ ( 'Toggle ON command:' ) ,
89+ } ) ;
90+ group1 . add ( entryRow1 ) ;
9391
94- // Group 3: Startup Behavior
92+ const entryRow2 = new Adw . EntryRow ( {
93+ title : _ ( 'Toggle OFF command:' ) ,
94+ } ) ;
95+ group1 . add ( entryRow2 ) ;
96+ //#endregion Commands
97+
98+
99+ //#region Startup Behavior
95100 const group3 = new Adw . PreferencesGroup ( {
96101 title : _ ( 'Startup Behavior' ) ,
97102 } ) ;
98103 page . add ( group3 ) ;
99104 groups . push ( group3 ) ;
100105
101106 const optionList = new Gtk . StringList ( ) ;
102- [ _ ( 'On' ) , _ ( 'Off' ) , _ ( 'Previous state' ) ] . forEach ( choice => optionList . append ( choice ) ) ;
103-
107+ [ _ ( 'On' ) , _ ( 'Off' ) , _ ( 'Previous state' ) , _ ( 'Command output' ) ] . forEach ( choice => optionList . append ( choice ) ) ;
104108 const comboRow = new Adw . ComboRow ( {
105109 title : _ ( 'Initial State' ) ,
106110 subtitle : _ ( 'State of the toggle button at login/startup' ) ,
107111 model : optionList ,
108112 selected : window . _settings . get_int ( `initialtogglestate${ pageIndex } -setting` ) ,
109113 } ) ;
110114 group3 . add ( comboRow ) ;
111-
115+
116+ const checkCommandInfo = new Adw . ActionRow ( {
117+ subtitle : _ (
118+ 'Enter a command below to check its output. If the specified Search Term appears in the command output, ' +
119+ 'the button will be set to ON at startup. Otherwise, the button will be set to OFF.'
120+ ) ,
121+ activatable : false ,
122+ } ) ;
123+ checkCommandInfo . visible = comboRow . selected === 3 ;
124+ group3 . add ( checkCommandInfo ) ;
125+
126+ const checkCommandRow = new Adw . EntryRow ( {
127+ title : _ ( "Command to Check:" ) ,
128+ } ) ;
129+ checkCommandRow . visible = comboRow . selected === 3 ;
130+ group3 . add ( checkCommandRow ) ;
131+
132+ const checkRegexRow = new Adw . EntryRow ( {
133+ title : _ ( "Search Term:" ) ,
134+ } ) ;
135+ checkRegexRow . visible = comboRow . selected === 3 ;
136+ group3 . add ( checkRegexRow ) ;
137+
138+ comboRow . connect ( "notify::selected" , ( ) => {
139+ checkCommandInfo . visible = comboRow . selected === 3 ;
140+ checkCommandRow . visible = comboRow . selected === 3 ;
141+ checkRegexRow . visible = comboRow . selected === 3 ;
142+ expanderRow . visible = comboRow . selected === 0 || comboRow . selected === 1 || comboRow . selected === 2 ;
143+ spinRow2 . visible = comboRow . selected === 3 ;
144+ } ) ;
145+
112146 const expanderRow = new Adw . ExpanderRow ( {
113147 title : _ ( 'Run Command at Startup' ) ,
114148 subtitle : _ ( 'Run associated toggle command at login/startup' ) ,
115149 show_enable_switch : true ,
116150 expanded : window . _settings . get_boolean ( `runcommandatboot${ pageIndex } -setting` ) ,
117151 enable_expansion : window . _settings . get_boolean ( `runcommandatboot${ pageIndex } -setting` ) ,
118152 } ) ;
153+ expanderRow . visible = comboRow . selected === 0 || comboRow . selected === 1 || comboRow . selected === 2 ;
154+
119155 expanderRow . connect ( 'notify::expanded' , widget => {
120156 expanderRow . enable_expansion = widget . expanded ;
121157 } ) ;
@@ -124,8 +160,7 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
124160 const spinRow = new Adw . SpinRow ( {
125161 title : _ ( 'Delay Time (seconds)' ) ,
126162 subtitle : _ ( 'Amount of time to delay command from running after startup \n' +
127- '(it may be required to allow other processes to finish loading before running the command)' ) ,
128- value : window . _settings . get_int ( `initialtogglestate${ pageIndex } -setting` ) ,
163+ '(it may be required to allow other processes to finish loading before running the command)' ) ,
129164 adjustment : new Gtk . Adjustment ( {
130165 lower : 0 ,
131166 upper : 10 ,
@@ -135,7 +170,23 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
135170 } ) ;
136171 expanderRow . add_row ( spinRow ) ;
137172
138- // Group 4: Toggle Behavior
173+ const spinRow2 = new Adw . SpinRow ( {
174+ title : _ ( 'Delay Time (seconds)' ) ,
175+ subtitle : _ ( 'Amount of time to delay command from running after startup \n' +
176+ '(it may be required to allow other processes to finish loading before running the command)' ) ,
177+ adjustment : new Gtk . Adjustment ( {
178+ lower : 0 ,
179+ upper : 10 ,
180+ step_increment : 1 ,
181+ page_increment : 1 ,
182+ } ) ,
183+ } ) ;
184+ spinRow2 . visible = comboRow . selected === 3 ;
185+ group3 . add ( spinRow2 ) ;
186+ //#endregion Startup Behavior
187+
188+
189+ //#region Toggle Behavior
139190 const group4 = new Adw . PreferencesGroup ( {
140191 title : _ ( 'Toggle Behavior' ) ,
141192 } ) ;
@@ -164,6 +215,18 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
164215 group4 . add ( comboRow2 ) ;
165216 page . add ( group4 ) ;
166217
218+ const switchRow3 = new Adw . SwitchRow ( {
219+ title : _ ( 'Check Command Exit Code' ) ,
220+ subtitle : _ ( 'Only toggle if the command executes succussfully (returns exit code 0)' ) ,
221+ active : window . _settings . get_boolean ( `checkexitcode${ pageIndex } -setting` ) ,
222+ } ) ;
223+ group4 . add ( switchRow3 ) ;
224+ switchRow3 . visible = comboRow2 . selected === 2 ;
225+
226+ comboRow2 . connect ( "notify::selected" , ( ) => {
227+ switchRow3 . visible = comboRow2 . selected === 2 ;
228+ } ) ;
229+
167230 const switchRow = new Adw . SwitchRow ( {
168231 title : _ ( 'Show Indicator Icon' ) ,
169232 subtitle : _ ( 'Show top bar icon when toggle button is switched on' ) ,
@@ -176,37 +239,46 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
176239 subtitle : _ ( 'Close quick settings menu immediately after clicking toggle button' ) ,
177240 active : window . _settings . get_boolean ( `closemenu${ pageIndex } -setting` ) ,
178241 } ) ;
179- group4 . add ( switchRow2 ) ;
242+ group4 . add ( switchRow2 ) ;
243+ //#endregion Toggle Behavior
180244
181- // Bindings
245+
246+ //#region Bindings
182247 let i = pageIndex ;
183248 if ( pageIndex === 1 ) { i = '' ; }
184249
185250 window . _settings . bind ( `entryrow1${ i } -setting` , entryRow1 , 'text' , Gio . SettingsBindFlags . DEFAULT ) ;
186251 window . _settings . bind ( `entryrow2${ i } -setting` , entryRow2 , 'text' , Gio . SettingsBindFlags . DEFAULT ) ;
187252 window . _settings . bind ( `entryrow3${ i } -setting` , entryRow3 , 'text' , Gio . SettingsBindFlags . DEFAULT ) ;
188253 window . _settings . bind ( `entryrow4${ i } -setting` , entryRow4 , 'text' , Gio . SettingsBindFlags . DEFAULT ) ;
189-
254+
255+ window . _settings . bind ( `checkcommand${ pageIndex } -setting` , checkCommandRow , "text" , Gio . SettingsBindFlags . DEFAULT ) ;
256+ window . _settings . bind ( `checkregex${ pageIndex } -setting` , checkRegexRow , "text" , Gio . SettingsBindFlags . DEFAULT ) ;
190257 window . _settings . bind ( `initialtogglestate${ pageIndex } -setting` , comboRow , 'selected' , Gio . SettingsBindFlags . DEFAULT ) ;
191258 window . _settings . bind ( `runcommandatboot${ pageIndex } -setting` , expanderRow , 'expanded' , Gio . SettingsBindFlags . DEFAULT ) ;
192259 window . _settings . bind ( `delaytime${ pageIndex } -setting` , spinRow , 'value' , Gio . SettingsBindFlags . DEFAULT ) ;
260+ window . _settings . bind ( `checkcommanddelaytime${ pageIndex } -setting` , spinRow2 , 'value' , Gio . SettingsBindFlags . DEFAULT ) ;
193261 window . _settings . bind ( `showindicator${ pageIndex } -setting` , switchRow , 'active' , Gio . SettingsBindFlags . DEFAULT ) ;
194262 window . _settings . bind ( `closemenu${ pageIndex } -setting` , switchRow2 , 'active' , Gio . SettingsBindFlags . DEFAULT ) ;
263+ window . _settings . bind ( `checkexitcode${ pageIndex } -setting` , switchRow3 , 'active' , Gio . SettingsBindFlags . DEFAULT ) ;
195264 window . _settings . bind ( `buttonclick${ pageIndex } -setting` , comboRow2 , 'selected' , Gio . SettingsBindFlags . DEFAULT ) ;
265+ //#endregion Bindings
196266
197267 // Push the created page to the pages array
198268 pages . push ( page ) ;
199- }
269+
270+ } // End of for loop to create toggle button settings pages
200271
201272
202- // Information Page
273+ //#region Information Page
203274 const infoPage = new Adw . PreferencesPage ( {
204275 title : _ ( 'Configuration' ) ,
205276 icon_name : 'applications-system-symbolic' ,
206277 } ) ;
207278 window . add ( infoPage ) ;
279+ //#endregion Information Page
208280
209- // Group 0: Settings
281+ //#region Settings
210282 const configGroup0 = new Adw . PreferencesGroup ( {
211283 title : _ ( 'Settings' ) ,
212284 } ) ;
@@ -226,13 +298,24 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
226298 configGroup0 . add ( spinRow0 ) ;
227299
228300 window . _settings . bind ( 'numbuttons-setting' , spinRow0 , 'value' , Gio . SettingsBindFlags . DEFAULT ) ;
301+
302+ const exportRow = new Adw . ActionRow ( {
303+ title : _ ( 'Export Toggle Settings' ) ,
304+ subtitle : _ ( `Click to export toggles.ini backup file to user's home directory` ) ,
305+ activatable : true ,
306+ } ) ;
307+ exportRow . connect ( 'activated' , ( ) => {
308+ exportConfiguration ( numButtons , window . _settings , window ) ;
309+ } ) ;
310+ configGroup0 . add ( exportRow ) ;
311+ //#endregion Settings
312+
229313
230- // Group 1: Resources
314+ //#region Resources
231315 const configGroup1 = new Adw . PreferencesGroup ( {
232316 title : _ ( 'Resources' ) ,
233317 } ) ;
234318
235-
236319 const configRow2 = new Adw . ActionRow ( {
237320 title : _ ( 'Icons' ) ,
238321 subtitle : _ (
@@ -263,8 +346,10 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
263346 } ) ;
264347 configRow4 . add_prefix ( new Gtk . Image ( { icon_name : 'folder-symbolic' } ) ) ;
265348 configRow4 . add_suffix ( new Gtk . Image ( { icon_name : 'go-next-symbolic' } ) ) ;
349+ //#endregion Resources
350+
266351
267- // Group: About
352+ //#region About
268353 const aboutGroup = new Adw . PreferencesGroup ( {
269354 title : _ ( 'About' ) ,
270355 } ) ;
@@ -319,6 +404,7 @@ export default class CustomCommandTogglePreferences extends ExtensionPreferences
319404 aboutGroup . add ( aboutRow0 ) ;
320405 aboutGroup . add ( aboutRow1 ) ;
321406 aboutGroup . add ( aboutRow2 ) ;
407+ //#endregion About
322408
323409 }
324410}
0 commit comments