Skip to content

Commit

Permalink
v2.5.10: Better monitoring of files and directories (linuxmint#6725)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiux authored Jan 2, 2025
1 parent 76fa9a8 commit fad255f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 99 deletions.
5 changes: 4 additions & 1 deletion Radio3.0@claudiux/files/Radio3.0@claudiux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### v2.5.8~20241231
### v2.5.10~20250101
* Better monitoring of files and directories.

### v2.5.9~20241231
* Album Art 3.0 becomes faster.
* Bugfixes.

Expand Down
29 changes: 23 additions & 6 deletions Radio3.0@claudiux/files/Radio3.0@claudiux/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,12 @@ var R3PopupMenu = class R3PopupMenu extends PopupMenu {
if (!sourceActor._applet_context_menu.isOpen)
sourceActor.actor.change_style_pseudo_class("checked", open);
}

destroy() {
this._signals.disconnectAllSignals();
//~ this.actor.destroy();
this.emit('destroy');
}
}

class WebRadioReceiverAndRecorder extends TextIconApplet {
Expand Down Expand Up @@ -1269,6 +1275,14 @@ class WebRadioReceiverAndRecorder extends TextIconApplet {
this.recMonitor = null;
this.recMonitorId = null;

// Other monitors:
this.r30stopMonitor = null;
this.r30stopMonitorId = null;
this.r30nextMonitor = null;
this.r30nextMonitorId = null;
this.r30previousMonitor = null;
this.r30previousMonitorId = null;

// Run all monitors:
this.on_network_monitoring_changed();
this.monitor_mpv_title();
Expand Down Expand Up @@ -1927,11 +1941,11 @@ class WebRadioReceiverAndRecorder extends TextIconApplet {
if (this.r30stopMonitor == null) return;

try {
if (this.r30stopMonitorId > 0) {
if (this.r30stopMonitorId != null) {
//this.r30stopMonitor.cancel();
this.r30stopMonitor.disconnect(this.r30stopMonitorId);
this.r30stopMonitor = null;
this.r30stopMonitorId = 0;
this.r30stopMonitorId = null;
}
} catch(e) {
logError("Unable to unmonitor %s!".format(R30STOP), e)
Expand All @@ -1942,11 +1956,11 @@ class WebRadioReceiverAndRecorder extends TextIconApplet {
if (this.r30previousMonitor == null) return;

try {
if (this.r30previousMonitorId > 0) {
if (this.r30previousMonitorId != null) {
//this.r30previousMonitor.cancel();
this.r30previousMonitor.disconnect(this.r30previousMonitorId);
this.r30previousMonitor = null;
this.r30previousMonitorId = 0;
this.r30previousMonitorId = null;
}
} catch(e) {
logError("Unable to unmonitor %s!".format(R30PREVIOUS), e)
Expand All @@ -1957,25 +1971,27 @@ class WebRadioReceiverAndRecorder extends TextIconApplet {
if (this.r30nextMonitor == null) return;

try {
if (this.r30nextMonitorId > 0) {
if (this.r30nextMonitorId != null) {
//this.r30nextMonitor.cancel();
this.r30nextMonitor.disconnect(this.r30nextMonitorId);
this.r30nextMonitor = null;
this.r30nextMonitorId = 0;
this.r30nextMonitorId = null;
}
} catch(e) {
logError("Unable to unmonitor %s!".format(R30NEXT), e)
}
}

_on_r30stop_changed() {
if (this.actor.get_stage() == null) return;
let file = file_new_for_path(R30STOP);
if (file.query_exists(null)) {
this.stop_mpv();
}
}

_on_mpv_title_changed() {
if (this.actor.get_stage() == null) return;
//log("_on_mpv_title_changed: " + MPV_TITLE_FILE);

let title = to_string(file_get_contents(MPV_TITLE_FILE)[1]).trim();
Expand Down Expand Up @@ -2086,6 +2102,7 @@ class WebRadioReceiverAndRecorder extends TextIconApplet {
}

_on_jobs_dir_changed() {
if (this.actor.get_stage() == null) return;
//log("_on_jobs_dir_changed: " + JOBS_DIR);

let dir = file_new_for_path(JOBS_DIR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//"use strict";
const Main = imports.ui.main;
const Gio = imports.gi.Gio;
const St = imports.gi.St;
const Desklet = imports.ui.desklet;
Expand All @@ -22,6 +23,7 @@ class AlbumArtRadio30 extends Desklet.Desklet {
this.update_id = null;
this.old_image_path = null;
this.isLooping = true;
this.dir_monitor_loop_is_active = true;

this.dir = "file://"+GLib.get_home_dir()+"/.config/Radio3.0/song-art";
this.shuffle = false;
Expand All @@ -45,16 +47,6 @@ class AlbumArtRadio30 extends Desklet.Desklet {

on_setting_changed() {
this.isLooping = false;
//~ if (this.update_id) {
//~ try {
//~ if (Mainloop.source_remove(this.update_id)) this.update_id = null;
//~ }
//~ catch(e) {
//~ this.update_id = null;
//~ } finally {
//~ this.update_id = null;
//~ }
//~ }

this._setup_dir_monitor();
if (this.currentPicture) {
Expand All @@ -68,54 +60,32 @@ class AlbumArtRadio30 extends Desklet.Desklet {
}

_setup_dir_monitor() {
if (this.dir_monitor_id && this.dir_monitor) {
this.dir_monitor.disconnect(this.dir_monitor_id);
this.dir_monitor_id = null;
}

/* The widget used to choose the folder the images are drawn from
was changed to use a URI instead of a path. This check is just
to ensure that people upgrading cinnamon versions will get the
existing path converted to a proper URI */
if (this.dir.indexOf('://') === -1) {
let file = Gio.file_new_for_path(this.dir);
this.dir = file.get_uri();
}

if (this.dir === ' ') {
let file = Gio.file_new_for_path(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES));
this.dir = file.get_uri();
}
if (this.dir_monitor_id != null) return;

this.dir_file = Gio.file_new_for_uri(this.dir);
this.dir_monitor = this.dir_file.monitor_directory(0, null);
this.dir_monitor_id = this.dir_monitor.connect('changed', Lang.bind(this, this.on_setting_changed));
this.dir_monitor_id = this.dir_monitor.connect('changed', Lang.bind(this, this.dir_monitor_loop));
}

//~ on_desklet_added_to_desktop(userEnabled) {
//~ this.actor.reactive = true;
//~ }
dir_monitor_loop() {
if (!this.dir_monitor_loop_is_active) {
this.dir_monitor_id = null;
return false;
}
this.on_setting_changed();
return true;
}

on_desklet_removed() {
if (this.dir_monitor) {
//~ if (this.dir_monitor) {
//~ this.dir_monitor.disconnectAllSignals();
this.dir_monitor.disconnect(this.dir_monitor_id);
//~ this.dir_monitor.disconnect(this.dir_monitor_id);
//~ this.dir_monitor_id = null;
}
this.dir_monitor_id = null;
//~ }
//~ this.dir_monitor_id = null;

this.isLooping = false;

//~ if (this.update_id) {
//~ try {
//~ if (Mainloop.source_remove(this.update_id)) this.update_id = null;
//~ }
//~ catch(e) {
//~ this.update_id = null;
//~ } finally {
//~ this.update_id = null;
//~ }
//~ }
this.dir_monitor_loop_is_active = false;
}

_scan_dir(dir) {
Expand Down Expand Up @@ -152,23 +122,6 @@ class AlbumArtRadio30 extends Desklet.Desklet {
this.setContent(this._photoFrame);
}

//~ if (this.effect == 'black-and-white') {
//~ let effect = new Clutter.DesaturateEffect();
//~ this._bin.add_effect(effect);
//~ } else if (this.effect == 'sepia') {
//~ let color = new Clutter.Color();
//~ color.from_hls(17.0, 0.59, 0.4);
//~ let colorize_effect = new Clutter.ColorizeEffect(color);
//~ let contrast_effect = new Clutter.BrightnessContrastEffect();
//~ let desaturate_effect = new Clutter.DesaturateEffect();
//~ desaturate_effect.set_factor(0.41);
//~ contrast_effect.set_brightness_full(0.1, 0.1, 0.1);
//~ contrast_effect.set_contrast_full(0.1, 0.1, 0.1);
//~ this._bin.add_effect(colorize_effect);
//~ this._bin.add_effect(contrast_effect);
//~ this._bin.add_effect(desaturate_effect);
//~ }

if (this.dir_file.query_exists(null)) {
this._scan_dir(this.dir);

Expand All @@ -183,21 +136,6 @@ class AlbumArtRadio30 extends Desklet.Desklet {
_update_loop() {
if (!this.isLooping) return false;
this._update();
//~ if (this.update_id) {
//~ try {
//~ if (Mainloop.source_remove(this.update_id)) this.update_id = null;
//~ }
//~ catch(e) {
//~ // Nothing to do.
//~ } finally {
//~ this.update_id = Mainloop.timeout_add_seconds(this.delay, Lang.bind(this, this._update_loop));
//~ }
//~ }
//~ if (this.update_id) {
//~ return true
//~ } else {
//~ this.update_id = Mainloop.timeout_add_seconds(this.delay, Lang.bind(this, this._update_loop));
//~ }
if (this.isLooping)
this.update_id = Mainloop.timeout_add_seconds(this.delay, Lang.bind(this, this._update_loop));
else
Expand All @@ -223,8 +161,6 @@ class AlbumArtRadio30 extends Desklet.Desklet {
}

_update() {
//~ this._show_or_hide();

if (this.updateInProgress) {
return;
}
Expand Down Expand Up @@ -294,7 +230,6 @@ class AlbumArtRadio30 extends Desklet.Desklet {
on_desklet_clicked(event) {
try {
if (event.get_button() == 1) {
//~ this._update();
this.on_setting_changed();
} else if (event.get_button() == 2) {
Util.spawn(['xdg-open', this.currentPicture.path]);
Expand All @@ -316,15 +251,6 @@ class AlbumArtRadio30 extends Desklet.Desklet {
return null;
}
}

//~ _show_or_hide() {
//~ if (GLib.file_test(GLib.get_home_dir()+"/.local/share/cinnamon/desklets/AlbumArt3.0@claudiux/HIDDEN", GLib.FileTest.EXISTS)) {
//~ if (this.actor) this.actor.hide();
//~ }
//~ else {
//~ if (this.actor) this.actor.show();
//~ }
//~ }
}

function main(metadata, desklet_id) {
Expand Down
2 changes: 1 addition & 1 deletion Radio3.0@claudiux/files/Radio3.0@claudiux/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"description": "The Ultimate Internet Radio Receiver & Recorder for Cinnamon",
"max-instances": 1,
"version": "2.5.9",
"version": "2.5.10",
"uuid": "Radio3.0@claudiux",
"name": "Radio3.0",
"author": "claudiux",
Expand Down

0 comments on commit fad255f

Please sign in to comment.