Use timeout instead of interval

This commit is contained in:
Eduard Urbach 2018-04-13 14:18:08 +02:00
parent c691eb8017
commit 6d8329a4eb

View File

@ -1,7 +1,7 @@
import AnimeNotifier from "../AnimeNotifier" import AnimeNotifier from "../AnimeNotifier"
let currentTheme = "light" let currentTheme = "light"
let intervalID: number = 0 let timeoutID: number = 0
const light = {} const light = {}
const dark = { const dark = {
@ -47,7 +47,7 @@ const dark = {
// Toggle theme // Toggle theme
export function toggleTheme(arn: AnimeNotifier) { export function toggleTheme(arn: AnimeNotifier) {
// Clear preview interval // Clear preview interval
clearInterval(intervalID) clearTimeout(timeoutID)
if(currentTheme === "light") { if(currentTheme === "light") {
darkTheme(arn) darkTheme(arn)
@ -80,7 +80,7 @@ export function darkTheme(arn: AnimeNotifier) {
arn.statusMessage.showInfo("Previewing Dark theme for 30 seconds. If you would like to use it permanently, please support us.", 5000) arn.statusMessage.showInfo("Previewing Dark theme for 30 seconds. If you would like to use it permanently, please support us.", 5000)
// After 30 seconds, switch back to default theme if the user doesn't own a PRO account // After 30 seconds, switch back to default theme if the user doesn't own a PRO account
intervalID = setInterval(() => { timeoutID = setTimeout(() => {
if(currentTheme === "dark") { if(currentTheme === "dark") {
toggleTheme(arn) toggleTheme(arn)
arn.statusMessage.showInfo("Dark theme preview time has ended. If you would like to use it permanently, please support us.", 5000) arn.statusMessage.showInfo("Dark theme preview time has ended. If you would like to use it permanently, please support us.", 5000)