Skip to content

Commit 4608951

Browse files
committed
Revert "feat: support tracking time in split-screen mode (#643) "
This reverts commit e7991b1.
1 parent 8a66476 commit 4608951

File tree

4 files changed

+19
-50
lines changed

4 files changed

+19
-50
lines changed

src/api/chrome/tab.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,6 @@
77

88
import { handleError } from "./common"
99

10-
class ActivatedTabCtx {
11-
lastTabId?: number
12-
listened: boolean = false
13-
14-
async apply(): Promise<number | undefined> {
15-
if (this.listened) {
16-
return this.lastTabId
17-
}
18-
19-
// init
20-
chrome.tabs.onActivated.addListener(activeInfo => {
21-
this.lastTabId = activeInfo.tabId
22-
})
23-
this.listened = true
24-
25-
return this.getInner()
26-
}
27-
28-
private getInner(): Promise<number | undefined> {
29-
return new Promise(resolve => chrome.tabs.query(
30-
{ active: true },
31-
tabs => {
32-
handleError('getActivatedTab')
33-
const activeTab = tabs?.[0]
34-
resolve(activeTab?.id)
35-
}
36-
))
37-
}
38-
}
39-
40-
const ACTIVATED_TAB_CTX = new ActivatedTabCtx()
41-
42-
export function lastActivatedTabId(): Promise<number | undefined> {
43-
return ACTIVATED_TAB_CTX.apply()
44-
}
45-
4610
export function getTab(id: number): Promise<ChromeTab | undefined> {
4711
if (id < 0) {
4812
return Promise.resolve(undefined)

src/api/chrome/window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FocusedWindowCtx {
7171
}
7272
const context = new FocusedWindowCtx(['normal'])
7373

74-
export const lastFocusedNormalWinId = () => context.apply()
74+
export const getFocusedNormalWindowId = () => context.apply()
7575

7676
export async function getWindow(id: number): Promise<chrome.windows.Window | undefined> {
7777
if (IS_ANDROID) {

src/background/badge-manager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { setBadgeBgColor, setBadgeText } from "@api/chrome/action"
99
import { listTabs } from "@api/chrome/tab"
10-
import { lastFocusedNormalWinId } from "@api/chrome/window"
10+
import { getFocusedNormalWindowId } from "@api/chrome/window"
1111
import statDatabase from "@db/stat-database"
1212
import optionHolder from "@service/components/option-holder"
1313
import whitelistHolder from "@service/whitelist/holder"
@@ -46,11 +46,11 @@ function setBadgeTextOfMills(milliseconds: number | undefined, tabId: number | u
4646
}
4747

4848
async function findActiveTab(): Promise<BadgeLocation | undefined> {
49-
const lastFocusWinId = await lastFocusedNormalWinId()
50-
if (!lastFocusWinId) {
49+
const windowId = await getFocusedNormalWindowId()
50+
if (!windowId) {
5151
return undefined
5252
}
53-
const tabs = await listTabs({ active: true, windowId: lastFocusWinId })
53+
const tabs = await listTabs({ active: true, windowId })
5454
// Fix #131
5555
// Edge will return two active tabs, including the new tab with url 'edge://newtab/', GG
5656
for (const { id: tabId, url } of tabs) {
@@ -75,7 +75,7 @@ interface BadgeManager {
7575
updateFocus(location?: BadgeLocation): void
7676
}
7777

78-
class DefaultBadgeManager implements BadgeManager {
78+
class DefaultBadgeManager {
7979
pausedTabId: number | undefined
8080
current: BadgeLocation | undefined
8181
visible: boolean | undefined

src/background/track-server/normal.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { lastActivatedTabId, listTabs, sendMsg2Tab } from "@api/chrome/tab"
2-
import { lastFocusedNormalWinId } from "@api/chrome/window"
1+
import { getTab, listTabs, sendMsg2Tab } from "@api/chrome/tab"
2+
import { getWindow } from "@api/chrome/window"
33
import optionHolder from "@service/components/option-holder"
44
import itemService, { type ItemIncContext } from "@service/item-service"
55
import limitService from "@service/limit-service"
66
import periodThrottler from '@service/throttler/period-throttler'
77
import whitelistHolder from "@service/whitelist/holder"
88
import { IS_ANDROID } from "@util/constant/environment"
99
import { extractHostname } from "@util/pattern"
10-
import badgeManager from '../badge-manager'
10+
import badgeManager from "../badge-manager"
1111

1212
async function handleTime(context: ItemIncContext, timeRange: [number, number], tabId: number | undefined): Promise<number> {
1313
const { host, url } = context
@@ -41,21 +41,26 @@ export async function handleTrackTimeEvent(event: timer.core.Event, senderTab: C
4141

4242
await handleTime({ host, url, groupId }, [start, end], tabId)
4343
if (tabId) {
44-
badgeManager.updateFocus({ tabId, url })
44+
const winTabs = await listTabs({ active: true, windowId })
45+
const firstActiveTab = winTabs?.[0]
46+
// Cause there is no way to determine whether this tab is selected in screen-split mode
47+
// So only show badge for first tab for screen-split mode
48+
// @see #246
49+
firstActiveTab?.id === tabId && badgeManager.updateFocus({ tabId, url })
4550
}
4651
}
4752

4853
async function windowNotFocused(winId: number | undefined): Promise<boolean> {
4954
if (IS_ANDROID) return false
5055
if (!winId) return true
51-
const focusedWinId = await lastFocusedNormalWinId()
52-
return focusedWinId !== winId
56+
const window = await getWindow(winId)
57+
return !window?.focused
5358
}
5459

5560
async function tabNotActive(tabId: number | undefined): Promise<boolean> {
5661
if (!tabId) return true
57-
const lastActivated = await lastActivatedTabId()
58-
return lastActivated !== tabId
62+
const tab = await getTab(tabId)
63+
return !tab?.active
5964
}
6065

6166
async function sendLimitedMessage(items: timer.limit.Item[]) {

0 commit comments

Comments
 (0)