Skip to content

Commit df87a1d

Browse files
committed
Add an option to use a custom system monitor
1 parent 7c30221 commit df87a1d

File tree

10 files changed

+153
-37
lines changed

10 files changed

+153
-37
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"log": "readonly",
3232
"logError": "readonly",
3333
"TextDecoder": "readonly",
34-
"Intl": "readonly"
34+
"Intl": "readonly",
35+
"console": "readonly"
3536
}
3637
}

po/messages.pot

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,37 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: gnome-runcat-extension 28\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2024-09-14 13:33+0300\n"
11+
"POT-Creation-Date: 2024-09-14 13:35+0300\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
1515
"Language: \n"
1616
"MIME-Version: 1.0\n"
17-
"Content-Type: text/plain; charset=CHARSET\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20-
#: src/indicator.js:177
20+
#: src/indicator.js:179
2121
msgid "Open System Monitor"
2222
msgstr ""
2323

24-
#: src/indicator.js:181
24+
#: src/indicator.js:189
25+
#, javascript-format
26+
msgid "Execution of “%s” failed"
27+
msgstr ""
28+
29+
#: src/indicator.js:197
2530
msgid "Settings"
2631
msgstr ""
2732

33+
#: src/indicator.js:201
34+
msgid "Failed to open extension settings"
35+
msgstr ""
36+
2837
#: src/prefs.js:54
2938
msgid "RunCat Settings"
3039
msgstr ""
3140

32-
#: src/prefs.js:116
41+
#: src/prefs.js:138
3342
msgid "Version"
3443
msgstr ""
3544

@@ -53,46 +62,54 @@ msgstr ""
5362
msgid "Character only"
5463
msgstr ""
5564

56-
#: src/resources/ui/preferences.ui:31
65+
#: src/resources/ui/preferences.ui:30
66+
msgid "Use a custom system monitor"
67+
msgstr ""
68+
69+
#: src/resources/ui/preferences.ui:33
70+
msgid "Command"
71+
msgstr ""
72+
73+
#: src/resources/ui/preferences.ui:45
5774
msgid "Character"
5875
msgstr ""
5976

60-
#: src/resources/ui/preferences.ui:35
77+
#: src/resources/ui/preferences.ui:49
6178
msgid "Invert speed"
6279
msgstr ""
6380

64-
#: src/resources/ui/preferences.ui:41
81+
#: src/resources/ui/preferences.ui:55
6582
msgid "Idle threshold"
6683
msgstr ""
6784

68-
#: src/resources/ui/preferences.ui:42
85+
#: src/resources/ui/preferences.ui:56
6986
msgid "Available when speed is not inverted"
7087
msgstr ""
7188

72-
#: src/resources/ui/preferences.ui:60
89+
#: src/resources/ui/preferences.ui:74
7390
msgid "Reset preferences"
7491
msgstr ""
7592

76-
#: src/resources/ui/preferences.ui:61
93+
#: src/resources/ui/preferences.ui:75
7794
msgid "Reset RunCat preferences to defaults"
7895
msgstr ""
7996

80-
#: src/resources/ui/preferences.ui:74
97+
#: src/resources/ui/preferences.ui:88
8198
msgid "Reset"
8299
msgstr ""
83100

84-
#: src/resources/ui/preferences.ui:93
101+
#: src/resources/ui/preferences.ui:107
85102
msgid "The cat tells you the CPU usage by running speed"
86103
msgstr ""
87104

88-
#: src/resources/ui/preferences.ui:97
105+
#: src/resources/ui/preferences.ui:111
89106
msgid "Visit RunCat's GitHub page"
90107
msgstr ""
91108

92-
#: src/resources/ui/preferences.ui:107
109+
#: src/resources/ui/preferences.ui:121
93110
msgid "Visit Homepage"
94111
msgstr ""
95112

96-
#: src/resources/ui/preferences.ui:111
113+
#: src/resources/ui/preferences.ui:125
97114
msgid "About RunCat"
98115
msgstr ""

