Skip to content

fix: keep Windows notification badge state in sync#12451

Open
huhuanming wants to merge 3 commits into
xfrom
codex/fix-windows-notification-badge-state
Open

fix: keep Windows notification badge state in sync#12451
huhuanming wants to merge 3 commits into
xfrom
codex/fix-windows-notification-badge-state

Conversation

@huhuanming

@huhuanming huhuanming commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace electron-taskbar-badge with a OneKey-owned Windows taskbar badge helper.
  • Keep badge state synchronized across clear, window show, accent-color changes, and overlapping asynchronous renders.
  • Remove the third-party dependency and its patch-package patch.

Intent & Context

This is a follow-up to #12447. The CommonJS loader fixed the original BadgeGenerator2 is not a constructor crash, but clearing the Windows notification badge could still restore the previous count.

The stale badge was reproduced after hiding/showing the window, changing the Windows accent color, and resolving an older asynchronous badge draw after a clear.

Root Cause

The previous clear path updated BrowserWindow.setOverlayIcon() without synchronizing the third-party package's module-level state. The package also allowed an older executeJavaScript() render to overwrite a newer clear.

Design Decisions

  • Reimplement only the required behavior in OneKey source instead of carrying a source patch for the GPL-licensed dependency.
  • Generate a PNG data URL with a controlled renderer canvas because Electron NativeImage supports PNG/JPEG data.
  • Use Electron's Windows accent-color API and refresh the icon when that color changes.
  • Keep the count, current image, and update version in one class so clears invalidate pending renders.
  • Remove listeners when the BrowserWindow closes.

Changes Detail

  • packages/kit-bg/src/desktopApis/WindowsTaskbarBadge.ts: OneKey-owned badge rendering and lifecycle implementation.
  • packages/kit-bg/src/desktopApis/WindowsTaskbarBadge.test.ts: regression coverage for clear/show/accent behavior and stale renders.
  • packages/kit-bg/src/desktopApis/DesktopApiNotification.ts: use the local helper for Windows badge updates.
  • package.json / yarn.lock: remove electron-taskbar-badge.
  • patches/electron-taskbar-badge+1.1.2.patch: remove the obsolete dependency patch.

Risk Assessment

  • Risk Level: Medium
  • Affected Platforms: Desktop (Windows)
  • Risk Areas: Windows taskbar overlay rendering and BrowserWindow lifecycle timing.

Test plan

  • Type-aware oxlint on all changed TypeScript files.
  • Jest regression: clear remains after window show and accent-color changes.
  • Jest regression: stale async render cannot overwrite clear.
  • Electron main-process development build.
  • Bundle inspection confirms no electron-taskbar-badge code remains and the stale-render guard is present.

@huhuanming
huhuanming marked this pull request as ready for review July 11, 2026 08:13
@huhuanming
huhuanming marked this pull request as draft July 11, 2026 08:26
@huhuanming
huhuanming marked this pull request as ready for review July 16, 2026 07:01
@huhuanming
huhuanming enabled auto-merge (squash) July 16, 2026 07:01
: 0;
this.updateVersion += 1;
const updateVersion = this.updateVersion;
this.currentCount = count;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当窗口已有旧 badge,而新的非零更新在 executeJavaScript、data URL 校验或 nativeImage 校验任一阶段失败时,这里已经把 currentCount 更新为新值,但 currentOverlayIcon 和任务栏仍保留旧图片。之后触发 show 会再次挂载旧数字,并使用新计数 description,导致可见 badge 与内部状态长期不一致。

请把 count 与 overlay icon 作为一次原子提交:仅在最新版本成功生成图片后同时写入;若最新版本渲染失败,则明确清空 overlay 状态,不能继续保留旧图标。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants