Skip to content

Commit

Permalink
Fix badge
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepzh committed Jun 30, 2023
1 parent b18b1f9 commit 3c10c3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/background/badge-text-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ async function findActiveTab(): Promise<BadgeLocation> {

async function updateFocus(badgeLocation?: BadgeLocation, lastLocation?: BadgeLocation): Promise<BadgeLocation> {
// Clear the last tab firstly
lastLocation?.tabId && setBadgeText('', lastLocation.tabId)
const needClearBefore = lastLocation?.tabId && lastLocation?.tabId !== badgeLocation?.tabId
needClearBefore && setBadgeText('', lastLocation.tabId)
badgeLocation = badgeLocation || await findActiveTab()
if (!badgeLocation) {
return badgeLocation
Expand Down
3 changes: 1 addition & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ initLimitProcesser(messageDispatcher)
// Content-script's request handler
initCsHandler(messageDispatcher)

// Start the timer
// new Timer().start()
// Start server
initServer(messageDispatcher)

// Collect the icon url and title
Expand Down
14 changes: 8 additions & 6 deletions src/background/timer/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { listTabs, sendMsg2Tab } from "@api/chrome/tab"
import { getTab, listTabs, sendMsg2Tab } from "@api/chrome/tab"
import { getWindow } from "@api/chrome/window"
import limitService from "@service/limit-service"
import periodService from "@service/period-service"
Expand All @@ -11,7 +11,7 @@ async function handleTime(hostInfo: HostInfo, url: string, dateRange: [number, n
const host = hostInfo.host
const [start, end] = dateRange
const focusTime = end - start
// 1. Saveasync
// 1. Save async
await statService.addFocusTime({ [host]: { [url]: focusTime } })
// 2. Process limit
const meedLimits = await limitService.addFocusTime(host, url, focusTime)
Expand All @@ -25,15 +25,17 @@ async function handleTime(hostInfo: HostInfo, url: string, dateRange: [number, n
async function handleEvent(event: timer.stat.Event, sender: ChromeMessageSender): Promise<void> {
const { url, start, end, ignoreTabCheck } = event
const windowId = sender?.tab?.windowId
const tabId = sender?.tab?.id
if (!ignoreTabCheck) {
if (!windowId) return
if (!windowId || !tabId) return
const window = await getWindow(windowId)
if (!window?.focused) return
const tab = await getTab(tabId)
if (!tab?.active) return
}
const hostInfo = extractHostname(url)
const focus = await handleTime(hostInfo, url, [start, end])
const tabId = sender?.tab?.id
tabId && badgeTextManager.forceUpdate({ tabId, url, focus })
await handleTime(hostInfo, url, [start, end])
tabId && badgeTextManager.forceUpdate({ tabId, url })
}

async function sendLimitedMessage(item: timer.limit.Item[]) {
Expand Down

0 comments on commit 3c10c3e

Please sign in to comment.