po/ru.po

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: gnome-runcat-extension 20\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2024-03-17 21:28+0300\n"
10+
"POT-Creation-Date: 2024-03-21 00:56+0300\n"
1111
"PO-Revision-Date: 2022-09-30 19:16+0300\n"
1212
"Last-Translator: Sergei Kolesnikov <sergei@kolesnikov.se>\n"
1313
"Language-Team: Russian\n"
@@ -18,19 +18,28 @@ msgstr ""
1818
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
1919
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
2020

21-
#: src/indicator.js:177
21+
#: src/indicator.js:179
2222
msgid "Open System Monitor"
2323
msgstr "Открыть Системный монитор"
2424

25-
#: src/indicator.js:181
25+
#: src/indicator.js:189
26+
#, javascript-format
27+
msgid "Execution of “%s” failed"
28+
msgstr "Не удалось выполнить «%s»"
29+
30+
#: src/indicator.js:197
2631
msgid "Settings"
2732
msgstr "Настройки"
2833

34+
#: src/indicator.js:201
35+
msgid "Failed to open extension settings"
36+
msgstr "Не удалось открыть настройки расширения"
37+
2938
#: src/prefs.js:54
3039
msgid "RunCat Settings"
3140
msgstr "Настройки RunCat"
3241

33-
#: src/prefs.js:116
42+
#: src/prefs.js:138
3443
msgid "Version"
3544
msgstr "Версия"
3645

@@ -54,48 +63,56 @@ msgstr "Только проценты"
5463
msgid "Character only"
5564
msgstr "Только персонаж"
5665

57-
#: src/resources/ui/preferences.ui:31
66+
#: src/resources/ui/preferences.ui:30
67+
msgid "Use a custom system monitor"
68+
msgstr "Использовать пользовательский системный монитор"
69+
70+
#: src/resources/ui/preferences.ui:33
71+
msgid "Command"
72+
msgstr "Команда"
73+
74+
#: src/resources/ui/preferences.ui:45
5875
msgid "Character"
5976
msgstr "Персонаж"
6077

61-
#: src/resources/ui/preferences.ui:35
78+
#: src/resources/ui/preferences.ui:49
6279
msgid "Invert speed"
6380
msgstr "Инвертировать скорость"
6481

65-
#: src/resources/ui/preferences.ui:41
82+
#: src/resources/ui/preferences.ui:55
6683
msgid "Idle threshold"
6784
msgstr "Порог бездействия"
6885

69-
#: src/resources/ui/preferences.ui:42
86+
#: src/resources/ui/preferences.ui:56
7087
msgid "Available when speed is not inverted"
7188
msgstr "Доступен, когда скорость не инвертирована"
7289

73-
#: src/resources/ui/preferences.ui:60
90+
#: src/resources/ui/preferences.ui:74
7491
msgid "Reset preferences"
7592
msgstr "Сбросить настройки"
7693

77-
#: src/resources/ui/preferences.ui:61
94+
#: src/resources/ui/preferences.ui:75
7895
msgid "Reset RunCat preferences to defaults"
7996
msgstr "Сбросить настройки RunCat к значениям по умолчанию"
8097

81-
#: src/resources/ui/preferences.ui:74
98+
#: src/resources/ui/preferences.ui:88
8299
msgid "Reset"
83100
msgstr "Сбросить"
84101

85-
#: src/resources/ui/preferences.ui:93
102+
#: src/resources/ui/preferences.ui:107
86103
msgid "The cat tells you the CPU usage by running speed"
87104
msgstr ""
88105
"Котик, который показывает загрузку\n"
89106
" процессора скоростью бега"
90107

91-
#: src/resources/ui/preferences.ui:97
108+
#: src/resources/ui/preferences.ui:111
92109
msgid "Visit RunCat's GitHub page"
93110
msgstr "Посетить страницу RunCat на GitHub"
94111

