-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Tag listener * Monetization tag * Add stop & resume * merge and resolve conflicts * merge conflicts * update monetization event payload * Monetization service progress * Update monetization event (include frameId as well) * Remove unused code * Move message handler in contentScript * Add contentScript file changes * Clear payment session on closed tab * Listen for tab events, resume & pause monetization * Update icon * remove logs * Remove null validation * Update icon logic * Update bulk at start * Fix build error * Minor code updated --------- Co-authored-by: Diana Fulga <diana.fulga@breakointit.eu> Co-authored-by: Ionut Anin <ionutanin@gmail.com> Co-authored-by: Radu-Cristian Popa <radu.popa@breakpointit.eu>
- Loading branch information
1 parent
2aad0ae
commit a5364ef
Showing
12 changed files
with
195 additions
and
41 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,16 +1,76 @@ | ||
import { type Browser, runtime } from 'webextension-polyfill' | ||
import { MonetizationService } from './monetization' | ||
import { StorageService } from './storage' | ||
import { IsTabMonetizedPayload } from '@/shared/messages' | ||
|
||
export class TabEvents { | ||
constructor(private monetizationService: MonetizationService) {} | ||
|
||
onRemovedTab = (tabId: number) => { | ||
this.monetizationService.clearTabSessions(tabId) | ||
} | ||
const icon34 = runtime.getURL('assets/icons/icon-34.png') | ||
const icon128 = runtime.getURL('assets/icons/icon-128.png') | ||
const iconActive34 = runtime.getURL('assets/icons/icon-active-34.png') | ||
const iconActive128 = runtime.getURL('assets/icons/icon-active-128.png') | ||
const iconInactive34 = runtime.getURL('assets/icons/icon-inactive-34.png') | ||
const iconInactive128 = runtime.getURL('assets/icons/icon-inactive-128.png') | ||
const iconWarning34 = runtime.getURL('assets/icons/icon-warning-34.png') | ||
const iconWarning128 = runtime.getURL('assets/icons/icon-warning-128.png') | ||
|
||
export class TabEvents { | ||
constructor( | ||
private monetizationService: MonetizationService, | ||
private storage: StorageService, | ||
private browser: Browser | ||
) {} | ||
// TODO: This is not ideal. Find a better way to clear the sessions for a specific tab. | ||
// When closing the tab, we receive the STOP_MONETIZATION message as well. | ||
// Maybe check if the tab is closed in the content script? | ||
onUpdatedTab = (tabId: number) => { | ||
onRemovedTab = (tabId: number) => { | ||
this.monetizationService.clearTabSessions(tabId) | ||
} | ||
|
||
private changeIcon = async () => { | ||
const { enabled } = await this.storage.get(['enabled']) | ||
|
||
const iconData = { | ||
'34': enabled ? icon34 : iconWarning34, | ||
'128': enabled ? icon128 : iconWarning128 | ||
} | ||
|
||
if (this.browser.action) { | ||
await this.browser.action.setIcon({ path: iconData }) | ||
} else if (chrome.browserAction) { | ||
chrome.browserAction.setIcon({ path: iconData }) | ||
} | ||
} | ||
|
||
onActivatedTab = async () => { | ||
await this.changeIcon() | ||
} | ||
|
||
onCreatedTab = async () => { | ||
await this.changeIcon() | ||
} | ||
|
||
onUpdatedTab = async (payload?: IsTabMonetizedPayload) => { | ||
const { enabled } = await this.storage.get(['enabled']) | ||
|
||
let iconData = { | ||
'34': enabled ? icon34 : iconWarning34, | ||
'128': enabled ? icon34 : iconWarning128 | ||
} | ||
|
||
if (enabled) { | ||
if (payload) { | ||
const { value } = payload | ||
|
||
iconData = { | ||
'34': value ? iconActive34 : iconInactive34, | ||
'128': value ? iconActive128 : iconInactive128 | ||
} | ||
} | ||
} | ||
|
||
if (this.browser.action) { | ||
await this.browser.action.setIcon({ path: iconData }) | ||
} else if (chrome.browserAction) { | ||
chrome.browserAction.setIcon({ path: iconData }) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.