Skip to content

Commit bc10a18

Browse files
authored
Squash fix review findings v25
* Fix review findings * Fix review findings * Update version * Update version
1 parent 0b7b291 commit bc10a18

File tree

3 files changed

+72
-61
lines changed

3 files changed

+72
-61
lines changed

extension.js

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ const POSITIONS = {
1212

1313
export default class Executor extends Extension {
1414
enable() {
15-
log('Executor enabled');
15+
console.log('Executor enabled');
1616

1717
if (!this.cancellable) {
1818
this.cancellable = new Gio.Cancellable();
1919
}
2020

21+
this.timeoutSourceIds = []
2122
this.stopped = false;
2223
this.settings = this.getSettings();
2324
this.executeQueue = [];
@@ -47,9 +48,11 @@ export default class Executor extends Extension {
4748
() => {
4849
if (this.settings.get_value('click-on-output-active').deep_unpack()) {
4950
this.settings.set_int('location', position);
50-
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
51-
this.openPreferences();
52-
});
51+
this.timeoutSourceIds.push(
52+
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
53+
this.openPreferences();
54+
})
55+
);
5356
}
5457
}
5558
);
@@ -112,7 +115,14 @@ export default class Executor extends Extension {
112115
this.executeQueue = null;
113116
this.locations = null;
114117

115-
log('Executor stopped');
118+
if (this.timeoutSourceIds.length > 0) {
119+
this.timeoutSourceIds.forEach((sourceId) => {
120+
GLib.Source.remove(sourceId);
121+
sourceId = null;
122+
});
123+
}
124+
125+
console.log('Executor stopped');
116126
}
117127