95-
#: src/resources/ui/preferences.ui:107
112+
#: src/resources/ui/preferences.ui:121
96113
msgid "Visit Homepage"
97114
msgstr "Открыть домашнюю страницу"
98115

99-
#: src/resources/ui/preferences.ui:111
116+
#: src/resources/ui/preferences.ui:125
100117
msgid "About RunCat"
101118
msgstr "О RunCat"

src/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const gioSettingsKeys = {
1515
IDLE_THRESHOLD: 'idle-threshold',
1616
DISPLAYING_ITEMS: 'displaying-items',
1717
INVERT_SPEED: 'invert-speed',
18+
customSystemMonitor: {
19+
ENABLED: 'custom-system-monitor-enabled',
20+
COMMAND: 'custom-system-monitor-command',
21+
},
1822
}
1923

2024
export const SYSTEM_MONITOR_COMMAND = 'gnome-system-monitor -r'

src/indicator.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import GObject from 'gi://GObject'
44
import GLib from 'gi://GLib'
55
import St from 'gi://St' // eslint-disable-line no-unused-vars
66

7+
import * as Main from 'resource:///org/gnome/shell/ui/main.js'
78
import { Button as PanelMenuButton } from 'resource:///org/gnome/shell/ui/panelMenu.js'
89
import { PopupSeparatorMenuItem } from 'resource:///org/gnome/shell/ui/popupMenu.js'
910
import { trySpawnCommandLine } from 'resource:///org/gnome/shell/misc/util.js'
@@ -81,7 +82,8 @@ export default class RunCatIndicator extends PanelMenuButton {
8182
* @type {{
8283
* idleThreshold: number,
8384
* invertSpeed: boolean,
84-
* displayingItems: { character: boolean, percentage: boolean }
85+
* displayingItems: { character: boolean, percentage: boolean },
86+
* customSystemMonitor: { isEnabled: boolean, command: string },
8587
* }}
8688
*/
8789
#settings
@@ -175,14 +177,29 @@ export default class RunCatIndicator extends PanelMenuButton {
175177

176178
this.menu.addAction(
177179
_('Open System Monitor'),
178-
() => trySpawnCommandLine(SYSTEM_MONITOR_COMMAND),
180+
() => {
181+
const command = this.#settings.customSystemMonitor.isEnabled
182+
? this.#settings.customSystemMonitor.command
183+
: SYSTEM_MONITOR_COMMAND
184+
185+
try {
186+
trySpawnCommandLine(command)
187+
} catch (e) {
188+
Main.notifyError(
189+
_('Execution of “%s” failed').format(command),
190+
e.message,
191+
)
192+
console.error(e)
193+
}
194+
},
179195
)
180196
this.menu.addMenuItem(new PopupSeparatorMenuItem())
181197
this.menu.addAction(_('Settings'), () => {
182198
try {
183199
this.#extension.openPreferences()
184200
} catch (e) {
185-
logError(e)
201+
Main.notifyError(_('Failed to open extension settings'), e.message)
202+
console.error(e)
186203
}
187204
})
188205
}
@@ -192,6 +209,10 @@ export default class RunCatIndicator extends PanelMenuButton {
192209
idleThreshold: this.#gioSettings.get_int(gioSettingsKeys.IDLE_THRESHOLD),
193210
displayingItems: displayingItems[this.#gioSettings.get_enum(gioSettingsKeys.DISPLAYING_ITEMS)],
194211
invertSpeed: this.#gioSettings.get_boolean(gioSettingsKeys.INVERT_SPEED),
212+
customSystemMonitor: {
213+
isEnabled: this.#gioSettings.get_boolean(gioSettingsKeys.customSystemMonitor.ENABLED),
214+
command: this.#gioSettings.get_string(gioSettingsKeys.customSystemMonitor.COMMAND),
215+
},
195216
}
196217

197218
this.#gioSettings.connect('changed', (_, key) => {
@@ -209,6 +230,16 @@ export default class RunCatIndicator extends PanelMenuButton {
209230
this.#settings.displayingItems = displayingItems[this.#gioSettings.get_enum(gioSettingsKeys.DISPLAYING_ITEMS)]
210231
this.#updateItemsVisibility()
211232
break
233+
234+
case gioSettingsKeys.customSystemMonitor.ENABLED:
235+
// eslint-disable-next-line max-len
236+
this.#settings.customSystemMonitor.isEnabled = this.#gioSettings.get_boolean(gioSettingsKeys.customSystemMonitor.ENABLED)
237+
break
238+
239+
case gioSettingsKeys.customSystemMonitor.COMMAND:
240+
// eslint-disable-next-line max-len
241+
this.#settings.customSystemMonitor.command = this.#gioSettings.get_string(gioSettingsKeys.customSystemMonitor.COMMAND)
242+
break
212243
}
213244
})
214245
}

