Skip to content

Commit

Permalink
Add an option to use a custom system monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
win0err committed Mar 19, 2024
1 parent 640413f commit 7062b0c
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"log": "readonly",
"logError": "readonly",
"TextDecoder": "readonly",
"Intl": "readonly"
"Intl": "readonly",
"console": "readonly"
}
}
49 changes: 33 additions & 16 deletions po/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,37 @@ msgid ""
msgstr ""
"Project-Id-Version: gnome-runcat-extension 26\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-17 21:28+0300\n"
"POT-Creation-Date: 2024-03-19 11:49+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/indicator.js:177
#: src/indicator.js:179
msgid "Open System Monitor"
msgstr ""

#: src/indicator.js:181
#: src/indicator.js:189
#, javascript-format
msgid "Execution of “%s” failed"
msgstr ""

#: src/indicator.js:197
msgid "Settings"
msgstr ""

#: src/indicator.js:201
msgid "Failed to open extension settings"
msgstr ""

#: src/prefs.js:54
msgid "RunCat Settings"
msgstr ""

#: src/prefs.js:116
#: src/prefs.js:138
msgid "Version"
msgstr ""

Expand All @@ -53,46 +62,54 @@ msgstr ""
msgid "Character only"
msgstr ""

#: src/resources/ui/preferences.ui:31
#: src/resources/ui/preferences.ui:30
msgid "Use a custom system monitor"
msgstr ""

#: src/resources/ui/preferences.ui:33
msgid "Command"
msgstr ""

#: src/resources/ui/preferences.ui:45
msgid "Character"
msgstr ""

#: src/resources/ui/preferences.ui:35
#: src/resources/ui/preferences.ui:49
msgid "Invert speed"
msgstr ""

#: src/resources/ui/preferences.ui:41
#: src/resources/ui/preferences.ui:55
msgid "Idle threshold"
msgstr ""

#: src/resources/ui/preferences.ui:42
#: src/resources/ui/preferences.ui:56
msgid "Available when speed is not inverted"
msgstr ""

#: src/resources/ui/preferences.ui:60
#: src/resources/ui/preferences.ui:74
msgid "Reset preferences"
msgstr ""

#: src/resources/ui/preferences.ui:61
#: src/resources/ui/preferences.ui:75
msgid "Reset RunCat preferences to defaults"
msgstr ""

#: src/resources/ui/preferences.ui:74
#: src/resources/ui/preferences.ui:88
msgid "Reset"
msgstr ""

#: src/resources/ui/preferences.ui:93
#: src/resources/ui/preferences.ui:107
msgid "The cat tells you the CPU usage by running speed"
msgstr ""

#: src/resources/ui/preferences.ui:97
#: src/resources/ui/preferences.ui:111
msgid "Visit RunCat's GitHub page"
msgstr ""

#: src/resources/ui/preferences.ui:107
#: src/resources/ui/preferences.ui:121
msgid "Visit Homepage"
msgstr ""

#: src/resources/ui/preferences.ui:111
#: src/resources/ui/preferences.ui:125
msgid "About RunCat"
msgstr ""
47 changes: 32 additions & 15 deletions po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gnome-runcat-extension 20\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-17 21:28+0300\n"
"POT-Creation-Date: 2024-03-19 11:49+0300\n"
"PO-Revision-Date: 2022-09-30 19:16+0300\n"
"Last-Translator: Sergei Kolesnikov <sergei@kolesnikov.se>\n"
"Language-Team: Russian\n"
Expand All @@ -18,19 +18,28 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"

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

#: src/indicator.js:181
#: src/indicator.js:189
#, javascript-format
msgid "Execution of “%s” failed"
msgstr "Не удалось выполнить «%s»"

#: src/indicator.js:197
msgid "Settings"
msgstr "Настройки"

#: src/indicator.js:201
msgid "Failed to open extension settings"
msgstr "Не удалось открыть настройки расширения"

