Skip to content

Commit

Permalink
Animated Sleeping (#24)
Browse files Browse the repository at this point in the history
The cat has a sleeping animation now
  • Loading branch information
exincore authored and win0err committed Mar 26, 2023
1 parent 17270d1 commit d9972bc
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 68 deletions.
34 changes: 19 additions & 15 deletions po/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gnome-runcat-extension 22\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-26 13:19+0300\n"
"POT-Creation-Date: 2022-10-29 11:47-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,19 +17,19 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/panelMenuButton.js:95
#: src/panelMenuButton.js:110
msgid "Open System Monitor"
msgstr ""

#: src/panelMenuButton.js:99
#: src/panelMenuButton.js:114
msgid "Settings"
msgstr ""

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

#: src/prefs.js:59
#: src/prefs.js:66
msgid "Version"
msgstr ""

Expand All @@ -46,45 +46,49 @@ msgid "Idle threshold"
msgstr ""

#: src/resources/ui/preferences.ui:34
msgid "Animated idle"
msgstr ""

#: src/resources/ui/preferences.ui:48
msgid "Displaying items"
msgstr ""

#: src/resources/ui/preferences.ui:38
#: src/resources/ui/preferences.ui:52
msgid "Character and percentage"
msgstr ""

#: src/resources/ui/preferences.ui:39
#: src/resources/ui/preferences.ui:53
msgid "Percentage only"
msgstr ""

#: src/resources/ui/preferences.ui:40
#: src/resources/ui/preferences.ui:54
msgid "Character only"
msgstr ""

#: src/resources/ui/preferences.ui:51
#: src/resources/ui/preferences.ui:65
msgid "Reset preferences"
msgstr ""

#: src/resources/ui/preferences.ui:52
#: src/resources/ui/preferences.ui:66
msgid "Reset RunCat preferences to defaults"
msgstr ""

#: src/resources/ui/preferences.ui:65
#: src/resources/ui/preferences.ui:79
msgid "Reset"
msgstr ""

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

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

#: src/resources/ui/preferences.ui:98
#: src/resources/ui/preferences.ui:112
msgid "Visit Homepage"
msgstr ""

#: src/resources/ui/preferences.ui:102
#: src/resources/ui/preferences.ui:116
msgid "About RunCat"
msgstr ""
34 changes: 19 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: 2022-10-05 02:43+0300\n"
"POT-Creation-Date: 2022-10-29 11:47-0600\n"
"PO-Revision-Date: 2022-09-30 19:16+0300\n"
"Last-Translator: Sergei Kolesnikov <[email protected]>\n"
"Language-Team: Russian\n"
Expand All @@ -18,19 +18,19 @@ 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/panelMenuButton.js:95
#: src/panelMenuButton.js:110
msgid "Open System Monitor"
msgstr "Открыть Системный монитор"

#: src/panelMenuButton.js:99
#: src/panelMenuButton.js:114
msgid "Settings"
msgstr "Настройки"

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

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

Expand All @@ -47,47 +47,51 @@ msgid "Idle threshold"
msgstr "Порог бездействия"

#: src/resources/ui/preferences.ui:34
msgid "Animated idle"
msgstr ""

#: src/resources/ui/preferences.ui:48
msgid "Displaying items"
msgstr "Отображаемые элементы"

#: src/resources/ui/preferences.ui:38
#: src/resources/ui/preferences.ui:52
msgid "Character and percentage"
msgstr "Персонаж и проценты"

#: src/resources/ui/preferences.ui:39
#: src/resources/ui/preferences.ui:53
msgid "Percentage only"
msgstr "Только проценты"

#: src/resources/ui/preferences.ui:40
#: src/resources/ui/preferences.ui:54
msgid "Character only"
msgstr "Только персонаж"

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

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

#: src/resources/ui/preferences.ui:65
#: src/resources/ui/preferences.ui:79
msgid "Reset"
msgstr "Сбрость"

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

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

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

#: src/resources/ui/preferences.ui:102
#: src/resources/ui/preferences.ui:116
msgid "About RunCat"
msgstr "О RunCat"
10 changes: 10 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ var PanelMenuButtonVisibility = {

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

var RunnerPacks = {
CAT: 'cat',
};

var RunnerStates = {
IDLE: 'idle',
ACTIVE: 'active',
};

var SYSTEM_MONITOR_COMMAND = 'gnome-system-monitor -r';
51 changes: 38 additions & 13 deletions src/panelMenuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,38 @@ const {
SCHEMA_PATH,
PanelMenuButtonVisibility,
Settings,
RunnerPacks,
RunnerStates,
} = Extension.imports.constants;
const { createGenerator: createCpuGenerator } = Extension.imports.dataProviders.cpu;

const getGIcon = name => Gio.icon_new_for_string(
`${Extension.path}/resources/icons/cat/my-${name}-symbolic.svg`,
const queryGIconExists = (name, state, index) => Gio.file_new_for_path(
`${Extension.path}/resources/icons/${name}/my-${state}-${index}-symbolic.svg`,
).query_exists(null);

const getGIcon = (name, state, index) => Gio.icon_new_for_string(
`${Extension.path}/resources/icons/${name}/my-${state}-${index}-symbolic.svg`,
);

// eslint-disable-next-line func-names
const spritesGenerator = function* () {
const SPRITES_COUNT = 5;
const getGIconSet = (name, state) => {
let count = 0;
const SET = [];
while (queryGIconExists(name, state, count)) {
SET[count] = getGIcon(name, state, count);
count++;
}
return SET;
};

const sprites = [...Array(SPRITES_COUNT).keys()]
.map(i => getGIcon(`active-${i}`));
// eslint-disable-next-line func-names
const spritesGenerator = function* (name, state) {
const SET = getGIconSet(name, state);
const LENGTH = SET.length;

let i;
while (true) {
for (i = 0; i < SPRITES_COUNT; i++) {
yield sprites[i];
for (i = 0; i < LENGTH; i++) {
yield SET[i];
}
}
};
Expand Down Expand Up @@ -63,8 +77,9 @@ var PanelMenuButton = GObject.registerClass(
this.ui = {
builder: Gtk.Builder.new(),
icons: {
idle: getGIcon('idle'),
runningGenerator: spritesGenerator(),
idle: getGIcon(RunnerPacks.CAT, RunnerStates.IDLE, 0),
idleGenerator: spritesGenerator(RunnerPacks.CAT, RunnerStates.IDLE),
runningGenerator: spritesGenerator(RunnerPacks.CAT, RunnerStates.ACTIVE),
},
};
this.ui.builder.set_translation_domain(Extension.metadata.uuid);
Expand All @@ -74,7 +89,7 @@ var PanelMenuButton = GObject.registerClass(
this.ui.builder.add_from_file(`${Extension.path}/resources/ui/extension.ui`);

const icon = this.ui.builder.get_object('icon');
icon.set_property('gicon', this.ui.icons.idle);
icon.set_property('gicon', this.ui.icons.idleGenerator.next().value);
if (!itemsVisibility.character) {
icon.hide();
}
Expand Down Expand Up @@ -120,13 +135,18 @@ var PanelMenuButton = GObject.registerClass(
this.gioSettings = ExtensionUtils.getSettings(SCHEMA_PATH);
this.settings = {
idleThreshold: this.gioSettings.get_int(Settings.IDLE_THRESHOLD),
animatedIdle: this.gioSettings.get_boolean(Settings.ANIMATED_IDLE),
displayingItems: this.gioSettings.get_enum(Settings.DISPLAYING_ITEMS),
};

this.gioSettings.connect(`changed::${Settings.IDLE_THRESHOLD}`, () => {
this.settings.idleThreshold = this.gioSettings.get_int(Settings.IDLE_THRESHOLD);
});

this.gioSettings.connect(`changed::${Settings.ANIMATED_IDLE}`, () => {
this.settings.animatedIdle = this.gioSettings.get_boolean(Settings.ANIMATED_IDLE);
});

this.gioSettings.connect(`changed::${Settings.DISPLAYING_ITEMS}`, () => {
this.settings.displayingItems = this.gioSettings.get_enum(Settings.DISPLAYING_ITEMS);

Expand Down Expand Up @@ -161,7 +181,12 @@ var PanelMenuButton = GObject.registerClass(

repaintUi() {
const isRunningSpriteShown = this.data?.cpu > this.settings.idleThreshold;
const gicon = isRunningSpriteShown ? this.ui.icons.runningGenerator.next().value : this.ui.icons.idle;
const idleSprite = this.settings.animatedIdle
? this.ui.icons.idleGenerator.next().value
: this.ui.icons.idle;
const gicon = isRunningSpriteShown
? this.ui.icons.runningGenerator.next().value
: idleSprite;

this.ui.builder.get_object('icon').set_gicon(gicon);
this.ui.builder.get_object('label').set_text(`${Math.round(this.data.cpu)}%`);
Expand Down
9 changes: 8 additions & 1 deletion src/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ function fillPreferencesWindow(window) {
Gio.SettingsBindFlags.DEFAULT,
);

settings.bind(
Settings.ANIMATED_IDLE,
builder.get_object(Settings.ANIMATED_IDLE),
'state',
Gio.SettingsBindFlags.DEFAULT,
);

const combo = builder.get_object(Settings.DISPLAYING_ITEMS);
combo.set_selected(settings.get_enum(Settings.DISPLAYING_ITEMS));
combo.connect('notify::selected', widget => {
Expand All @@ -36,7 +43,7 @@ function fillPreferencesWindow(window) {

builder.get_object('reset').connect('clicked', () => {
settings.reset(Settings.IDLE_THRESHOLD);

settings.reset(Settings.ANIMATED_IDLE);
settings.reset(Settings.DISPLAYING_ITEMS);
combo.set_selected(settings.get_enum(Settings.DISPLAYING_ITEMS));
});
Expand Down
14 changes: 14 additions & 0 deletions src/resources/icons/cat/my-idle-0-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d9972bc

Please sign in to comment.