-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(badge): badge not updating when switching to a not yet registered…
… tab
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { call, put, take, select } from '@redux-saga/core/effects'; | ||
import { eventChannel } from '@redux-saga/core'; | ||
import createActivatedTabListener from 'webext/createActivatedTabListener'; | ||
import { createErrorAction } from 'app/actions'; | ||
import { getTabById } from '../selectors/tabs'; | ||
import { disable } from 'webext/browserAction'; | ||
import { resetBadge } from 'app/lmem/badge'; | ||
|
||
export default function*() { | ||
const channel = yield call(() => eventChannel(createActivatedTabListener)); | ||
|
||
while (true) { | ||
try { | ||
const { | ||
meta: { tabId } | ||
} = yield take(channel); | ||
const tab = yield select(getTabById(tabId)); | ||
|
||
if (!tab || !tab.url) { | ||
yield call(resetBadge, tabId); | ||
yield call(disable, tabId); | ||
} | ||
} catch (e) { | ||
yield put(createErrorAction()(e)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Action } from 'redux'; | ||
import { tabActivated } from 'app/actions'; | ||
|
||
type Emit = (action: Action) => void; | ||
|
||
export default (emit: Emit) => { | ||
const handleTabActivated = ({ tabId }: chrome.tabs.TabActiveInfo) => { | ||
emit(tabActivated(tabId)); | ||
}; | ||
|
||
chrome.tabs.onActivated.addListener(handleTabActivated); | ||
|
||
// unsubscribe | ||
return () => { | ||
chrome.tabs.onActivated.removeListener(handleTabActivated); | ||
}; | ||
}; |