Skip to content

Commit d7df4d7

Browse files
committed
fix: fix It Just Works
Fixed an issue that caused inconsistent execution results.
1 parent 7aa970c commit d7df4d7

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { autoUpdater } from 'electron-updater';
88
import electronDebug from 'electron-debug';
99

1010
import config from './config';
11-
import { setApplicationMenu } from './menu';
11+
import { refreshMenu, setApplicationMenu } from './menu';
1212
import { fileExists, injectCSS, injectCSSAsFile } from './plugins/utils';
1313
import { isTesting } from './utils/testing';
1414
import { setUpTray } from './tray';
@@ -470,6 +470,7 @@ app.on('ready', async () => {
470470

471471
mainWindow = await createMainWindow();
472472
setApplicationMenu(mainWindow);
473+
refreshMenu(mainWindow);
473474
setUpTray(app, mainWindow);
474475

475476
setupProtocolHandler(mainWindow);

menu.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ const pluginEnabledMenu = (plugin: string, label = '', hasSubmenu = false, refre
6262
},
6363
});
6464

65+
export const refreshMenu = (win: BrowserWindow) => {
66+
setApplicationMenu(win);
67+
if (inAppMenuActive) {
68+
win.webContents.send('refreshMenu');
69+
}
70+
};
71+
6572
export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
66-
const refreshMenu = () => {
67-
setApplicationMenu(win);
68-
if (inAppMenuActive) {
69-
win.webContents.send('refreshMenu');
70-
}
71-
};
73+
const innerRefreshMenu = () => refreshMenu(win);
7274

7375
return [
7476
{
@@ -84,15 +86,15 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
8486
const getPluginMenu = pluginMenus[pluginName as keyof typeof pluginMenus];
8587

8688
if (!config.plugins.isEnabled(pluginName)) {
87-
return pluginEnabledMenu(pluginName, pluginLabel, true, refreshMenu);
89+
return pluginEnabledMenu(pluginName, pluginLabel, true, innerRefreshMenu);
8890
}
8991

9092
return {
9193
label: pluginLabel,
9294
submenu: [
93-
pluginEnabledMenu(pluginName, 'Enabled', true, refreshMenu),
95+
pluginEnabledMenu(pluginName, 'Enabled', true, innerRefreshMenu),
9496
{ type: 'separator' },
95-
...getPluginMenu(win, config.plugins.getOptions(pluginName), refreshMenu),
97+
...getPluginMenu(win, config.plugins.getOptions(pluginName), innerRefreshMenu),
9698
],
9799
} satisfies Electron.MenuItemConstructorOptions;
98100
}

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
"!node_modules",
2222
"node_modules/custom-electron-prompt/**",
2323
"node_modules/@cliqz/adblocker-electron-preload/**",
24-
"node_modules/@cliqz/adblocker-content/**",
25-
"node_modules/@cliqz/adblocker-extended-selectors/**",
2624
"node_modules/@ffmpeg.wasm/core-mt/**",
2725
"!node_modules/**/*.map",
2826
"!node_modules/**/*.ts"
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export default () => {
2-
const path = '@cliqz/adblocker-electron-preload'; // prevent require hoisting
3-
require(path);
1+
export default async () => {
2+
await import('@cliqz/adblocker-electron-preload');
43
};

plugins/adblocker/preload.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import config from './config';
1+
import config, { shouldUseBlocklists } from './config';
22
import inject from './inject';
33
import injectCliqzPreload from './inject-cliqz-preload';
44

55
import { blockers } from './blocker-types';
66

77
export default async () => {
8-
if (await config.shouldUseBlocklists()) {
8+
if (shouldUseBlocklists()) {
99
// Preload adblocker to inject scripts/styles
10-
injectCliqzPreload();
10+
await injectCliqzPreload();
1111
// eslint-disable-next-line @typescript-eslint/await-thenable
12-
} else if ((await config.get('blocker')) === blockers.InPlayer) {
12+
} else if ((config.get('blocker')) === blockers.InPlayer) {
1313
inject();
1414
}
1515
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default () => {
1+
export default async () => {
22
// See https://github.com/zerodytrash/Simple-YouTube-Age-Restriction-Bypass#userscript
3-
import('simple-youtube-age-restriction-bypass');
3+
await import('simple-youtube-age-restriction-bypass');
44
};

0 commit comments

Comments
 (0)