Skip to content

Commit 0048844

Browse files
committed
version 10 updates
1 parent eca2f9e commit 0048844

16 files changed

+66
-21
lines changed

README.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ Custom Command Toggle is an extension for GNOME 45/46/47/48 to create fully cust
66

77
<br>
88

9-
![Screenshot-main](screenshots/screenshot-main-5.png)
9+
![Screenshot-main](screenshots/screenshot-main-10.png)
1010

1111
<br>
1212

1313
## Features:
1414

15-
- Run terminal commands and launch custom scripts using quick toggle buttons.
15+
- Run commands and launch custom scripts using quick toggle buttons.
1616
- Assign custom button names and icons.
17-
- Enter separate commands to run when the button is switched on and when it is switched off.
1817
- Run a command at startup to determine the button's initial state based on the command output, or manually specify whether the button starts as on, off, or in its last known state.
1918
- Run associated on or off command at startup to sync button state if required.
19+
- Keep button states synced to a command's output.
2020
- Option to toggle the button only if the command executes successfully and returns exit code 0 (for use with sudo commands using `pkexec sudo` where the command could be canceled or incorrect password entered).
2121
- Customize toggle button behavior to toggle or be in an always on or off state.
2222
- Assign keyboard shortcuts to quick toggle buttons.
@@ -63,35 +63,37 @@ There is also an option to export the current configuration for all the toggle b
6363

6464
<br>
6565

66-
### Appearance
66+
### Icons
6767

68-
Enter the name and icon information to use for the quick toggle button.
68+
Enter the button name and icon information for each toggle button.
6969

7070
![Screenshot-appearance](screenshots/Screenshot-appearance.png)
7171

