Skip to content

Commit

Permalink
fix: sync mini tracker open state
Browse files Browse the repository at this point in the history
  • Loading branch information
Z233 committed Oct 2, 2023
1 parent 01464e5 commit a3a6290
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
38 changes: 25 additions & 13 deletions src/platform/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function miniTrackerInit(plugin: SuperPlan, tracker: PlanTracker) {

let miniTracker: Maybe<MiniTracker> = null

const showMiniTracker = () => {
function showMiniTracker() {
miniTracker = MiniTracker.new(store, tracker)

let windowFolder: string | undefined
Expand All @@ -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,
})
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
5 changes: 3 additions & 2 deletions src/window/mini-tracker/mini-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a3a6290

Please sign in to comment.