From 70616524e03995d0d55db04c628b1e1c3f718218 Mon Sep 17 00:00:00 2001 From: claudiux <33965039+claudiux@users.noreply.github.com> Date: Fri, 17 Jan 2025 01:58:50 +0100 Subject: [PATCH] mainloopTools library: improvements (#1387) --- .../lib/mainloopTools.js | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/googleCalendar@javahelps.com/files/googleCalendar@javahelps.com/lib/mainloopTools.js b/googleCalendar@javahelps.com/files/googleCalendar@javahelps.com/lib/mainloopTools.js index ccebf2e2..18511f57 100644 --- a/googleCalendar@javahelps.com/files/googleCalendar@javahelps.com/lib/mainloopTools.js +++ b/googleCalendar@javahelps.com/files/googleCalendar@javahelps.com/lib/mainloopTools.js @@ -17,7 +17,9 @@ var _sourceIds = []; * */ function timeout_add_seconds(sec, callback, params=null) { - let id = Mainloop.timeout_add_seconds(sec, callback, params); + //~ let id = Mainloop.timeout_add_seconds(sec, callback, params); + //~ let id = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, sec, callback, params); + let id = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, sec, callback); if (id && (_sourceIds.indexOf(id) === -1)) _sourceIds.push(id); return id; } @@ -32,7 +34,9 @@ function timeout_add_seconds(sec, callback, params=null) { * */ function timeout_add(ms, callback, params=null) { - let id = Mainloop.timeout_add_seconds(ms, callback, params); + //~ let id = Mainloop.timeout_add_seconds(ms, callback, params); + //~ let id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, ms, callback, params); + let id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, ms, callback); if (id && (_sourceIds.indexOf(id) === -1)) _sourceIds.push(id); return id; } @@ -53,10 +57,14 @@ function setTimeout(callback, ms) { args = args.slice.call(arguments, 2); } - let id = Mainloop.timeout_add(ms, () => { + //~ let id = Mainloop.timeout_add(ms, () => { + let id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, + ms, + () => { callback.call(null, ...args); return false; // Stop repeating - }, null); + } + ); if (id && (_sourceIds.indexOf(id) === -1)) _sourceIds.push(id); @@ -71,7 +79,8 @@ function setTimeout(callback, ms) { */ function clearTimeout(id) { if (id) { - Mainloop.source_remove(id); + //~ Mainloop.source_remove(id); + GLib.source_remove(id); const pos = _sourceIds.indexOf(id); if (pos > -1) _sourceIds.splice(pos, 1); } @@ -94,10 +103,11 @@ function setInterval(callback, ms) { args = args.slice.call(arguments, 2); } - let id = Mainloop.timeout_add(ms, () => { + //~ let id = Mainloop.timeout_add(ms, () => { + let id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, ms, () => { callback.call(null, ...args); return true; // Repeat - }, null); + }); if (id && (_sourceIds.indexOf(id) === -1)) _sourceIds.push(id); @@ -112,7 +122,8 @@ function setInterval(callback, ms) { */ function clearInterval(id) { if (id) { - Mainloop.source_remove(id); + //~ Mainloop.source_remove(id); + GLib.source_remove(id); const pos = _sourceIds.indexOf(id); if (pos > -1) _sourceIds.splice(pos, 1); } @@ -154,7 +165,8 @@ function source_exists(id) { */ function source_remove(id, remove_from_sourceIds=true) { if (source_exists(id)) { - Mainloop.source_remove(id); + //~ Mainloop.source_remove(id); + GLib.source_remove(id); if (remove_from_sourceIds) { const pos = _sourceIds.indexOf(id); if (pos > -1) _sourceIds.splice(pos, 1);