Skip to content

Commit

Permalink
chore: Refine the icon animation transition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhua committed Jan 25, 2025
1 parent b2d6f34 commit 5204009
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
15 changes: 4 additions & 11 deletions js/IconUtils/AnimationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class AnimationController {

// Set new timeout for auto-stop
this.timeoutId = setTimeout(() => {
this.#stop(type);
this.#stop();
}, newAnimation.duration);
}

Expand All @@ -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);
Expand All @@ -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 () => {
Expand All @@ -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();
}
}
}
13 changes: 13 additions & 0 deletions js/IconUtils/IconManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class IconManager {
static IconType = 'Default';
static async setIcon(imageData) {
try {
await chrome.action.setIcon({ imageData });
Expand All @@ -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",
Expand All @@ -24,6 +36,7 @@ export class IconManager {

static async setToDark() {
try {
IconManager.IconType = 'Dark';
await chrome.action.setIcon({
path: {
'32': "images/logo32-dark.png",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 5204009

Please sign in to comment.