7272
**For a list of available symbolic icons to use refer to:**
73-
- [GNOME default icons](https://github.com/StorageB/icons/blob/main/GNOME46Adwaita/icons.md)
73+
- [GNOME default icons](https://github.com/StorageB/icons/blob/main/GNOME48Adwaita/icons.md)
7474
- [Ubuntu Yaru icons](https://github.com/StorageB/icons/blob/main/Yaru/icons.md)
7575

76-
Alternatively, browse the icon directory for your system’s theme (typically /usr/share/icons), or use the [Icon Library app](https://flathub.org/apps/org.gnome.design.IconLibrary).
76+
Alternatively, browse the icon directory for your system’s theme (typically /usr/share/icons) and enter the name of an icon (without the file extension).
7777

78-
To use a custom icon, place an SVG icon in: `~/.local/share/icons/hicolor/scalable/apps/`. Reboot and then enter the icon name (without the file extension).
78+
To use a custom icon, place the icon in: `~/.local/share/icons/`. Reboot and then enter the icon name (without the file extension).
79+
80+
To use separate on/off icons, enter both icon names separated by a comma.
7981

8082
<br>
8183

8284
### Commands
8385

8486
Enter the terminal/shell commands to associate with the quick toggle on/off actions.
8587

86-
![Screenshot-commands](screenshots/Screenshot-commands.png)
88+
![Screenshot-commands](screenshots/screenshot-commands-10.png)
8789

8890
Command tips:
8991
- Run multiple commands in parallel by using `&` between commands.
9092
- Run multiple commands one at a time using `&&` between commands.
91-
- Commands run silently (no terminal output), so test the full command in a terminal before adding it to the menu.
93+
- Commands run silently (no terminal output), so test them in a terminal before using.
9294
- To run a command in a terminal window, use `gnome-terminal -- command`. Note that by default the GNOME terminal will close after the command is complete, but that can be changed in the terminal preferences if needed.
9395
- For sudo commands that require a password, use `pkexec` before the command to get a password prompt. For example, `pkexec sudo command` prompts for your password and then runs the command. Alternatively, use `gnome-terminal -- sudo command` to open a terminal where you can enter your password.
94-
- To open the command configuration window for this extension directly, use the command `gnome-extensions prefs custom-command-list@storageb.github.com`.
96+
- To open the command configuration window for this extension directly, use the command `gnome-extensions prefs custom-command-toggle@storageb.github.com`.
9597

9698
<br>
9799

@@ -100,27 +102,49 @@ Command tips:
100102

101103
Specify the state of each toggle button at startup (on, off, the previous state it was in, or check a command's output to determine the state), and select if you want that command to run at startup to sync to the selected toggle state.
102104

103-
![Screenshot-appearance](screenshots/Screenshot-startup.png)
105+
![Screenshot-startup](screenshots/Screenshot-startup.png)
104106

105107
If "Run Command at Startup" is selected, there is an option to specify a delay time before the command is executed. Because GNOME extensions load early in the startup process, it may be required to delay your command from running by a few seconds to allow other processes to finish loading first. If this is not required, set the delay to 0.
106108

107-
If "Command output" is selected as the Initial State, Enter a command to check its output. If the specified Search Term appears in the command output, the button will be set to ON at startup. Otherwise, the button will be OFF at startup.
109+
If "Command output" is selected as the Initial State, enter a command to check its output. If the specified Search Term appears in the command output, the button will be set to ON at startup. Otherwise, the button will be OFF at startup.
110+
111+
Enable "Keep Toggle State Synced" to periodically check the output of a command and update the button state accordingly. Set "Polling Frequency" to specify how often the command should run in the background.
108112

109-
![Screenshot-appearance](screenshots/screenshot-startup-2.png)
113+
![Screenshot-startup-command](screenshots/screenshot-startup-command-10.png)
110114

111115

112116
<br>
113117

114118
### Toggle Behavior
115119

116-
Assign keyboard shortcuts for each button, and specify how the button and menu behave when the button is clicked.
120+
Specify how the button and menu behave when the button is clicked.
117121

118-
![Screenshot-appearance](screenshots/screenshot-toggle-2.png)
122+
![Screenshot-toggle](screenshots/screenshot-toggle-10.png)
119123

120124
If using `pkexec` or `gnome-terminal -- command` to run sudo commands, it is recommended to enable Check Command Exit Code so that if an incorrect password is entered or the command is canceled, the button will not toggle if the command does not run.
121125

122126
<br>
123127

128+
### Keyboard Shortcuts
129+
130+
Assign keyboard shortcuts to toggle buttons.
131+
132+
![Screenshot-shortcuts](screenshots/screenshot-shortcuts-10.png)
133+
134+
<br>
135+
136+
### Advanced
137+
138+
In the Configuration tab under Advanced, enable "Detailed Logging" to view extension and command output for toggle button and command sync setup and troubleshooting purposes. Run the following command in a terminal to view the output (click the copy button to copy the command):
139+
140+
`journalctl -f -o cat /usr/bin/gnome-shell | grep "Custom Command Toggle"`
141+
142+
![Screenshot-advanced](screenshots/screenshot-advanced-10.png)
143+
144+
Caution: Use detailed logging only for troubleshooting purposes. Leaving this option enabled could result in continuous excessive logging.
145+
146+
<br>
147+
124148

125149
## License
126150

extension.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class MyIndicator1 extends SystemIndicator {
9090
if (settings.get_boolean('closemenu1-setting')) {Main.panel.closeQuickSettings();}
9191
if (settings.get_int('buttonclick1-setting') === 2 && settings.get_boolean('checkexitcode1-setting')) {
9292
checkCommandExitCode(1, this.toggle1.checked, entryRow1, entryRow2, (exitCodeResult) => {
93-
if (debug) console.log(`[Custom Command Toggle] Toggle 1 | Exit code status check: ${exitCodeResult ? 'passed' : 'failed'}${exitCodeResult ? '' : ' (toggle state not changed)'}`);
93+
if (debug) console.log(`[Custom Command Toggle] Toggle 1 | Exit code check: ${exitCodeResult ? 'passed' : 'failed'}${exitCodeResult ? '' : ' (toggle state not changed)'}`);
9494
if (!exitCodeResult) {
9595
GObject.signal_handler_block(this.toggle1, this.toggle1ConnectSignal);
9696
this.toggle1.checked = !this.toggle1.checked;
@@ -801,6 +801,7 @@ export default class CustomQuickToggleExtension extends Extension {
801801
if (bytes.get_size() === 0) {
802802
GLib.source_remove(timeoutId);
803803
const output = new TextDecoder().decode(Uint8Array.from(chunks.flat())).trim();
804+
const match = outputMatches(output, checkRegex);
804805

805806
if (debug) {
806807
console.log(`[Custom Command Toggle] Toggle ${toggleNumber} | Command output:`);
@@ -812,12 +813,11 @@ export default class CustomQuickToggleExtension extends Extension {
812813
});
813814
}
814815
console.log(`[Custom Command Toggle] Toggle ${toggleNumber} | Search term: ${checkRegex}`);
815-
console.log(`[Custom Command Toggle] Toggle ${toggleNumber} | Search term found in command output: ${output.includes(checkRegex)} ` +
816-
`(toggle set to ${output.includes(checkRegex) ? 'ON' : 'OFF'})`);
817-
816+
console.log(`[Custom Command Toggle] Toggle ${toggleNumber} | Search term found in command output: ${match} ` +
817+
`(toggle set to ${match ? 'ON' : 'OFF'})`);
818818
}
819819
cleanup();
820-
callback(output.includes(checkRegex));
820+
callback(match);
821821
return;
822822
}
823823

@@ -845,6 +845,27 @@ export default class CustomQuickToggleExtension extends Extension {
845845
callback(false);
846846
}
847847
}//#endregion Check Output
848+
849+
850+
//#region Output match
851+
function outputMatches(output, searchTerm) {
852+
853+
const normalizedOutput = output.toLowerCase();
854+
const normalizedSearch = searchTerm.toLowerCase();
855+
856+
// Remove punctuation (letters, numbers, spaces only)
857+
const cleanedOutput = normalizedOutput.replace(/[^\p{L}\p{N}\s]/gu, ' ').replace(/\s+/g, ' ').trim();
858+
const cleanedSearch = normalizedSearch.replace(/[^\p{L}\p{N}\s]/gu, ' ').replace(/\s+/g, ' ').trim();
859+
860+
const isSingleWord = !cleanedSearch.includes(' ');
861+
if (isSingleWord) {
862+
const regex = new RegExp(`\\b${cleanedSearch}\\b`, 'i');
863+
return regex.test(cleanedOutput);
864+
} else {
865+
return cleanedOutput.includes(cleanedSearch);
866+
}
867+
}
868+
//#endregion Output match
848869

849870

850871
//#region Refresh indicator
-20.5 KB
Binary file not shown.
-7.97 KB
Binary file not shown.

screenshots/Screenshot-toggle.png

-31.5 KB
Binary file not shown.
18 KB
Loading
24.1 KB
Loading
18 KB
Loading

screenshots/screenshot-main-10.png

339 KB
Loading
10.9 KB
Loading

0 commit comments

Comments
 (0)