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 cutomizable timer duration #319

Merged
merged 27 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
344c3dd
Add new preference page for timer
pakaoraki Mar 9, 2024
e5d59f1
Add new keys
pakaoraki Mar 9, 2024
92fbb3e
Remove timer settings from general page
pakaoraki Mar 9, 2024
45ec40c
Use new duration keys
pakaoraki Mar 9, 2024
ca61f9b
Clean and remove old code
pakaoraki Mar 9, 2024
f725468
Fix timer
pakaoraki Mar 9, 2024
6d9dbc9
Replace Gtk.text with Gtk.entry
pakaoraki Mar 12, 2024
9830e4a
Set sensitive property on the ActionRow
pakaoraki Mar 12, 2024
18c0ce7
Change reset icon
pakaoraki Mar 13, 2024
c6c9171
Update translation
pakaoraki Mar 14, 2024
cc901fa
Clean code
pakaoraki Mar 14, 2024
6c6c424
Fix catalan translation
pakaoraki Mar 14, 2024
8a91c83
Clean code and syntax
pakaoraki Mar 15, 2024
0785c4a
Rename declarative value
pakaoraki Mar 15, 2024
19c19d6
Fix syntax
pakaoraki Mar 15, 2024
f5ded21
Remove css style error on reset button
pakaoraki Mar 15, 2024
3c1022a
Use only one key to store duration
pakaoraki Mar 15, 2024
b54c422
Add missing translations and update
pakaoraki Mar 15, 2024
2cbbf24
Fix syntax
pakaoraki Mar 15, 2024
e0728a8
Improve and fix code
pakaoraki Mar 15, 2024
2b885e2
Linter: remove jsdoc plugin
pakaoraki Apr 18, 2024
3fc6f86
Revert "Linter: remove jsdoc plugin"
pakaoraki Apr 30, 2024
f749cdd
Update translation
pakaoraki May 26, 2024
66c094d
Simplify code
pakaoraki Jun 22, 2024
4847883
Fix label plural display
pakaoraki Jul 1, 2024
529bf35
Custom duration detection: improve code
pakaoraki Jul 2, 2024
79d55c6
Fix swicth indentation spaces
pakaoraki Jul 2, 2024
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
74 changes: 45 additions & 29 deletions caffeine@patapon.info/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const INHIBIT_APPS_KEY = 'inhibit-apps';
const SHOW_INDICATOR_KEY = 'show-indicator';
const SHOW_NOTIFICATIONS_KEY = 'show-notifications';
const SHOW_TIMER_KEY = 'show-timer';
const DURATION_TIMER_INDEX = 'duration-timer';
const DURATION_TIMER_LIST = 'duration-timer-list';
const TOGGLE_STATE_KEY = 'toggle-state';
const USER_ENABLED_KEY = 'user-enabled';
const RESTORE_KEY = 'restore-state';
Expand Down Expand Up @@ -102,6 +102,12 @@ const DBusSessionManagerInhibitorProxy = Gio.DBusProxy.makeProxyWrapper(DBusSess
const DisabledIcon = 'my-caffeine-off-symbolic';
const EnabledIcon = 'my-caffeine-on-symbolic';
const TimerMenuIcon = 'stopwatch-symbolic';
const TimerIcons = [
'caffeine-short-timer-symbolic',
'caffeine-medium-timer-symbolic',
'caffeine-long-timer-symbolic',
'caffeine-infinite-timer-symbolic'
];

const ControlContext = {
NEVER: 0,
Expand All @@ -121,13 +127,6 @@ const AppsTrigger = {
ON_ACTIVE_WORKSPACE: 2
};

const TIMERS = [
[5, 10, 15, 20, 30, 'caffeine-short-timer-symbolic'],
[10, 20, 30, 40, 50, 'caffeine-medium-timer-symbolic'],
[30, 45, 60, 75, 80, 'caffeine-long-timer-symbolic'],
[0, 0, 0, 0, 0, 'caffeine-infinite-timer-symbolic']
];

const CaffeineToggle = GObject.registerClass(
class CaffeineToggle extends QuickSettings.QuickMenuToggle {
_init(settings, path) {
Expand All @@ -144,7 +143,7 @@ class CaffeineToggle extends QuickSettings.QuickMenuToggle {
let iconTheme = new St.IconTheme();
if (!iconTheme.has_icon(TimerMenuIcon)) {
this.finalTimerMenuIcon =
Gio.icon_new_for_string(`${this._path}/icons/${TimerMenuIcon}.svg`);
Gio.icon_new_for_string(`${this._path}/icons/hicolor/scalable/actions/${TimerMenuIcon}.svg`);
}
this._iconActivated = Gio.icon_new_for_string(`${this._path}/icons/${EnabledIcon}.svg`);
this._iconDeactivated = Gio.icon_new_for_string(`${this._path}/icons/${DisabledIcon}.svg`);
Expand All @@ -170,7 +169,7 @@ class CaffeineToggle extends QuickSettings.QuickMenuToggle {
() => this._iconName(),
`changed::${TIMER_KEY}`,
() => this._sync(),
`changed::${DURATION_TIMER_INDEX}`,
`changed::${DURATION_TIMER_LIST}`,
() => this._syncTimers(true),
this);
this.connect('destroy', () => {
Expand All @@ -183,27 +182,34 @@ class CaffeineToggle extends QuickSettings.QuickMenuToggle {
_syncTimers(resetDefault) {
this._itemsSection.removeAll();
this._timerItems.clear();
const durationIndex = this._settings.get_int(DURATION_TIMER_INDEX);
// Get duration list and add '0' for the 'infinite' entry (no timer)
let durationValues = this._settings.get_value(DURATION_TIMER_LIST).deepUnpack();
durationValues.push(0);

for (const timer of TIMERS) {
// Create menu timer
for (const [index, timer] of durationValues.entries()) {
let label = null;
if (timer[0] === 0) {
if (timer === 0) {
label = _('Infinite');
} else {
label = parseInt(timer[durationIndex]) + _(' minutes');
let hours = Math.floor(timer / 3600);
let minutes = Math.floor((timer % 3600) / 60);
if (hours !== 0) {
label = hours + _(' hours ');
}
if (minutes !== 0) {
label = label + minutes + _(' minutes');
}
}
if (!label) {
continue;
}

const icon = Gio.icon_new_for_string(`${this._path}/icons/${timer[5]}.svg`);
const icon = Gio.icon_new_for_string(`${this._path}/icons/${TimerIcons[index]}.svg`);
const item = new PopupMenu.PopupImageMenuItem(label, icon);

item.connectObject('activate', () => this._checkTimer(timer[durationIndex]), this);
this._timerItems.set(timer[durationIndex], item);
item.connectObject('activate', () => this._checkTimer(timer), this);
this._timerItems.set(timer, item);
this._itemsSection.addMenuItem(item);
}
this.menuEnabled = TIMERS.length > 2;

// Select active duration
if (resetDefault && this._settings.get_int(TIMER_KEY) !== 0) {
Expand Down Expand Up @@ -567,7 +573,7 @@ class Caffeine extends QuickSettings.SystemIndicator {
this._timerEnable = true;

// Get duration
let timerDelay = this._settings.get_int(TIMER_KEY) * 60;
let timerDelay = this._settings.get_int(TIMER_KEY);

// Execute Timer only if duration isn't set on infinite time
if (timerDelay !== 0) {
Expand All @@ -589,14 +595,16 @@ class Caffeine extends QuickSettings.SystemIndicator {
}
}

_printTimer(second) {
const min = Math.floor(second / 60);
const minS = Math.floor(second % 60).toLocaleString('en-US', {
minimumIntegerDigits: 2,
useGrouping: false
});
_printTimer(seconds) {
const hours = Math.floor(seconds / 3600).toString().padStart(2, '0');
const min = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');
const sec = Math.floor(seconds % 60).toString().padStart(2, '0');
// Print Timer in system Indicator and Toggle menu subLabel
this._updateLabelTimer(min + ':' + minS);
if (hours !== '00') {
this._updateLabelTimer(hours + ':' + min + ':' + sec);
} else {
this._updateLabelTimer(min + ':' + sec);
}
}

_removeTimer() {
Expand Down Expand Up @@ -797,8 +805,16 @@ class Caffeine extends QuickSettings.SystemIndicator {
_updateTimerSubtitle() {
if (!this._settings.get_boolean(TOGGLE_STATE_KEY)) {
const timerDuration = this._settings.get_int(TIMER_KEY);
const hours = Math.floor(timerDuration / 3600);
const min = Math.floor((timerDuration % 3600) / 60);
let timeLabel = hours !== 0
? hours + _(' hours ')
: '';
timeLabel += min !== 0
? min + _(' minutes')
: '';
this._caffeineToggle.subtitle = timerDuration !== 0
? parseInt(timerDuration) + _(' minutes')
? timeLabel
: null;
}
}
Expand Down
Loading
Loading