Skip to content

Commit e4eed2e

Browse files
committed
add custom-electron-prompt
also use it to set proxy option
1 parent 8decdf4 commit e4eed2e

File tree

5 files changed

+154
-76
lines changed

5 files changed

+154
-76
lines changed

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ if (config.get("options.proxy")) {
3737
}
3838

3939
// Adds debug features like hotkeys for triggering dev tools and reload
40-
require("electron-debug")();
40+
require("electron-debug")({
41+
showDevTools: false, //disable automatic devTools on new window
42+
});
4143

4244
// Prevent window being garbage collected
4345
let mainWindow;
@@ -58,7 +60,7 @@ function onClosed() {
5860

5961
function loadPlugins(win) {
6062
injectCSS(win.webContents, path.join(__dirname, "youtube-music.css"));
61-
win.webContents.on("did-finish-load", () => {
63+
win.webContents.once("did-finish-load", () => {
6264
if (is.dev()) {
6365
console.log("did finish load");
6466
win.webContents.openDevTools();

menu.js

+119-74
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const is = require("electron-is");
66

77
const { getAllPlugins } = require("./plugins/utils");
88
const config = require("./config");
9+
const prompt = require("custom-electron-prompt");
910

1011
const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({
1112
label: label || plugin,
@@ -103,30 +104,38 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
103104
},
104105
...(is.windows() || is.linux()
105106
? [
106-
{
107-
label: "Hide menu",
108-
type: "checkbox",
109-
checked: config.get("options.hideMenu"),
110-
click: (item) => {
111-
config.set("options.hideMenu", item.checked);
112-
},
107+
{
108+
label: "Hide menu",
109+
type: "checkbox",
110+
checked: config.get("options.hideMenu"),
111+
click: (item) => {
112+
config.set("options.hideMenu", item.checked);
113113
},
114-
]
114+
},
115+
]
115116
: []),
116117
...(is.windows() || is.macOS()
117118
? // Only works on Win/Mac
118-
// https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows
119-
[
120-
{
121-
label: "Start at login",
122-
type: "checkbox",
123-
checked: config.get("options.startAtLogin"),
124-
click: (item) => {
125-
config.set("options.startAtLogin", item.checked);
126-
},
119+
// https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows
120+
[
121+
{
122+
label: "Start at login",
123+
type: "checkbox",
124+
checked: config.get("options.startAtLogin"),
125+
click: (item) => {
126+
config.set("options.startAtLogin", item.checked);
127127
},
128-
]
128+
},
129+
]
129130
: []),
131+
{
132+
label: "Proxy",
133+
type: "checkbox",
134+
checked: !!config.get("options.proxy"),
135+
click: (item) => {
136+
setProxy(item, win);
137+
}
138+
},
130139
{
131140
label: "Tray",
132141
submenu: [
@@ -194,56 +203,56 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
194203
},
195204
...(!isTray
196205
? [
197-
{
198-
label: "View",
199-
submenu: withRoles
200-
? [
201-
{ role: "reload" },
202-
{ role: "forceReload" },
203-
{ type: "separator" },
204-
{ role: "zoomIn" },
205-
{ role: "zoomOut" },
206-
{ role: "resetZoom" },
207-
]
208-
: [
209-
{
210-
label: "Reload",
211-
click: () => {
212-
win.webContents.reload();
213-
},
214-
},
215-
{
216-
label: "Force Reload",
217-
click: () => {
218-
win.webContents.reloadIgnoringCache();
219-
},
220-
},
221-
{ type: "separator" },
222-
{
223-
label: "Zoom In",
224-
click: () => {
225-
win.webContents.setZoomLevel(
226-
win.webContents.getZoomLevel() + 1
227-
);
228-
},
229-
},
230-
{
231-
label: "Zoom Out",
232-
click: () => {
233-
win.webContents.setZoomLevel(
234-
win.webContents.getZoomLevel() - 1
235-
);
236-
},
237-
},
238-
{
239-
label: "Reset Zoom",
240-
click: () => {
241-
win.webContents.setZoomLevel(0);
242-
},
243-
},
244-
],
245-
},
246-
]
206+
{
207+
label: "View",
208+
submenu: withRoles
209+
? [
210+
{ role: "reload" },
211+
{ role: "forceReload" },
212+
{ type: "separator" },
213+
{ role: "zoomIn" },
214+
{ role: "zoomOut" },
215+
{ role: "resetZoom" },
216+
]
217+
: [
218+
{
219+
label: "Reload",
220+
click: () => {
221+
win.webContents.reload();
222+
},
223+
},
224+
{
225+
label: "Force Reload",
226+
click: () => {
227+
win.webContents.reloadIgnoringCache();
228+
},
229+
},
230+
{ type: "separator" },
231+
{
232+
label: "Zoom In",
233+
click: () => {
234+
win.webContents.setZoomLevel(
235+
win.webContents.getZoomLevel() + 1
236+
);
237+
},
238+
},
239+
{
240+
label: "Zoom Out",
241+
click: () => {
242+
win.webContents.setZoomLevel(
243+
win.webContents.getZoomLevel() - 1
244+
);
245+
},
246+
},
247+
{
248+
label: "Reset Zoom",
249+
click: () => {
250+
win.webContents.setZoomLevel(0);
251+
},
252+
},
253+
],
254+
},
255+
]
247256
: []),
248257
{
249258
label: "Navigation",
@@ -273,13 +282,13 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [
273282
},
274283
...(!isTray
275284
? [
276-
{
277-
label: "Quit App",
278-
click: () => {
279-
app.quit();
280-
},
285+
{
286+
label: "Quit App",
287+
click: () => {
288+
app.quit();
281289
},
282-
]
290+
},
291+
]
283292
: []),
284293
],
285294
},
@@ -318,3 +327,39 @@ module.exports.setApplicationMenu = (win) => {
318327
const menu = Menu.buildFromTemplate(menuTemplate);
319328
Menu.setApplicationMenu(menu);
320329
};
330+
331+
const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png");
332+
const example = `Example: "socks5://127.0.0.1:9999"`;
333+
function setProxy(item, win) {
334+
let options = {
335+
title: 'Set Proxy',
336+
label: 'Enter Proxy Address: (leave empty to disable)',
337+
value: config.get("options.proxy") || example,
338+
inputAttrs: {
339+
type: 'text'
340+
},
341+
type: 'input',
342+
icon: iconPath,
343+
customStylesheet: "dark",
344+
};
345+
//TODO: custom bar on prompt need testing on macOS
346+
if (!is.macOS()) {
347+
Object.assign(options, {
348+
frame: false,
349+
customScript: path.join(__dirname, "plugins", "in-app-menu", "prompt-custom-titlebar.js"),
350+
enableRemoteModule: true,
351+
height: 200,
352+
width: 450,
353+
});
354+
}
355+
prompt(options, win)
356+
.then(input => {
357+
if (input !== null && input !== example) {
358+
config.set("options.proxy", input);
359+
item.checked = input !== "";
360+
} else { //user pressed cancel
361+
item.checked = !item.checked; //reset checkbox
362+
}
363+
})
364+
.catch(console.error);
365+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.1",
6969
"async-mutex": "^0.3.1",
7070
"browser-id3-writer": "^4.4.0",
71+
"custom-electron-prompt": "^1.0.2",
7172
"custom-electron-titlebar": "^3.2.6",
7273
"discord-rpc": "^3.2.0",
7374
"downloads-folder": "^3.0.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const customTitlebar = require("custom-electron-titlebar");
2+
3+
module.exports = () => {
4+
const bar = new customTitlebar.Titlebar({
5+
backgroundColor: customTitlebar.Color.fromHex("#050505"),
6+
minimizable: false,
7+
maximizable: false,
8+
menu: null
9+
});
10+
const mainStyle = document.querySelector("#container").style;
11+
mainStyle.width = "100%";
12+
mainStyle.position = "fixed";
13+
mainStyle.border = "unset";
14+
};

yarn.lock

+16
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,13 @@ cssstyle@^2.2.0:
26362636
dependencies:
26372637
cssom "~0.3.6"
26382638

2639+
custom-electron-prompt@^1.0.1:
2640+
version "1.0.1"
2641+
resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.1.tgz#6d11c6e5130a444a9425bd27864777b36f1fef11"
2642+
integrity sha512-ldEiZ1t3rBDOb0nfvVpxQOjWJvkkUO3B/sD9IIYr2C/VG9COkc6IJNO2E3rXMPdDDIwejXEQx3CTWp2N2d4moQ==
2643+
dependencies:
2644+
electron "^11.4.4"
2645+
26392646
custom-electron-titlebar@^3.2.6:
26402647
version "3.2.6"
26412648
resolved "https://registry.yarnpkg.com/custom-electron-titlebar/-/custom-electron-titlebar-3.2.6.tgz#4cd064efa5020954c09732efa8c667a7ee3636e3"
@@ -3140,6 +3147,15 @@ electron@^11.2.3:
31403147
"@types/node" "^12.0.12"
31413148
extract-zip "^1.0.3"
31423149

3150+
electron@^11.4.4:
3151+
version "11.4.4"
3152+
resolved "https://registry.yarnpkg.com/electron/-/electron-11.4.4.tgz#d6c046dedd9e22df5f6408841c3f8ae1a1d59414"
3153+
integrity sha512-m52nF85VADCmL9DpzJfgmkvc9fNiGZPYwptv/4fTYrYhAMiO+hmClGMXncCoSAzoULQjl+f+0b9CY4yd6nRFlQ==
3154+
dependencies:
3155+
"@electron/get" "^1.0.1"
3156+
"@types/node" "^12.0.12"
3157+
extract-zip "^1.0.3"
3158+
31433159
elliptic@^6.5.3:
31443160
version "6.5.4"
31453161
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"

0 commit comments

Comments
 (0)