Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typechecking #56

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move to typescript
  • Loading branch information
win0err committed Nov 11, 2024
commit a8f7d91be3d2c34f323c073e268f3e9fed00034c
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,3 +10,4 @@ src/schemas/gschemas.compiled
po/*~
tsconfig.alias.json
.#*
.build/
47 changes: 33 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

.PHONY : build clean install uninstall open-prefs spawn-gnome-shell translations
.PHONY : build clean install uninstall open-prefs spawn-gnome-shell translations compile
.DEFAULT_GOAL := build

UUID = runcat@kolesnikov.se
@@ -9,41 +9,60 @@ LOCAL = $(HOME)/.local/share/gnome-shell/extensions

all_sources = $(shell find src -type f)

js_sources = $(shell cd src && find . -maxdepth 1 -type f -name '*.js')
typescript_sources = $(shell find src -type f -name '*.ts' -not -name '*.d.ts')
typescript_compiled = $(typescript_sources:src/%.ts=.build/%.js)

translations_sources = src/indicator.js src/prefs.js
translations_sources += $(shell find src/resources/ui -maxdepth 1 -type f -name '*.ui')
translations = $(shell find po -maxdepth 1 -type f -name '*.po')
translations_ts_sources = src/indicator.ts src/prefs.ts
translations_ui_sources = $(wildcard src/resources/ui/*.ui)
translations = $(wildcard po/*.po)

schema = src/schemas/org.gnome.shell.extensions.runcat.gschema.xml
stylesheet = src/stylesheet.css

build: dist/$(DIST_ARCHIVE)

dist:
mkdir -p dist/

dist/$(DIST_ARCHIVE): dist po/messages.pot $(translations) $(all_sources)
gnome-extensions pack -f src/ \
$(addprefix --extra-source=, $(js_sources)) \
--extra-source=./dataProviders \
--extra-source=./resources \
--extra-source=../LICENSE \
--podir=../po \
.build/%.js: $(typescript_sources)
tsc

dist/$(DIST_ARCHIVE): dist compile po/messages.pot $(translations) $(all_sources) $(typescript_compiled)
gnome-extensions pack --force \
$(addprefix --extra-source=, $(wildcard .build/*.js)) \
$(addprefix --extra-source=, $(shell find .build/ -mindepth 1 -type d)) \
--extra-source=./$(stylesheet) \
--extra-source=./src/metadata.json \
--extra-source=./src/resources \
--extra-source=./LICENSE \
--podir=./po \
--schema=./$(schema) \
-o dist/


po/%.po: po/messages.pot
touch $@ && msgmerge --update $@ $^

po/messages.pot: $(translations_sources)
po/messages.pot: $(translations_ts_sources) $(translations_ui_sources)
xgettext \
--language=JavaScript \
--package-name=gnome-runcat-extension \
--package-version=$$(jq .version src/metadata.json) \
--from-code=UTF-8 \
--output=$@ \
$^
$(translations_ts_sources)
xgettext \
--join-existing \
--package-name=gnome-runcat-extension \
--package-version=$$(jq .version src/metadata.json) \
--from-code=UTF-8 \
--output=$@ \
$(translations_ui_sources)

translations: po/messages.pot $(translations)

compile: $(typescript_compiled)

clean:
rm -rf dist

18 changes: 0 additions & 18 deletions jsconfig.json

This file was deleted.

16 changes: 8 additions & 8 deletions po/messages.pot
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: gnome-runcat-extension 28\n"
"Project-Id-Version: gnome-runcat-extension 29\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-14 13:41+0300\n"
"POT-Creation-Date: 2024-11-11 21:06+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"
@@ -17,28 +17,28 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/indicator.js:238
#: src/indicator.ts:150
msgid "Open System Monitor"
msgstr ""

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

#: src/indicator.js:260
#: src/indicator.ts:171
msgid "Settings"
msgstr ""

#: src/indicator.js:264
#: src/indicator.ts:176
msgid "Failed to open extension settings"
msgstr ""

#: src/prefs.js:57
#: src/prefs.ts:47
msgid "RunCat Settings"
msgstr ""

#: src/prefs.js:141
#: src/prefs.ts:133
msgid "Version"
msgstr ""

14 changes: 7 additions & 7 deletions po/ru.po
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gnome-runcat-extension 20\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-10 22:13+0300\n"
"POT-Creation-Date: 2024-11-11 21:06+0300\n"
"PO-Revision-Date: 2022-09-30 19:16+0300\n"
"Last-Translator: Sergei Kolesnikov <sergei@kolesnikov.se>\n"
"Language-Team: Russian\n"
@@ -18,28 +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:238
#: src/indicator.ts:150
msgid "Open System Monitor"
msgstr "Открыть Системный монитор"

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

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

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

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

#: src/prefs.js:141
#: src/prefs.ts:133
msgid "Version"
msgstr "Версия"

37 changes: 0 additions & 37 deletions src/constants.js

This file was deleted.

72 changes: 72 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Gio from 'gi://Gio'
import GObject from 'gi://GObject'
import type { DisplayingItems, DisplayingItemsOption } from './types'

export const displayingItemsOptions = {
CHARACTER_AND_PERCENTAGE: 0,
PERCENTAGE_ONLY: 1,
CHARACTER_ONLY: 2,
} as const

export const enumToDisplayingItems: Record<DisplayingItemsOption, DisplayingItems> = {
[displayingItemsOptions.CHARACTER_AND_PERCENTAGE]: { character: true, percentage: true },
[displayingItemsOptions.PERCENTAGE_ONLY]: { character: false, percentage: true },
[displayingItemsOptions.CHARACTER_ONLY]: { character: true, percentage: false },
}

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',
},
} as const

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


export const gObjectPropertyNames = {
currentText: 'currentText',
currentIcon: 'currentIcon',
displayingItems: 'displayingItems',
isSpeedInverted: 'isSpeedInverted',
idleThreshold: 'idleThreshold',
useCustomSystemMonitor: 'useCustomSystemMonitor',
customSystemMonitorCommand: 'customSystemMonitorCommand',
} as const

export const gObjectProperties: Record<keyof typeof gObjectPropertyNames, GObject.ParamSpec> = {
currentText: GObject.ParamSpec.string(
'currentText', '', '',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, '...',
),
currentIcon: GObject.ParamSpec.object<Gio.Icon>(
'currentIcon', '', '',
(GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT) as any, Gio.Icon.$gtype,
),

displayingItems: GObject.ParamSpec.jsobject<DisplayingItems>(
'displayingItems', '', '',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
),

isSpeedInverted: GObject.ParamSpec.boolean(
'isSpeedInverted', '', '',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, false,
),
idleThreshold: GObject.ParamSpec.int(
'idleThreshold', '', '',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, 0, 100, 0,
),

useCustomSystemMonitor: GObject.ParamSpec.boolean(
'useCustomSystemMonitor', '', '',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, false,
),
customSystemMonitorCommand: GObject.ParamSpec.string(
'customSystemMonitorCommand', '', '',
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, SYSTEM_MONITOR_COMMAND,
),
}
9 changes: 4 additions & 5 deletions src/dataProviders/cpu.js → src/dataProviders/cpu.ts
Original file line number Diff line number Diff line change
@@ -3,10 +3,9 @@ import GTop from 'gi://GTop'

export const MAX_CPU_UTILIZATION = 1.0

/**
* @returns {{ active: number, total: number }}
*/
function getCpuStats() {
type CpuStats = { active: number, total: number }

function getCpuStats(): CpuStats {
const cpu = new GTop.glibtop_cpu()
GTop.glibtop_get_cpu(cpu)

@@ -16,7 +15,7 @@ function getCpuStats() {
}
}

export default function* () {
export default function* (): Generator<number, number, void> {
let prevActive = 0
let prevTotal = 0

6 changes: 3 additions & 3 deletions src/extension.js → src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js'
import { panel as MainPanel } from 'resource:///org/gnome/shell/ui/main.js'
import type { Button as PanelMenuButton } from 'resource:///org/gnome/shell/ui/panelMenu.js'

import RunCatIndicator from './indicator.js'


export default class RunCatExtension extends Extension {
/** @type {import('resource:///org/gnome/shell/ui/panelMenu.js').Button} */
#indicator
#indicator: PanelMenuButton | null = null

enable() {
this.#indicator = new RunCatIndicator(this)
MainPanel.addToStatusArea('runcat-indicator', this.#indicator)
}

disable() {
this.#indicator.destroy()
this.#indicator?.destroy()
this.#indicator = null
}
}
Loading
Loading