#: src/prefs.js:54
msgid "RunCat Settings"
msgstr "Настройки RunCat"

#: src/prefs.js:116
#: src/prefs.js:138
msgid "Version"
msgstr "Версия"

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

#: src/resources/ui/preferences.ui:31
#: src/resources/ui/preferences.ui:30
msgid "Use a custom system monitor"
msgstr "Использовать пользовательский системный монитор"

#: src/resources/ui/preferences.ui:33
msgid "Command"
msgstr "Команда"

#: src/resources/ui/preferences.ui:45
msgid "Character"
msgstr "Персонаж"

#: src/resources/ui/preferences.ui:35
#: src/resources/ui/preferences.ui:49
msgid "Invert speed"
msgstr "Инвертировать скорость"

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

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

#: src/resources/ui/preferences.ui:60
#: src/resources/ui/preferences.ui:74
msgid "Reset preferences"
msgstr "Сбросить настройки"

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

#: src/resources/ui/preferences.ui:74
#: src/resources/ui/preferences.ui:88
msgid "Reset"
msgstr "Сбросить"

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

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

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

#: src/resources/ui/preferences.ui:111
#: src/resources/ui/preferences.ui:125
msgid "About RunCat"
msgstr "О RunCat"
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const gioSettingsKeys = {
IDLE_THRESHOLD: 'idle-threshold',
DISPLAYING_ITEMS: 'displaying-items',
INVERT_SPEED: 'invert-speed',
customSystemMonitor: {
ENABLED: 'custom-system-monitor-enabled',
COMMAND: 'custom-system-monitor-command',
},
}

export const SYSTEM_MONITOR_COMMAND = 'gnome-system-monitor -r'
37 changes: 34 additions & 3 deletions src/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import GObject from 'gi://GObject'
import GLib from 'gi://GLib'
import St from 'gi://St' // eslint-disable-line no-unused-vars

import * as Main from 'resource:///org/gnome/shell/ui/main.js'
import { Button as PanelMenuButton } from 'resource:///org/gnome/shell/ui/panelMenu.js'
import { PopupSeparatorMenuItem } from 'resource:///org/gnome/shell/ui/popupMenu.js'
import { trySpawnCommandLine } from 'resource:///org/gnome/shell/misc/util.js'
Expand Down Expand Up @@ -81,7 +82,8 @@ export default class RunCatIndicator extends PanelMenuButton {
* @type {{
* idleThreshold: number,
* invertSpeed: boolean,
* displayingItems: { character: boolean, percentage: boolean }
* displayingItems: { character: boolean, percentage: boolean },
* customSystemMonitor: { isEnabled: boolean, command: string },
* }}
*/
#settings
Expand Down Expand Up @@ -175,14 +177,29 @@ export default class RunCatIndicator extends PanelMenuButton {

this.menu.addAction(
_('Open System Monitor'),
() => trySpawnCommandLine(SYSTEM_MONITOR_COMMAND),
() => {
const command = this.#settings.customSystemMonitor.isEnabled
? this.#settings.customSystemMonitor.command
: SYSTEM_MONITOR_COMMAND

try {
trySpawnCommandLine(command)
} catch (e) {
Main.notifyError(
_('Execution of “%s” failed').format(command),
e.message,
)
console.error(e)
}
},
)
this.menu.addMenuItem(new PopupSeparatorMenuItem())
this.menu.addAction(_('Settings'), () => {
try {
this.#extension.openPreferences()
} catch (e) {
logError(e)
Main.notifyError(_('Failed to open extension settings'), e.message)
console.error(e)
}
})
}
Expand All @@ -192,6 +209,10 @@ export default class RunCatIndicator extends PanelMenuButton {
idleThreshold: this.#gioSettings.get_int(gioSettingsKeys.IDLE_THRESHOLD),
displayingItems: displayingItems[this.#gioSettings.get_enum(gioSettingsKeys.DISPLAYING_ITEMS)],
invertSpeed: this.#gioSettings.get_boolean(gioSettingsKeys.INVERT_SPEED),
customSystemMonitor: {
isEnabled: this.#gioSettings.get_boolean(gioSettingsKeys.customSystemMonitor.ENABLED),
command: this.#gioSettings.get_string(gioSettingsKeys.customSystemMonitor.COMMAND),
},
}

this.#gioSettings.connect('changed', (_, key) => {
Expand All @@ -209,6 +230,16 @@ export default class RunCatIndicator extends PanelMenuButton {
this.#settings.displayingItems = displayingItems[this.#gioSettings.get_enum(gioSettingsKeys.DISPLAYING_ITEMS)]
this.#updateItemsVisibility()
break

case gioSettingsKeys.customSystemMonitor.ENABLED:
// eslint-disable-next-line max-len
this.#settings.customSystemMonitor.isEnabled = this.#gioSettings.get_boolean(gioSettingsKeys.customSystemMonitor.ENABLED)
break

case gioSettingsKeys.customSystemMonitor.COMMAND:
// eslint-disable-next-line max-len
this.#settings.customSystemMonitor.command = this.#gioSettings.get_string(gioSettingsKeys.customSystemMonitor.COMMAND)
break
}
})
}
Expand Down
22 changes: 22 additions & 0 deletions src/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ export default class RunCatPreferences extends ExtensionPreferences {
this.#settings.set_enum(gioSettingsKeys.DISPLAYING_ITEMS, selected)
})