src/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"uuid": "runcat@kolesnikov.se",
55
"gettext-domain": "runcat@kolesnikov.se",
66
"settings-schema": "org.gnome.shell.extensions.runcat",
7-
"shell-version": ["45", "46", "47"],
7+
"shell-version": ["46", "47"],
88
"url": "https://github.com/win0err/gnome-runcat",
99
"version": 28
1010
}

src/prefs.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ export default class RunCatPreferences extends ExtensionPreferences {
8686
this.#settings.set_enum(gioSettingsKeys.DISPLAYING_ITEMS, selected)
8787
})
8888

89+
// Enable custom system monitor
90+
this.#settings.bind(
91+
gioSettingsKeys.customSystemMonitor.ENABLED,
92+
this.#builder.get_object(gioSettingsKeys.customSystemMonitor.ENABLED),
93+
'enable-expansion',
94+
Gio.SettingsBindFlags.DEFAULT,
95+
)
96+
97+
// Custom system monitor command
98+
this.#settings.bind(
99+
gioSettingsKeys.customSystemMonitor.COMMAND,
100+
this.#builder.get_object(gioSettingsKeys.customSystemMonitor.COMMAND),
101+
'text',
102+
Gio.SettingsBindFlags.DEFAULT,
103+
)
104+
89105
// Reset
90106
this.#builder.get_object('reset').connect('clicked', () => {
91107
// Idle Threshold
@@ -94,6 +110,12 @@ export default class RunCatPreferences extends ExtensionPreferences {
94110
// Invert Speed
95111
this.#settings.reset(gioSettingsKeys.INVERT_SPEED)
96112

113+
// Enable custom system monitor
114+
this.#settings.reset(gioSettingsKeys.customSystemMonitor.ENABLED)
115+
116+
// Custom system monitor command
117+
this.#settings.reset(gioSettingsKeys.customSystemMonitor.COMMAND)
118+
97119
// Displaying Items
98120
this.#settings.reset(gioSettingsKeys.DISPLAYING_ITEMS)
99121
combo.set_selected(this.#settings.get_enum(gioSettingsKeys.DISPLAYING_ITEMS))

src/resources/ui/extension.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
</object>
2121

2222
<object class="StBoxLayout" id="labelBox" />
23-
</interface>
23+
</interface>

src/resources/ui/preferences.ui

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
</property>
2424
</object>
2525
</child>
26+
27+
<child>
28+
<object class="AdwExpanderRow" id="custom-system-monitor-enabled">
29+
<property name="show_enable_switch">True</property>
30+
<property name="title" translatable="yes">Use a custom system monitor</property>
31+
<child>
32+
<object class="AdwEntryRow" id="custom-system-monitor-command">
33+
<property name="title" translatable="yes">Command</property>
34+
<property name="text">gnome-system-monitor -r</property>
35+
<property name="show-apply-button">True</property>
36+
</object>
37+
</child>
38+
</object>
39+
</child>
2640
</object>
2741
</child>
2842

0 commit comments

Comments
 (0)