mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
hotfix(adblocker): fix ipcRenderer.sendSync() with ...
This issue is caused by the renderer's adblocker being loaded before the main process's adblocker.
This commit is contained in:
19
index.ts
19
index.ts
@ -144,7 +144,7 @@ if (is.windows()) {
|
|||||||
|
|
||||||
ipcMain.handle('get-main-plugin-names', () => Object.keys(mainPlugins));
|
ipcMain.handle('get-main-plugin-names', () => Object.keys(mainPlugins));
|
||||||
|
|
||||||
function loadPlugins(win: BrowserWindow) {
|
async function loadPlugins(win: BrowserWindow) {
|
||||||
injectCSS(win.webContents, youtubeMusicCSS);
|
injectCSS(win.webContents, youtubeMusicCSS);
|
||||||
// Load user CSS
|
// Load user CSS
|
||||||
const themes: string[] = config.get('options.themes');
|
const themes: string[] = config.get('options.themes');
|
||||||
@ -175,7 +175,7 @@ function loadPlugins(win: BrowserWindow) {
|
|||||||
console.log('Loaded plugin - ' + plugin);
|
console.log('Loaded plugin - ' + plugin);
|
||||||
const handler = mainPlugins[plugin as keyof typeof mainPlugins];
|
const handler = mainPlugins[plugin as keyof typeof mainPlugins];
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler(win, options as never);
|
await handler(win, options as never);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -184,7 +184,7 @@ function loadPlugins(win: BrowserWindow) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMainWindow() {
|
async function createMainWindow() {
|
||||||
const windowSize = config.get('window-size');
|
const windowSize = config.get('window-size');
|
||||||
const windowMaximized = config.get('window-maximized');
|
const windowMaximized = config.get('window-maximized');
|
||||||
const windowPosition: Electron.Point = config.get('window-position');
|
const windowPosition: Electron.Point = config.get('window-position');
|
||||||
@ -223,7 +223,7 @@ function createMainWindow() {
|
|||||||
: 'default'),
|
: 'default'),
|
||||||
autoHideMenuBar: config.get('options.hideMenu'),
|
autoHideMenuBar: config.get('options.hideMenu'),
|
||||||
});
|
});
|
||||||
loadPlugins(win);
|
await loadPlugins(win);
|
||||||
|
|
||||||
if (windowPosition) {
|
if (windowPosition) {
|
||||||
const { x: windowX, y: windowY } = windowPosition;
|
const { x: windowX, y: windowY } = windowPosition;
|
||||||
@ -258,7 +258,6 @@ function createMainWindow() {
|
|||||||
const urlToLoad = config.get('options.resumeOnStart')
|
const urlToLoad = config.get('options.resumeOnStart')
|
||||||
? config.get('url')
|
? config.get('url')
|
||||||
: config.defaultConfig.url;
|
: config.defaultConfig.url;
|
||||||
win.webContents.loadURL(urlToLoad);
|
|
||||||
win.on('closed', onClosed);
|
win.on('closed', onClosed);
|
||||||
|
|
||||||
type PiPOptions = typeof config.defaultConfig.plugins['picture-in-picture'];
|
type PiPOptions = typeof config.defaultConfig.plugins['picture-in-picture'];
|
||||||
@ -338,6 +337,8 @@ function createMainWindow() {
|
|||||||
|
|
||||||
removeContentSecurityPolicy();
|
removeContentSecurityPolicy();
|
||||||
|
|
||||||
|
await win.webContents.loadURL(urlToLoad);
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,17 +415,17 @@ app.on('window-all-closed', () => {
|
|||||||
globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', async () => {
|
||||||
// On OS X it's common to re-create a window in the app when the
|
// On OS X it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
mainWindow = createMainWindow();
|
mainWindow = await createMainWindow();
|
||||||
} else if (!mainWindow.isVisible()) {
|
} else if (!mainWindow.isVisible()) {
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', async () => {
|
||||||
if (config.get('options.autoResetAppCache')) {
|
if (config.get('options.autoResetAppCache')) {
|
||||||
// Clear cache after 20s
|
// Clear cache after 20s
|
||||||
const clearCacheTimeout = setTimeout(() => {
|
const clearCacheTimeout = setTimeout(() => {
|
||||||
@ -469,7 +470,7 @@ app.on('ready', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow = createMainWindow();
|
mainWindow = await createMainWindow();
|
||||||
setApplicationMenu(mainWindow);
|
setApplicationMenu(mainWindow);
|
||||||
setUpTray(app, mainWindow);
|
setUpTray(app, mainWindow);
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,8 @@ import type { ConfigType } from '../../config/dynamic';
|
|||||||
type AdBlockOptions = ConfigType<'adblocker'>;
|
type AdBlockOptions = ConfigType<'adblocker'>;
|
||||||
|
|
||||||
export default async (win: BrowserWindow, options: AdBlockOptions) => {
|
export default async (win: BrowserWindow, options: AdBlockOptions) => {
|
||||||
if (await shouldUseBlocklists()) {
|
if (shouldUseBlocklists()) {
|
||||||
loadAdBlockerEngine(
|
await loadAdBlockerEngine(
|
||||||
win.webContents.session,
|
win.webContents.session,
|
||||||
options.cache,
|
options.cache,
|
||||||
options.additionalBlockLists,
|
options.additionalBlockLists,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import path from 'node:path';
|
|||||||
import fs, { promises } from 'node:fs';
|
import fs, { promises } from 'node:fs';
|
||||||
|
|
||||||
import { ElectronBlocker } from '@cliqz/adblocker-electron';
|
import { ElectronBlocker } from '@cliqz/adblocker-electron';
|
||||||
import { app } from 'electron';
|
import { app, net } from 'electron';
|
||||||
|
|
||||||
const SOURCES = [
|
const SOURCES = [
|
||||||
'https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt',
|
'https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt',
|
||||||
@ -17,7 +17,7 @@ const SOURCES = [
|
|||||||
'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt',
|
'https://secure.fanboy.co.nz/fanboy-annoyance_ubo.txt',
|
||||||
];
|
];
|
||||||
|
|
||||||
export const loadAdBlockerEngine = (
|
export const loadAdBlockerEngine = async (
|
||||||
session: Electron.Session | undefined = undefined,
|
session: Electron.Session | undefined = undefined,
|
||||||
cache = true,
|
cache = true,
|
||||||
additionalBlockLists = [],
|
additionalBlockLists = [],
|
||||||
@ -49,25 +49,24 @@ export const loadAdBlockerEngine = (
|
|||||||
...additionalBlockLists,
|
...additionalBlockLists,
|
||||||
];
|
];
|
||||||
|
|
||||||
ElectronBlocker.fromLists(
|
try {
|
||||||
fetch,
|
const blocker = await ElectronBlocker.fromLists(
|
||||||
lists,
|
(url: string) => net.fetch(url),
|
||||||
{
|
lists,
|
||||||
// When generating the engine for caching, do not load network filters
|
{
|
||||||
// So that enhancing the session works as expected
|
// When generating the engine for caching, do not load network filters
|
||||||
// Allowing to define multiple webRequest listeners
|
// So that enhancing the session works as expected
|
||||||
loadNetworkFilters: session !== undefined,
|
// Allowing to define multiple webRequest listeners
|
||||||
},
|
loadNetworkFilters: session !== undefined,
|
||||||
cachingOptions,
|
},
|
||||||
)
|
cachingOptions,
|
||||||
.then((blocker) => {
|
);
|
||||||
if (session) {
|
if (session) {
|
||||||
blocker.enableBlockingInSession(session);
|
blocker.enableBlockingInSession(session);
|
||||||
} else {
|
}
|
||||||
console.log('Successfully generated adBlocker engine.');
|
} catch (error) {
|
||||||
}
|
console.log('Error loading adBlocker engine', error);
|
||||||
})
|
}
|
||||||
.catch((error) => console.log('Error loading adBlocker engine', error));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default { loadAdBlockerEngine };
|
export default { loadAdBlockerEngine };
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { PluginConfig } from '../../config/dynamic';
|
|||||||
|
|
||||||
const config = new PluginConfig('adblocker', { enableFront: true });
|
const config = new PluginConfig('adblocker', { enableFront: true });
|
||||||
|
|
||||||
export const shouldUseBlocklists = async () => await config.get('blocker') !== blockers.InPlayer;
|
export const shouldUseBlocklists = () => config.get('blocker') !== blockers.InPlayer;
|
||||||
|
|
||||||
export default Object.assign(config, {
|
export default Object.assign(config, {
|
||||||
shouldUseBlocklists,
|
shouldUseBlocklists,
|
||||||
|
|||||||
Reference in New Issue
Block a user