From e20fd331efeaf9d07b0fa99af0b498de90f4b9ae Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 1 Apr 2022 14:42:03 -0600 Subject: [PATCH 1/2] switch to manager for toasts --- scripts/startup/preload.js | 6 +++++- scripts/toast/createtoast.js | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/startup/preload.js b/scripts/startup/preload.js index f934d20..fad3280 100755 --- a/scripts/startup/preload.js +++ b/scripts/startup/preload.js @@ -23,7 +23,11 @@ window.addEventListener('DOMContentLoaded', () => { name: "Alpha", semver: require('../../package.json').version }, - platform: undefined + platform: undefined, + toasts: { + total: 0, + shown: [] + } }; const platform = ipcRenderer.sendSync('preload', 'request-platform'); diff --git a/scripts/toast/createtoast.js b/scripts/toast/createtoast.js index 19d0a41..08742fc 100755 --- a/scripts/toast/createtoast.js +++ b/scripts/toast/createtoast.js @@ -40,7 +40,12 @@ module.exports = (name, text, bg = '#a172a6', persistOnClick = false, time = 5, timer.style.backgroundColor = timerColor; timer.style.animation = `toast-timer ${time}s linear`; toastWrap.appendChild(timer); - //toast.onmouseenter = () => {timer.style.animationPlayState = 'paused';}; + toast.id = `toast-${window.kade.toasts.total}`; //toast.onmouseleave = () => {timer.style.animationPlayState = 'normal';}; setTimeout(() => {if (continueTimeout) {removeToast(toast);}}, time * 1000); + window.kade.toasts.shown[window.kade.toasts.total] = { + timer, + toast, + }; + window.kade.toasts.total++; }; \ No newline at end of file From 2524979142b5f4fe5b778bdb7e515677d2e33e07 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 1 Apr 2022 14:46:47 -0600 Subject: [PATCH 2/2] pause toast timers kinda. this feature is not fully working toasts randomly disappear will investigate when i have the will to like, care --- scripts/toast/createtoast.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/toast/createtoast.js b/scripts/toast/createtoast.js index 08742fc..a0334c3 100755 --- a/scripts/toast/createtoast.js +++ b/scripts/toast/createtoast.js @@ -8,8 +8,6 @@ module.exports = (name, text, bg = '#a172a6', persistOnClick = false, time = 5, toast.style.backgroundColor = `${bg}c2`; toast.style.borderColor = `${bg}c2`; toast.classList.add('toast-entering'); - toast.onmouseenter = () => {toast.style.backgroundColor = bg;}; - toast.onmouseleave = () => {toast.style.backgroundColor = `${bg}c2`;}; let toastWrap = document.createElement('div'); toastWrap.className = 'toast-wrapper'; let continueTimeout = true; @@ -41,11 +39,26 @@ module.exports = (name, text, bg = '#a172a6', persistOnClick = false, time = 5, timer.style.animation = `toast-timer ${time}s linear`; toastWrap.appendChild(timer); toast.id = `toast-${window.kade.toasts.total}`; - //toast.onmouseleave = () => {timer.style.animationPlayState = 'normal';}; - setTimeout(() => {if (continueTimeout) {removeToast(toast);}}, time * 1000); + toast.onmouseenter = () => { + let ctoast = window.kade.toasts.shown[toast.id.slice(6)]; + ctoast.toast.style.backgroundColor = bg; + ctoast.timer.style.animationPlayState = 'paused'; + clearTimeout(ctoast.timeout); + ctoast.tl = ctoast.tt - (Date.now() - ctoast.ts); + }; + toast.onmouseleave = () => { + let ctoast = window.kade.toasts.shown[toast.id.slice(6)]; + ctoast.toast.style.backgroundColor = `${bg}c2`; + ctoast.timer.style.animationPlayState = 'running'; + ctoast.timeout = setTimeout(() => {if (continueTimeout) {removeToast(ctoast.toast);}}, ctoast.tl); + }; window.kade.toasts.shown[window.kade.toasts.total] = { + timeout: setTimeout(() => {if (continueTimeout) {removeToast(toast);}}, time * 1000), timer, toast, + tl: time * 1000, + ts: Date.now(), + tt: time * 1000 }; window.kade.toasts.total++; }; \ No newline at end of file