From a3a62908fae7e7fb4a32c35ac35494372633aab6 Mon Sep 17 00:00:00 2001 From: z233 Date: Mon, 2 Oct 2023 11:44:17 +0800 Subject: [PATCH] fix: sync mini tracker open state --- src/platform/desktop.ts | 38 ++++++++++++++++--------- src/store.ts | 2 ++ src/window/mini-tracker/mini-tracker.ts | 5 ++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/platform/desktop.ts b/src/platform/desktop.ts index b1e53d0..aacb52b 100644 --- a/src/platform/desktop.ts +++ b/src/platform/desktop.ts @@ -55,7 +55,7 @@ function miniTrackerInit(plugin: SuperPlan, tracker: PlanTracker) { let miniTracker: Maybe = null - const showMiniTracker = () => { + function showMiniTracker() { miniTracker = MiniTracker.new(store, tracker) let windowFolder: string | undefined @@ -71,28 +71,40 @@ function miniTrackerInit(plugin: SuperPlan, tracker: PlanTracker) { } miniTracker.open(windowFolder) + ribbon.firstChild?.remove() ribbon.appendChild(openedIconSVG) + + plugin.settings.update({ + showMiniTracker: true, + }) + + miniTracker.onClose(() => { + closeMiniTracker() + }) + + } + + function closeMiniTracker() { + ribbon.firstChild?.remove() + ribbon.appendChild(closedIconSVG) + + if (miniTracker?.isOpen) { + miniTracker?.close() + } + + plugin.settings.update({ + showMiniTracker: false, + }) } if (open) showMiniTracker() ribbon.onclick = () => { if (settings.showMiniTracker) { - // Disable mini tracker - ribbon.firstChild?.remove() - ribbon.appendChild(closedIconSVG) - miniTracker?.close() - - plugin.settings.update({ - showMiniTracker: false, - }) + closeMiniTracker() } else { showMiniTracker() - - plugin.settings.update({ - showMiniTracker: true, - }) } } } diff --git a/src/store.ts b/src/store.ts index c66623d..1aec342 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,3 +1,5 @@ +import { atom, createStore } from 'jotai' +import { atomWithStorage } from 'jotai/utils' import type SuperPlan from './main' import type { ISettings } from './setting/settings' diff --git a/src/window/mini-tracker/mini-tracker.ts b/src/window/mini-tracker/mini-tracker.ts index 0457d4e..1d53eaa 100644 --- a/src/window/mini-tracker/mini-tracker.ts +++ b/src/window/mini-tracker/mini-tracker.ts @@ -35,12 +35,12 @@ export class MiniTracker { close() { if (this.isOpen) { - this.onCloseCallbacks.forEach((cb) => cb()) this.win?.close() } + this.onCloseCallbacks.forEach((cb) => cb()) + this.tracker.removeObserver(this.trackerObserver) - this.win?.removeAllListeners() } @@ -80,6 +80,7 @@ export class MiniTracker { this.tracker.addObserver(this.trackerObserver) this.win.on('move', debounce(this.handleWindowMove, 500).bind(this)) + this.win.on('close', this.close.bind(this)) window.addEventListener('pagehide', (e) => { MiniTracker.clean()