-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(plugins): Ensure IPC data is correctly passed to renderer plugins #4048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ea77098
f9faa3c
429ffb0
90200a4
dffbfd2
81fcbc4
d8e2aae
430226a
6dcd0a7
3cc8294
1628e4b
31a229e
97e93b9
37182b8
3932769
8556772
2381e13
afa6a75
e646864
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| appId: com.github.th-ch.pear-desktop | ||
| productName: Pear Desktop | ||
| productName: YouTube Music | ||
| files: | ||
| - '!*' | ||
| - dist | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||||
| import { createPlugin } from '@/utils'; | ||||||||||
| import { t } from '@/i18n'; | ||||||||||
|
|
||||||||||
| let observer: MutationObserver | null = null; | ||||||||||
| let lastAdCheck = 0; | ||||||||||
| let checkInterval: NodeJS.Timeout | null = null; | ||||||||||
|
|
||||||||||
| function checkAndSkipAd() { | ||||||||||
| // Throttle checks to avoid performance issues | ||||||||||
| const now = Date.now(); | ||||||||||
| if (now - lastAdCheck < 100) return; | ||||||||||
| lastAdCheck = now; | ||||||||||
|
|
||||||||||
| const video = document.querySelector<HTMLVideoElement>('video'); | ||||||||||
| if (!video) return; | ||||||||||
|
|
||||||||||
| const adContainer = document.querySelector('.ytp-ad-player-overlay, .video-ads, .ytp-ad-module'); | ||||||||||
| const adText = document.querySelector('.ytp-ad-text, .ytp-ad-preview-text'); | ||||||||||
|
|
||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||
| // Check if ad is playing | ||||||||||
| const isAd = adContainer || adText || | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||
| document.querySelector('.ad-showing') || | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||
| document.querySelector('.advertisement'); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||
|
|
||||||||||
| if (isAd) { | ||||||||||
| // Mute and speed up the video | ||||||||||
| if (!video.muted) { | ||||||||||
| video.muted = true; | ||||||||||
| } | ||||||||||
| if (video.playbackRate !== 16) { | ||||||||||
| video.playbackRate = 16; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Try to click skip button if available | ||||||||||
| const skipButton = document.querySelector<HTMLElement>( | ||||||||||
| '.ytp-ad-skip-button, .ytp-ad-skip-button-modern, button.ytp-ad-skip-button' | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||
| ); | ||||||||||
| if (skipButton && skipButton.offsetParent !== null) { | ||||||||||
| skipButton.click(); | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
| // Restore normal playback when not an ad | ||||||||||
| if (video.muted) { | ||||||||||
| video.muted = false; | ||||||||||
| } | ||||||||||
| if (video.playbackRate !== 1) { | ||||||||||
| video.playbackRate = 1; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export default createPlugin({ | ||||||||||
| name: () => t('plugins.ad-speedup.name'), | ||||||||||
| description: () => t('plugins.ad-speedup.description'), | ||||||||||
| restartNeeded: false, | ||||||||||
| config: { | ||||||||||
| enabled: true, | ||||||||||
| }, | ||||||||||
| renderer: { | ||||||||||
| start() { | ||||||||||
| // Check for ads periodically | ||||||||||
| checkInterval = setInterval(() => { | ||||||||||
| checkAndSkipAd(); | ||||||||||
| }, 500); | ||||||||||
|
|
||||||||||
| // Also watch for DOM changes | ||||||||||
| observer = new MutationObserver(() => { | ||||||||||
| checkAndSkipAd(); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const targetNode = document.body; | ||||||||||
| if (targetNode) { | ||||||||||
| observer.observe(targetNode, { | ||||||||||
| childList: true, | ||||||||||
| subtree: true, | ||||||||||
| }); | ||||||||||
| } | ||||||||||
| }, | ||||||||||
|
|
||||||||||
| stop() { | ||||||||||
| if (observer) { | ||||||||||
| observer.disconnect(); | ||||||||||
| observer = null; | ||||||||||
| } | ||||||||||
| if (checkInterval) { | ||||||||||
| clearInterval(checkInterval); | ||||||||||
| checkInterval = null; | ||||||||||
| } | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }); | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||
| import { ElectronBlocker } from '@ghostery/adblocker-electron'; | ||||||||||||
| import { session } from 'electron'; | ||||||||||||
|
|
||||||||||||
| import { createPlugin } from '@/utils'; | ||||||||||||
| import { t } from '@/i18n'; | ||||||||||||
|
|
||||||||||||
| import type { BackendContext } from '@/types/contexts'; | ||||||||||||
|
|
||||||||||||
| export type AdBlockerPluginConfig = { | ||||||||||||
| enabled: boolean; | ||||||||||||
| cache: boolean; | ||||||||||||
| additionalBlockLists: string[]; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| let blocker: ElectronBlocker | null = null; | ||||||||||||
|
|
||||||||||||
| const defaultBlockLists = [ | ||||||||||||
| 'https://easylist.to/easylist/easylist.txt', | ||||||||||||
| 'https://easylist.to/easylist/easyprivacy.txt', | ||||||||||||
| 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt', | ||||||||||||
| 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt', | ||||||||||||
| 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt', | ||||||||||||
| 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt', | ||||||||||||
| 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt', | ||||||||||||
| 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/annoyances.txt', | ||||||||||||
| ]; | ||||||||||||
|
|
||||||||||||
| export default createPlugin({ | ||||||||||||
| name: () => t('plugins.adblocker.name'), | ||||||||||||
| description: () => t('plugins.adblocker.description'), | ||||||||||||
| restartNeeded: false, | ||||||||||||
| config: { | ||||||||||||
| enabled: true, | ||||||||||||
| cache: true, | ||||||||||||
| additionalBlockLists: [], | ||||||||||||
| }, | ||||||||||||
| backend: { | ||||||||||||
| async start({ getConfig }: BackendContext<AdBlockerPluginConfig>) { | ||||||||||||
| const config = await getConfig(); | ||||||||||||
| const blockLists = [...defaultBlockLists, ...config.additionalBlockLists]; | ||||||||||||
|
|
||||||||||||
| try { | ||||||||||||
| blocker = await ElectronBlocker.fromLists( | ||||||||||||
| fetch, | ||||||||||||
| blockLists, | ||||||||||||
| { | ||||||||||||
|
Comment on lines
+43
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||
| enableCompression: true, | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||
| }, | ||||||||||||
| ); | ||||||||||||
|
Comment on lines
+48
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Suggested change
|
||||||||||||
|
|
||||||||||||
| blocker.enableBlockingInSession(session.defaultSession); | ||||||||||||
|
|
||||||||||||
| console.log('[AdBlocker] Ad blocker enabled successfully'); | ||||||||||||
| } catch (error) { | ||||||||||||
| console.error('[AdBlocker] Failed to initialize ad blocker:', error); | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
|
|
||||||||||||
| async onConfigChange(newConfig: AdBlockerPluginConfig) { | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [eslint] <@typescript-eslint/require-await> reported by reviewdog 🐶 |
||||||||||||
| if (!newConfig.enabled && blocker) { | ||||||||||||
| blocker.disableBlockingInSession(session.defaultSession); | ||||||||||||
| blocker = null; | ||||||||||||
| console.log('[AdBlocker] Ad blocker disabled'); | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
|
|
||||||||||||
| stop() { | ||||||||||||
| if (blocker) { | ||||||||||||
| blocker.disableBlockingInSession(session.defaultSession); | ||||||||||||
| blocker = null; | ||||||||||||
| console.log('[AdBlocker] Ad blocker stopped'); | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
| }, | ||||||||||||
| }); | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [eslint] <prettier/prettier> reported by reviewdog 🐶
Replace
'.ytp-ad-player-overlay,·.video-ads,·.ytp-ad-module'with⏎····'.ytp-ad-player-overlay,·.video-ads,·.ytp-ad-module',⏎··