From 428f1c8f2e4c4217b3ff371ebe360fa663d14d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20L=C3=B6tscher?= Date: Mon, 12 Feb 2024 13:08:14 +0100 Subject: [PATCH] Use GLib.timeout_add instead of JS function --- demos/Progress Bar/main.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/demos/Progress Bar/main.js b/demos/Progress Bar/main.js index 20554c95..adbfe6b7 100644 --- a/demos/Progress Bar/main.js +++ b/demos/Progress Bar/main.js @@ -1,4 +1,5 @@ import Adw from "gi://Adw"; +import GLib from "gi://GLib"; const first_bar = workbench.builder.get_object("first"); const second_bar = workbench.builder.get_object("second"); @@ -33,30 +34,30 @@ function pulseProgress() { // Duration of animation const duration = 10000; const increment = pulse_period / duration; - const interval = setInterval(() => { + GLib.timeout_add(GLib.PRIORITY_DEFAULT, pulse_period, () => { if (counter >= 1.0) { - clearInterval(interval); counter = 0; second_bar.fraction = 0; - return; + return false; } second_bar.pulse(); counter += increment; - }, pulse_period); + return true; + }); } function updateTracker() { let time = 10; - const interval = setInterval(() => { + GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => { if (time === 0) { progress_tracker.label = ""; - clearInterval(interval); console.log("Operation complete!"); - return; + return false; } progress_tracker.label = `${time} seconds remaining…`; time -= 1; - }, 1000); + return true; + }); }