118128
initOutputLabels(location) {
@@ -164,7 +174,7 @@ export default class Executor extends Extension {
164174
try {
165175
location.commandsSettings = JSON.parse(json);
166176
} catch (e) {
167-
log('Error in json file for location: ' + location.name);
177+
console.log('Error in json file for location: ' + location.name);
168178
}
169179

170180
this.initOutputLabels(location);
@@ -186,7 +196,7 @@ export default class Executor extends Extension {
186196

187197
this.resetOutput(location);
188198
} else {
189-
log('No commands specified: ' + location.name);
199+
console.log('No commands specified: ' + location.name);
190200
location.commandsOutput = [];
191201
this.resetOutput(location);
192202
}
@@ -198,10 +208,12 @@ export default class Executor extends Extension {
198208
this.executeQueue = [];
199209
this.handleCurrentQueue(copy);
200210
} else {
201-
GLib.timeout_add(0, 500, () => {
202-
this.checkQueue();
203-
return GLib.SOURCE_REMOVE;
204-
});
211+
this.timeoutSourceIds.push(
212+
GLib.timeout_add(0, 500, () => {
213+
this.checkQueue();
214+
return GLib.SOURCE_REMOVE;
215+
})
216+
);
205217
}
206218
}
207219

@@ -211,12 +223,14 @@ export default class Executor extends Extension {
211223
this.execCommand(current, ['bash', '-c', current.command]);
212224

213225
if (copy.length > 0) {
214-
GLib.timeout_add(0, 50, () => {
215-
if (copy.length > 0) {
216-
this.handleCurrentQueue(copy);
217-
}
218-
return GLib.SOURCE_REMOVE;
219-
});
226+
this.timeoutSourceIds.push(
227+
GLib.timeout_add(0, 50, () => {
228+
if (copy.length > 0) {
229+
this.handleCurrentQueue(copy);
230+
}
231+
return GLib.SOURCE_REMOVE;
232+
})
233+
);
220234
} else if (!this.stopped) {
221235
this.checkQueue();
222236
}
@@ -238,7 +252,7 @@ export default class Executor extends Extension {
238252
if (!proc.get_successful()) {
239253
let status = proc.get_exit_status();
240254

241-
log(
255+
console.log(
242256
'Executor: error in command "' +
243257
command.command +
244258
'": ' +
@@ -278,7 +292,7 @@ export default class Executor extends Extension {
278292

279293
let locationIndex = Object.keys(POSITIONS).find((key) => POSITIONS[key] === command.locationName);
280294

281-
if (!this.locations[locationIndex].stopped) {
295+
if (!this.stopped && !this.locations[locationIndex].stopped) {
282296
if (!this.locations[locationIndex].commandsSettings.commands.some((c) => c.uuid === command.uuid)) {
283297
this.locations[locationIndex].commandsOutput.splice(index, 1);
284298
} else {
@@ -291,22 +305,24 @@ export default class Executor extends Extension {
291305
this.locations[locationIndex].commandsOutput = [];
292306
}
293307

294-
GLib.timeout_add_seconds(0, command.interval, () => {
295-
if (this.cancellable && !this.cancellable.is_cancelled()) {
296-
if (!this.stopped && !this.locations[locationIndex].stopped) {
297-
if (!this.executeQueue.some((c) => c.uuid === command.uuid)) {
298-
this.executeQueue.push(command);
308+
this.timeoutSourceIds.push(
309+
GLib.timeout_add_seconds(0, command.interval, () => {
310+
if (this.cancellable && !this.cancellable.is_cancelled()) {
311+
if (!this.stopped && !this.locations[locationIndex].stopped) {
312+
if (!this.executeQueue.some((c) => c.uuid === command.uuid)) {
313+
this.executeQueue.push(command);
314+
}
299315
}
300316
}
301-
}
302317

303-
return GLib.SOURCE_REMOVE;
304-
});
318+
return GLib.SOURCE_REMOVE;
319+
})
320+
);
305321
}
306322
try {
307323
this.setOutput(this.locations[locationIndex], command.index);
308324
} catch (e) {
309-
log('Caught exception while setting output: ' + e);
325+
console.log('Caught exception while setting output: ' + e);
310326
}
311327
}
312328
}

metadata.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
2-
"name": "Executor",
3-
"description": "Execute multiple shell commands periodically with separate intervals and display the output in gnome top bar.",
4-
"uuid": "[email protected]",
5-
"settings-schema": "org.gnome.shell.extensions.executor",
6-
"shell-version": ["45"],
7-
"url": "https://github.com/raujonas/executor",
8-
"version": 24
2+
"name": "Executor",
3+
"description": "Execute multiple shell commands periodically with separate intervals and display the output in gnome top bar.",
4+
"uuid": "[email protected]",
5+
"settings-schema": "org.gnome.shell.extensions.executor",
6+
"shell-version": [
7+
"45"
8+
],
9+
"url": "https://github.com/raujonas/executor",
10+
"version": 25
911
}

prefs.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class ExecutorPreferences extends ExtensionPreferences {
1717
2: _('Right'),
1818
};
1919

20-
this.settings = this.getSettings();
20+
const settings = this.getSettings();
2121

2222
let prefsWidget = new Gtk.Grid({visible: true, column_homogeneous: true});
2323
this.notebook = new Gtk.Notebook({visible: true});
@@ -31,12 +31,12 @@ export default class ExecutorPreferences extends ExtensionPreferences {
3131
this.commandsArrayCopy[position] = [];
3232
try {
3333
this.commandsArray[position] = JSON.parse(
34-
this.settings.get_value(POSITIONS[position] + '-commands-json').deep_unpack()
34+
settings.get_value(POSITIONS[position] + '-commands-json').deep_unpack()
3535
).commands;
3636
this.commandsArrayCopy[position] = JSON.parse(JSON.stringify(this.commandsArray[position]));
3737
} catch (e) {
38-
log('Error in json file for position:', POSITIONS[position]);
39-
this.settings.set_string(
38+
console.log('Error in json file for position:', POSITIONS[position]);
39+
settings.set_string(
4040
POSITIONS[position] + '-commands-json',
4141
'{"commands":[{"command":"echo Executor works!","interval":1}]}'
4242
);
@@ -64,9 +64,14 @@ export default class ExecutorPreferences extends ExtensionPreferences {
6464
valign: Gtk.Align.CENTER,
6565
hexpand: true,
6666
});
67-
active.set_active(this.settings.get_value(POSITIONS[position] + '-active').deep_unpack());
67+
active.set_active(settings.get_value(POSITIONS[position] + '-active').deep_unpack());
6868
active.connect('notify::active', () => {
69-
this.activeClicked(active.get_active());
69+
let position = this.notebook.get_current_page();
70+
if (active.get_active()) {
71+
this.saveCommands(settings);
72+
}
73+
74+
settings.set_boolean(POSITIONS[position] + '-active', active.get_active());
7075
});
7176
let index = new Gtk.SpinButton({
7277
adjustment: new Gtk.Adjustment({lower: 0, upper: 10, step_increment: 1}),
@@ -133,7 +138,7 @@ export default class ExecutorPreferences extends ExtensionPreferences {
133138
this.commandsArray[position] = JSON.parse(JSON.stringify(this.commandsArrayCopy[position]));
134139
this.populateCommandList(position);
135140
});
136-
saveButton.connect('clicked', this.saveCommands.bind(this));
141+
saveButton.connect('clicked', this.saveCommands.bind(this, settings));
137142
buttonsHbox.append(addButton);
138143
buttonsHbox.append(cancelButton);
139144
buttonsHbox.append(saveButton);
@@ -142,7 +147,7 @@ export default class ExecutorPreferences extends ExtensionPreferences {
142147
let pos = postrans[position];
143148
this.notebook.append_page(grid, new Gtk.Label({label: _(pos), visible: true, hexpand: true}));
144149

145-
this.settings.bind(POSITIONS[position] + '-index', index, 'value', Gio.SettingsBindFlags.DEFAULT);
150+
settings.bind(POSITIONS[position] + '-index', index, 'value', Gio.SettingsBindFlags.DEFAULT);
146151
}
147152

148153
/* General tab */
@@ -167,9 +172,9 @@ export default class ExecutorPreferences extends ExtensionPreferences {
167172
valign: Gtk.Align.CENTER,
168173
hexpand: true,
169174
});
170-
clickOnOutputActive.set_active(this.settings.get_value('click-on-output-active').deep_unpack());
175+
clickOnOutputActive.set_active(settings.get_value('click-on-output-active').deep_unpack());
171176
clickOnOutputActive.connect('notify::active', () => {
172-
this.clickOnOutputActiveClicked(clickOnOutputActive.get_active());
177+
settings.set_boolean('click-on-output-active', clickOnOutputActive.get_active());
173178
});
174179
topHbox.append(
175180
new Gtk.Label({label: _('Click on output in top bar active:'), use_markup: true, visible: true})
@@ -179,9 +184,9 @@ export default class ExecutorPreferences extends ExtensionPreferences {
179184
this.notebook.append_page(grid, new Gtk.Label({label: _('General'), visible: true, hexpand: true}));
180185
/* End of general tab */
181186

182-
this.notebook.set_current_page(this.settings.get_value('location').deep_unpack());
187+
this.notebook.set_current_page(settings.get_value('location').deep_unpack());
183188
this.notebook.connect('switch-page', (notebook, page, index) => {
184-
this.settings.set_int('location', index);
189+
settings.set_int('location', index);
185190
});
186191
return prefsWidget;
187192
}
@@ -291,7 +296,7 @@ export default class ExecutorPreferences extends ExtensionPreferences {
291296
array.splice(toIndex, 0, element);
292297
}
293298

294-
saveCommands() {
299+
saveCommands(settings) {
295300
let position = this.notebook.get_current_page();
296301
this.commandsArray[position].splice(0, this.commandsArray[position].length);
297302

@@ -321,7 +326,7 @@ export default class ExecutorPreferences extends ExtensionPreferences {
321326
}
322327

323328
this.commandsArrayCopy[position] = JSON.parse(JSON.stringify(this.commandsArray[position]));
324-
this.settings.set_string(
329+
settings.set_string(
325330
POSITIONS[position] + '-commands-json',
326331
'{"commands":' + JSON.stringify(this.commandsArray[position]) + '}'
327332
);
@@ -335,16 +340,4 @@ export default class ExecutorPreferences extends ExtensionPreferences {
335340
});
336341
}
337342

338-
activeClicked(isActive) {
339-
let position = this.notebook.get_current_page();
340-
if (isActive) {
341-
this.saveCommands();
342-
}
343-
344-
this.settings.set_boolean(POSITIONS[position] + '-active', isActive);
345-
}
346-
347-
clickOnOutputActiveClicked(isActive) {
348-
this.settings.set_boolean('click-on-output-active', isActive);
349-
}
350343
}

0 commit comments

Comments
 (0)