Skip to content

Commit

Permalink
Version 20 (#32)
Browse files Browse the repository at this point in the history
* Add translations
* New preferences window
* New about window
* Right-click menu
  • Loading branch information
win0err authored Oct 3, 2022
1 parent 62f0717 commit 531362b
Show file tree
Hide file tree
Showing 27 changed files with 722 additions and 648 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ dist/
node_modules/
yarn.lock
package-lock.json
docs-lock.json
docs-lock.json
src/schemas/gschemas.compiled
src/po/*~
46 changes: 38 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
#!/usr/bin/make -f

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

UUID = [email protected]
DIST_ARCHIVE = $(UUID).shell-extension.zip
LOCAL = $(HOME)/.local/share/gnome-shell/extensions

js_sources = $(shell find src -maxdepth 1 -type f -name '*.js')
all_sources = $(shell find src -type f)

build: clean
js_sources = $(shell cd src && find . -maxdepth 1 -type f -name '*.js')

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


build: dist/$(DIST_ARCHIVE)

dist:
mkdir -p dist/

dist/$(DIST_ARCHIVE): dist $(all_sources)
gnome-extensions pack -f src/ \
$(addprefix --extra-source=../, $(js_sources)) \
$(addprefix --extra-source=, $(js_sources)) \
--extra-source=./dataProviders \
--extra-source=./resources \
--extra-source=../assets \
--extra-source=../LICENSE \
--podir=./po \
-o dist/


src/po/%.po: src/po/messages.pot
msgmerge --update $@ src/po/messages.pot

src/po/messages.pot: $(translations_sources)
touch src/po/messages.pot && \
xgettext \
--package-name gnome-runcat-extension \
--package-version 20 \
--from-code=UTF-8 \
--output=src/po/messages.pot \
$^

translations: src/po/messages.pot $(translations)

clean:
rm -rf dist

install: uninstall build
gnome-extensions install dist/$(UUID).shell-extension.zip --force
gnome-extensions install dist/$(DIST_ARCHIVE) --force
gnome-extensions enable $(UUID) || true
echo "You need to restart GNOME Shell to apply changes"

Expand All @@ -31,8 +61,8 @@ uninstall:
open-prefs:
gnome-extensions prefs $(UUID)

spawn-gnome-shell: install
env MUTTER_DEBUG_DUMMY_MODE_SPECS=1280x720 \
spawn-gnome-shell:
env MUTTER_DEBUG_DUMMY_MODE_SPECS=1600x800 \
MUTTER_DEBUG_DUMMY_MONITOR_SCALES=1 \
dbus-run-session -- gnome-shell --nested --wayland

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img height="165" src="assets/se.kolesnikov.runcat.svg" alt="RunCat for GNOME Shell Logo" align="right" />
<img height="165" src="src/resources/se.kolesnikov.runcat.svg" alt="RunCat for GNOME Shell Logo" align="right" />

# RunCat for GNOME Shell

Expand All @@ -15,7 +15,7 @@ This is the recommended method for installation, as it doesn't require the build

[<img src="assets/get-it-on-ego.png" height="100">](https://extensions.gnome.org/extension/2986/runcat/)

### Manual installation
### Manual installation

#### From source code
If you want to install the extension from sources, clone [the RunCat repository](https://github.com/win0err/gnome-runcat), navigate to the cloned directory and run:
Expand All @@ -24,23 +24,24 @@ $ make install
```

#### Release ZIP-archive
If you want to install the extension from release zip-archive,
download `[email protected]` from [the releases section](https://github.com/win0err/gnome-runcat/releases) and run:
If you want to install the extension from release zip-archive,
download `[email protected].shell-extension.zip` from [the releases section](https://github.com/win0err/gnome-runcat/releases) and run:
```bash
$ gnome-extensions install path/to/[email protected] --force
$ gnome-extensions install path/to/[email protected].shell-extension.zip --force
```

#### After installation:
1. Restart the GNOME Shell:
1. Restart the GNOME Shell:
- <kbd>ALT</kbd>+<kbd>F2</kbd> to open the command prompt, and enter <kbd>r</kbd> to restart the GNOME Shell;
- or Log Out, then Log In, if GNOME Shell won't restart;
2. Enable the extension:
2. Enable the extension:
- Open GNOME Tweaks → Extensions → RunCat → On;
- or Run in terminal: `gnome-extensions enable [email protected]`.


### Manage RunCat preferences
- Open GNOME Tweaks → Extensions → RunCat → ⚙️;
- Right-click on the extension button on the top bar → Settings;
- or Open GNOME Tweaks → Extensions → RunCat → ⚙️;
- or Open [RunCat on GNOME Extensions portal](https://extensions.gnome.org/extension/2986/runcat/) → ⚙️;
- or Manage directly in `dconf`: `dconf list /org/gnome/shell/extensions/runcat/`.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "runcat",
"private": true,
"scripts": {
"generate:types": "ts-for-gir generate Gtk-4.0 Adw-1 -e gjs",
"generate:types": "ts-for-gir generate Gtk-4.0 Adw-1 Clutter-1.0 -e gjs",
"lint": "eslint src/"
},
"repository": "win0err/gnome-runcat",
Expand Down
21 changes: 21 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable no-var, no-unused-vars */

var SCHEMA_PATH = 'org.gnome.shell.extensions.runcat';
var LOG_ERROR_PREFIX = 'RuncatExtensionError';

const CHARACTER_AND_PERCENTAGE = 0;
const PERCENTAGE_ONLY = 1;
const CHARACTER_ONLY = 2;

var PanelMenuButtonVisibility = {
[CHARACTER_AND_PERCENTAGE]: { character: true, percentage: true },
[PERCENTAGE_ONLY]: { character: false, percentage: true },
[CHARACTER_ONLY]: { character: true, percentage: false },
};

var Settings = {
IDLE_THRESHOLD: 'idle-threshold',
DISPLAYING_ITEMS: 'displaying-items',
};

var SYSTEM_MONITOR_COMMAND = 'gnome-system-monitor -r';
77 changes: 0 additions & 77 deletions src/cpu.js

This file was deleted.

59 changes: 59 additions & 0 deletions src/dataProviders/cpu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { Gio } = imports.gi;
const Extension = imports.misc.extensionUtils.getCurrentExtension();

const { readFile } = Extension.imports.utils;

// eslint-disable-next-line func-names, no-unused-vars, no-var
var createGenerator = async function* () {
const procStatFile = Gio.File.new_for_path('/proc/stat');

let prevActive = 0;
let prevTotal = 0;

while (true) {
// eslint-disable-next-line no-await-in-loop
const procStatContents = await readFile(procStatFile);

const cpuInfo = procStatContents
.split('\n')[0].trim()
.split(/[\s]+/)
.map(n => parseInt(n, 10));

const [
, // eslint-disable-line
user,
nice,
system,
idle,
iowait,
irq, // eslint-disable-line
softirq,
steal,
guest, // eslint-disable-line
] = cpuInfo;

const active = user + system + nice + softirq + steal;
const total = user + system + nice + softirq + steal + idle + iowait;

// eslint-disable-next-line object-curly-newline
const data = JSON.stringify({ total, active, prevTotal, prevActive });

let utilization = 100 * ((active - prevActive) / (total - prevTotal));
if (Number.isNaN(utilization) || !Number.isFinite(utilization)) {
log(`cpu utilization is ${utilization}, data: ${data}`);

utilization = 0;
}

if (utilization > 100) {
log(`cpu utilization is ${utilization}, data: ${data}`);

utilization = 100;
}

prevActive = active;
prevTotal = total;

yield utilization;
}
};
7 changes: 6 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

imports.gi.versions.Gtk = '4.0';

const Main = imports.ui.main;
const Extension = imports.misc.extensionUtils.getCurrentExtension();
const ExtensionUtils = imports.misc.extensionUtils;
const Extension = ExtensionUtils.getCurrentExtension();

const { PanelMenuButton } = Extension.imports.panelMenuButton;

Expand All @@ -22,5 +25,7 @@ class RunCatExtension {
}

function init() {
ExtensionUtils.initTranslations(Extension.metadata.uuid);

return new RunCatExtension();
}
41 changes: 0 additions & 41 deletions src/iconProvider.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"name": "RunCat",
"description": "The cat tells you the CPU usage by running speed",
"uuid": "[email protected]",
"gettext-domain": "[email protected]",
"shell-version": [
"3.38",
"40",
"41",
"42",
"43"
],
"session-modes": ["user"],
"url": "https://github.com/win0err/gnome-runcat",
"version": 19
"version": 20
}
Loading

0 comments on commit 531362b

Please sign in to comment.