// Enable custom system monitor
this.#settings.bind(
gioSettingsKeys.customSystemMonitor.ENABLED,
this.#builder.get_object(gioSettingsKeys.customSystemMonitor.ENABLED),
'enable-expansion',
Gio.SettingsBindFlags.DEFAULT,
)

// Custom system monitor command
this.#settings.bind(
gioSettingsKeys.customSystemMonitor.COMMAND,
this.#builder.get_object(gioSettingsKeys.customSystemMonitor.COMMAND),
'text',
Gio.SettingsBindFlags.DEFAULT,
)

// Reset
this.#builder.get_object('reset').connect('clicked', () => {
// Idle Threshold
Expand All @@ -94,6 +110,12 @@ export default class RunCatPreferences extends ExtensionPreferences {
// Invert Speed
this.#settings.reset(gioSettingsKeys.INVERT_SPEED)

// Enable custom system monitor
this.#settings.reset(gioSettingsKeys.customSystemMonitor.ENABLED)

// Custom system monitor command
this.#settings.reset(gioSettingsKeys.customSystemMonitor.COMMAND)

// Displaying Items
this.#settings.reset(gioSettingsKeys.DISPLAYING_ITEMS)
combo.set_selected(this.#settings.get_enum(gioSettingsKeys.DISPLAYING_ITEMS))
Expand Down
14 changes: 14 additions & 0 deletions src/resources/ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
</property>
</object>
</child>

<child>
<object class="AdwExpanderRow" id="custom-system-monitor-enabled">
<property name="show_enable_switch">True</property>
<property name="title" translatable="yes">Use a custom system monitor</property>
<child>
<object class="AdwEntryRow" id="custom-system-monitor-command">
<property name="title" translatable="yes">Command</property>
<property name="text">gnome-system-monitor -r</property>
<property name="show-apply-button">True</property>
</object>
</child>
</object>
</child>
</object>
</child>

Expand Down
10 changes: 10 additions & 0 deletions src/schemas/org.gnome.shell.extensions.runcat.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@
<default>false</default>
<summary>Invert speed</summary>
</key>

<key name="custom-system-monitor-enabled" type="b">
<default>false</default>
<summary>Enable custom system monitor</summary>
</key>

<key name="custom-system-monitor-command" type="s">
<default>'gnome-system-monitor -r'</default>
<summary>Custom system monitor command</summary>
</key>
</schema>
</schemalist>

0 comments on commit 7062b0c

Please sign in to comment.