From 52040093d88e87c743b1bbb7bff4aaa10b2eedd3 Mon Sep 17 00:00:00 2001 From: Alex Hua Date: Fri, 24 Jan 2025 19:57:09 +0800 Subject: [PATCH] chore: Refine the icon animation transition logic --- js/IconUtils/AnimationController.js | 15 ++++----------- js/IconUtils/IconManager.js | 13 +++++++++++++ manifest.json | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/js/IconUtils/AnimationController.js b/js/IconUtils/AnimationController.js index f91e13b..6bdeb0b 100644 --- a/js/IconUtils/AnimationController.js +++ b/js/IconUtils/AnimationController.js @@ -67,7 +67,7 @@ export class AnimationController { // Set new timeout for auto-stop this.timeoutId = setTimeout(() => { - this.#stop(type); + this.#stop(); }, newAnimation.duration); } @@ -81,7 +81,7 @@ export class AnimationController { }, FRAME_INTERVAL); } - async #stop(type) { + async #stop() { // Clear the auto-stop timeout if it exists if (this.timeoutId) { clearTimeout(this.timeoutId); @@ -93,13 +93,6 @@ export class AnimationController { this.intervalId = null; } - // No need fade-out for progress animation - if (type == 'Progress') { - this.progressAnimation?.setProgress(0); - this.transitionManager.currentAnimation = null; - return; - }; - if (this.transitionManager.currentAnimation) { let progress = 0; this.fadeIntervalId = setInterval(async () => { @@ -111,11 +104,11 @@ export class AnimationController { clearInterval(this.fadeIntervalId); this.fadeIntervalId = null; this.transitionManager.currentAnimation = null; - await IconManager.setToDefault(); + await IconManager.restore(); } }, FADE_INTERVAL); } else { - await IconManager.setToDefault(); + await IconManager.restore(); } } } diff --git a/js/IconUtils/IconManager.js b/js/IconUtils/IconManager.js index 8ff4c05..0535fa3 100644 --- a/js/IconUtils/IconManager.js +++ b/js/IconUtils/IconManager.js @@ -1,4 +1,5 @@ export class IconManager { + static IconType = 'Default'; static async setIcon(imageData) { try { await chrome.action.setIcon({ imageData }); @@ -7,8 +8,19 @@ export class IconManager { } } + static async restore() { + if (IconManager.IconType == 'Default') { + await this.setToDefault(); + } else if (IconManager.IconType == 'Dark') { + await this.setToDark(); + } else { + throw new Error("IconManager: Invalid icon type"); + } + } + static async setToDefault() { try { + IconManager.IconType = 'Default'; await chrome.action.setIcon({ path: { '32': "images/logo32.png", @@ -24,6 +36,7 @@ export class IconManager { static async setToDark() { try { + IconManager.IconType = 'Dark'; await chrome.action.setIcon({ path: { '32': "images/logo32-dark.png", diff --git a/manifest.json b/manifest.json index 4fa90cc..823210f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_appName__", "short_name": "A2E", - "version": "2.6.0", + "version": "2.6.1", "manifest_version": 3, "minimum_chrome_version": "116.0.0", "default_locale": "en",