Skip to content

Commit c231d08

Browse files
auto-dark-light@gihaume: Version 1.2.1 (#6524)
* Corrects list's `Active` attribute default to `true` * Adds shell features support
1 parent a781ade commit c231d08

27 files changed

+371
-340
lines changed

auto-dark-light@gihaume/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
## 1.2.1 - 22.10.2024
2+
3+
- Custom commands launching feature:
4+
- Corrected list's `Active` attribute default to `true`
5+
- Added shell features support
6+
17
## 1.2.0 - 22.10.2024
28

3-
- Added commands launching feature
9+
- Added custom commands launching feature
410

511
## 1.1.0 - 02.09.2024
612

auto-dark-light@gihaume/files/auto-dark-light@gihaume/applet.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const Themes_handler = require('./lib/themes_handler.js');
22
const Background_handler = require('./lib/background_handler.js');
3-
const Twilights_calculator = require('./lib/twilights_calculator.js');
3+
const Twilights_calculator = require('./lib/twilights_calculator/twilights_calculator.js');
44
const Event_scheduler = require('./lib/event_scheduler.js');
55
const Timer_absolute = require('./lib/timer_absolute.js');
66
const Time_of_day = require('./lib/time_of_day.js');
77
const Time_change_listener = require('./lib/time_change_listener/time_change_listener.js');
88
const Timezone_change_listener = require('./lib/timezone_change_listener.js');
99
const Timezone_coordinates_finder = require('./lib/timezones_coordinates/timezone_coordinates_finder.js');
10-
const Sleep_wakeup_listener = require('./lib/sleep_wakeup_listener.js');
10+
const Sleep_wakeup_listener = require('./lib/sleep_wakeup_listener/sleep_wakeup_listener.js');
1111
const Color_scheme_change_listener = require('./lib/color_scheme_change_listener.js');
12-
const Commands_launcher = require('./lib/commands_launcher.js');
12+
const Commands_launcher = require('./lib/commands_launcher/commands_launcher.js');
1313
const { _ } = require('./lib/translator.js');
1414

1515
const Applet = imports.ui.applet;
@@ -120,7 +120,8 @@ class ThisApplet extends Applet.IconApplet {
120120
try {
121121
this.time_change_listener = new Time_change_listener(
122122
`${this.metadata.path}/lib/time_change_listener`,
123-
this._update.bind(this)
123+
this._update.bind(this),
124+
this._notify_error.bind(this)
124125
);
125126
} catch (error) {
126127
this._notify_critical(error.message);

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/background_handler.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const IO = {
1010
}
1111
};
1212

13-
/**
14-
* A `Cinnamon desktop` background handler that detects and applies the background settings.
15-
*/
13+
/** A `Cinnamon desktop` background handler that detects and applies the background settings. */
1614
class Background_handler {
1715
/**
1816
* @param {Settings.XletSettingsBase} settings - The settings of the desk/applet.
@@ -27,9 +25,7 @@ class Background_handler {
2725
settings.bindWithObject(this, keys.slideshow_folder, "slideshow_folder");
2826
}
2927

30-
/**
31-
* Detects and save the current background settings applied to Cinnamon desktop.
32-
*/
28+
/** Detects and save the current background settings applied to Cinnamon desktop. */
3329
detect() {
3430
this.is_slideshow = IO.SLIDESHOW. get_boolean(IO.KEYS.IS_SLIDESHOW);
3531
this.background_file = IO.BACKGROUND.get_string( IO.KEYS.BACKGROUND_FILE);
@@ -40,9 +36,7 @@ class Background_handler {
4036
this.slideshow_folder = IO.SLIDESHOW.get_string(IO.KEYS.SLIDESHOW_FOLDER).replace('directory://', "file://");
4137
}
4238

43-
/**
44-
* Applies the saved background settings to Cinnamon desktop.
45-
*/
39+
/** Applies the saved background settings to Cinnamon desktop. */
4640
apply() {
4741
IO.SLIDESHOW. set_boolean(IO.KEYS.IS_SLIDESHOW, this.is_slideshow);
4842
IO.BACKGROUND.set_string( IO.KEYS.BACKGROUND_FILE, this.background_file);

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/color_scheme_change_listener.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const Gio = imports.gi.Gio;
22

3-
/**
4-
* Listens for changes in the color scheme and calls the provided callback
5-
*/
3+
/** Listens for changes in the color scheme and calls the provided callback */
64
class Color_scheme_change_listener {
75
#interface = Gio.Settings.new('org.x.apps.portal');
86
#callback;
@@ -25,9 +23,7 @@ class Color_scheme_change_listener {
2523
}
2624
}
2725

28-
/**
29-
* Declare the object as finished to release any ressource acquired.
30-
*/
26+
/** Declare the object as finished to release any ressource acquired. */
3127
finalize() { this.disable(); }
3228
}
3329

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/commands_launcher.js renamed to auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/commands_launcher/commands_launcher.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const launch_command = require('./lib/launch_command.js');
1+
const launch_command = require('./lib/commands_launcher/launch_command.js');
22
const { _ } = require('./lib/translator.js');
33

44
const {Gio, GLib} = imports.gi;
55

6+
/** A launcher for the commands of the settings list. */
67
class Commands_launcher {
78
#callback_for_errors;
89

910
/**
1011
* @param {Settings.XletSettingsBase} settings - The settings of the desk/applet.
1112
* @param {object} key_of_list - The keys of the settings' commands list.
12-
* @param {function(string): void} callback_for_errors - The callback with a message for when an error occurs.
13+
* @param {function(string): void} callback_for_errors - The function to call with a message for when an error occurs.
1314
*/
1415
constructor(settings, key_of_list, callback_for_errors) {
1516
settings.bindWithObject(this, key_of_list, "list");
@@ -19,13 +20,13 @@ class Commands_launcher {
1920
async launch_commands() {
2021
for (const item of this.list) {
2122
const { name, active, expiry, command } = item;
22-
2323
if (!active)
2424
continue;
2525

2626
try { await launch_command(command, expiry); }
2727
catch (error) {
28-
let msg = `${_("the command")} '${name}' ${_("failed")}`;
28+
const name_for_error = name !== '' ? name : command;
29+
let msg = `${_("the command")} '${name_for_error}' ${_("failed")}`;
2930
if (error instanceof GLib.ShellError)
3031
msg += ` ${_("due to a wrong format")}${_(":")} ${error.message}`;
3132
else

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/launch_command.js renamed to auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/commands_launcher/launch_command.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Gio._promisify(Gio.Subprocess.prototype, 'communicate_utf8_async');
44

55
/**
66
* Executes a command with a timeout and transmits any error on failure.
7-
*
87
* @async
98
* @param {string} command - The shell command to execute.
109
* @param {number} [timeout_seconds=10] - The delay in seconds before cancelling the command. `0` means infinity/never.
@@ -14,6 +13,7 @@ Gio._promisify(Gio.Subprocess.prototype, 'communicate_utf8_async');
1413
* @throws {Gio.IOErrorEnum.FAILED} - If the command fails with a non-zero exit code. The error message is the `stderr` output if any, otherwise the exit status.
1514
*/
1615
async function launch_command(command, timeout_seconds = 10) {
16+
command = `sh -c ${GLib.shell_quote(`exec ${command}`)}`; // brings shell features
1717
const [_ok, argvp] = GLib.shell_parse_argv(command); // can throw GLib.ShellError
1818

1919
const proc = new Gio.Subprocess({

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/dbus.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const {Gio, GLib} = imports.gi;
22

33
class Dbus {
4-
/**
5-
* An interface to read the system screensaver lock state.
6-
*/
4+
/** An interface to read the system screensaver lock state. */
75
static Screen_lock = class {
86
#signal_id;
97

@@ -61,9 +59,7 @@ class Dbus {
6159
}
6260
}
6361

64-
/**
65-
* An interface to read the system sleep/wakeup state.
66-
*/
62+
/** An interface to read the system sleep/wakeup state. */
6763
static Sleep = class {
6864
#signal_id;
6965

@@ -97,9 +93,7 @@ class Dbus {
9793
}
9894
}
9995

100-
/**
101-
* An interface to read the system timezone.
102-
*/
96+
/** An interface to read the system timezone. */
10397
static Timezone = class {
10498
#signal_id;
10599

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/event_scheduler.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ const Mainloop = imports.mainloop;
22

33
const Time_of_day = require('./lib/time_of_day.js');
44

5-
/**
6-
* A single-event scheduler which call a function at a specified due time of day.
7-
*/
5+
/** A single-event scheduler which call a function at a specified due time of day. */
86
class Event_scheduler {
97
#event_id;
108

@@ -29,19 +27,15 @@ class Event_scheduler {
2927
// );
3028
}
3129

32-
/**
33-
* Unset the scheduled event if it exists.
34-
*/
30+
/** Unset the scheduled event if it exists. */
3531
unset_the_event() {
3632
if (this.#event_id !== undefined) {
3733
Mainloop.source_remove(this.#event_id);
3834
this.#event_id = undefined;
3935
}
4036
}
4137

42-
/**
43-
* Declare the object as finished to release any ressource acquired.
44-
*/
38+
/** Declare the object as finished to release any ressource acquired. */
4539
finalize() { this.unset_the_event(); }
4640

4741
}

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/screen_lock_handler.js renamed to auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/sleep_wakeup_listener/screen_lock_checker.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const Dbus = require('./lib/dbus.js');
22

3-
/**
4-
* A gatekeeper for the screen locked state.
5-
*/
6-
class Screen_lock_handler {
3+
/** A gatekeeper for the screen locked state. */
4+
class Screen_lock_checker {
75
#lock = new Dbus.Screen_lock();
86

97
/**
@@ -24,15 +22,11 @@ class Screen_lock_handler {
2422
});
2523
}
2624

27-
/**
28-
* Cancel the `try_now_or_postpone` procedure.
29-
*/
25+
/** Cancel the `try_now_or_postpone` procedure. */
3026
cancel() { this.#lock.unsubscribe_to_changes(); }
3127

32-
/**
33-
* Declare the object as finished to release any ressource acquired.
34-
*/
28+
/** Declare the object as finished to release any ressource acquired. */
3529
finalize() { this.cancel(); }
3630
}
3731

38-
module.exports = Screen_lock_handler;
32+
module.exports = Screen_lock_checker;

auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/sleep_wakeup_listener.js renamed to auto-dark-light@gihaume/files/auto-dark-light@gihaume/lib/sleep_wakeup_listener/sleep_wakeup_listener.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
const Dbus = require('./lib/dbus.js');
2-
const Screen_lock_handler = require('./lib/screen_lock_handler.js');
2+
const Screen_lock_checker = require('./lib/sleep_wakeup_listener/screen_lock_checker.js');
33

4-
/**
5-
* A gatekeeper for the sleep combined with the screen locked on wakeup.
6-
*/
4+
/** A gatekeeper for the sleep combined with the screen locked on wakeup. */
75
class Sleep_wakeup_listener {
8-
#sleep = new Dbus.Sleep();
9-
#lock = new Screen_lock_handler();
6+
#sleep_dbus = new Dbus.Sleep();
7+
#lock_checker = new Screen_lock_checker();
108
#on_sleep_entry_callback;
119
#on_wakeup_unlocked_callback;
1210

@@ -20,27 +18,25 @@ class Sleep_wakeup_listener {
2018
}
2119

2220
enable() {
23-
this.#sleep.subscribe_to_changes((is_sleeping) => {
21+
this.#sleep_dbus.subscribe_to_changes((is_sleeping) => {
2422
if (is_sleeping)
2523
this.#on_sleep_entry_callback();
2624
else
27-
this.#lock.try_now_or_postpone_until_unlocked(
25+
this.#lock_checker.try_now_or_postpone_until_unlocked(
2826
this.#on_wakeup_unlocked_callback.bind(this)
2927
);
3028
});
3129
}
3230

3331
disable() {
34-
this.#sleep.unsubscribe_to_changes();
35-
this.#lock.cancel();
32+
this.#sleep_dbus.unsubscribe_to_changes();
33+
this.#lock_checker.cancel();
3634
}
3735

38-
/**
39-
* Declare the object as finished to release any ressource acquired.
40-
*/
36+
/** Declare the object as finished to release any ressource acquired. */
4137
finalize() {
42-
this.#sleep.unsubscribe_to_changes();
43-
this.#lock.finalize();
38+
this.#sleep_dbus.unsubscribe_to_changes();
39+
this.#lock_checker.finalize();
4440
}
4541
}
4642

0 commit comments

Comments
 (0)