From 609c136bb0dc58348b06956b2aaa9d099aa7fa9c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 15 Feb 2020 14:36:23 +0900 Subject: [PATCH] fixed webview not updating on time --- Cargo.lock | 2 +- Cargo.toml | 3 ++- web/index.html | 6 +++--- web/script.js | 31 ++++++++++++++----------------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48baa68..9558da1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -695,7 +695,7 @@ dependencies = [ [[package]] name = "soundsense-rs" -version = "1.4.1" +version = "1.4.3-alpha" dependencies = [ "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 33748bc..0913929 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "soundsense-rs" -version = "1.4.1" +version = "1.4.3-alpha" build = "build.rs" authors = ["prixt "] edition = "2018" +description = "A Rusty SoundSense alternative" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/web/index.html b/web/index.html index 5a6d8c9..bcb0025 100644 --- a/web/index.html +++ b/web/index.html @@ -35,11 +35,11 @@ Options
+ onclick="external.invoke('link_original')">🔗 zwei's original SoundSense & soundpack + onclick="external.invoke('link_fork')">🔗 jecowa's soundpack fork + onclick="external.invoke('show_about')">ℹī¸ About
diff --git a/web/script.js b/web/script.js index 66efe6f..1a5cc0b 100644 --- a/web/script.js +++ b/web/script.js @@ -35,14 +35,11 @@ function createSlider(channel_name) { } function setSliderValue(channel_name, value) { let slider = document.getElementById(channel_name+"_slider"); - if (slider != null) { - slider.value = value; - } + if (slider != null) slider.value = value; } function clearSliders() { - while (channels.firstChild) { + while (channels.firstChild) channels.removeChild(channels.firstChild); - } } let alerts_footer = null; @@ -52,9 +49,8 @@ function addAlert(name, color, text) { let new_alert = createAlert(name, color, text); alerts[name] = new_alert; alerts_footer.insertAdjacentElement('afterbegin', new_alert); - if (alerts_footer.childElementCount > 4) { + if (alerts_footer.childElementCount > 4) removeAlert(alerts_footer.lastChild.name); - } } function removeAlert(name) { let alert = document.getElementById("alert_"+name); @@ -86,19 +82,20 @@ function main() { alerts_footer = document.getElementById('alerts'); alerts = new Map(); - let prev = Date.now(); + let prev = null; function step(now) { - let dt = (now - prev) * 0.001; - prev = now; + let dt = 0.0; + if (prev != null) dt = (now - prev) * 0.001; + prev = now; - for (let key in alerts) { - let alert = alerts[key]; - alert.timer -= dt; - if (alert.timer <= 1) {alert.style.opacity = alert.timer;} - if (alert.timer <= 0) {removeAlert(alert.name);} - } + for (let key in alerts) { + let alert = alerts[key]; + alert.timer -= dt; + if (alert.timer <= 1.0) alert.style.opacity = alert.timer; + if (alert.timer <= 0.0) removeAlert(alert.name); + } - window.requestAnimationFrame(step); + window.requestAnimationFrame(step); } window.requestAnimationFrame(step);