Skip to content

Commit 107c79f

Browse files
committed
Merge branch 'master' of https://github.com/xn-oah/youtube-music
2 parents 6aa789f + 94c8649 commit 107c79f

File tree

26 files changed

+670
-337
lines changed

26 files changed

+670
-337
lines changed

.github/workflows/build.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,60 @@ jobs:
3535
- name: Install dependencies
3636
run: yarn --frozen-lockfile
3737

38+
######################
39+
# Patch SnoreToast to fix App ID - see https://github.com/th-ch/youtube-music/issues/479#issuecomment-965473559
40+
- name: SnoreToast - parameters
41+
id: snoretoast-params
42+
if: startsWith(matrix.os, 'windows')
43+
shell: bash
44+
run: |
45+
echo "::set-output name=version::v0.8.0"
46+
echo "::set-output name=path::./vendor/snoretoast"
47+
48+
- name: SnoreToast - cache
49+
id: snoretoast-cache
50+
uses: actions/cache@v2
51+
if: startsWith(matrix.os, 'windows')
52+
with:
53+
path: ${{ steps.snoretoast-params.outputs.path }}
54+
key: snoretoast-${{ steps.snoretoast-params.outputs.version }}
55+
56+
- name: SnoreToast - compile
57+
if: |
58+
startsWith(matrix.os, 'windows') &&
59+
steps.snoretoast-cache.outputs.cache-hit != 'true'
60+
shell: bash
61+
run: |
62+
SNORETOAST_TAG="${{ steps.snoretoast-params.outputs.version }}"
63+
echo "Compiling SnoreToast $SNORETOAST_TAG"
64+
65+
git config --global user.email "[email protected]"
66+
git config --global user.name "YouTube Music"
67+
git clone -c advice.detachedHead=false --branch $SNORETOAST_TAG --depth 1 https://github.com/KDE/snoretoast.git ${{ steps.snoretoast-params.outputs.path }}
68+
cd ${{ steps.snoretoast-params.outputs.path }}
69+
70+
# Apply https://github.com/KDE/snoretoast/pull/15/commits/c5faeceaf36f4b9fb27e5269990b716a25ecbe43
71+
# Patch generated with `git format-patch -1 c5faeceaf36f4b9fb27e5269990b716a25ecbe43`
72+
git am < ../snoretoast-patch/0001-Fix-activation-not-writing-to-pipe.patch
73+
74+
# Compile for win32
75+
cmake -A Win32 -B build32
76+
cmake --build build32 --config Release
77+
78+
# Compile for x64
79+
cmake -A x64 -B build64
80+
cmake --build build64 --config Release
81+
82+
- name: SnoreToast - overwrite with custom build
83+
if: startsWith(matrix.os, 'windows')
84+
shell: bash
85+
run: |
86+
# Override SnoreToast with the patched versions
87+
cp ${{ steps.snoretoast-params.outputs.path }}/build32/bin/Release/snoretoast.exe ./node_modules/node-notifier/vendor/snoreToast/snoretoast-x86.exe
88+
cp ${{ steps.snoretoast-params.outputs.path }}/build64/bin/Release/snoretoast.exe ./node_modules/node-notifier/vendor/snoreToast/snoretoast-x64.exe
89+
# End of SnoreToast patch
90+
######################
91+
3892
- name: Test
3993
uses: GabrielBB/xvfb-action@v1
4094
with:

config/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
const defaultConfig = require("./defaults");
22
const plugins = require("./plugins");
33
const store = require("./store");
4+
const { restart } = require("../providers/app-controls");
45

56
const set = (key, value) => {
67
store.set(key, value);
78
};
89

10+
function setMenuOption(key, value) {
11+
set(key, value);
12+
if (store.get("options.restartOnConfigChanges")) restart();
13+
}
14+
915
const get = (key) => {
1016
return store.get(key);
1117
};
@@ -14,6 +20,7 @@ module.exports = {
1420
defaultConfig,
1521
get,
1622
set,
23+
setMenuOption,
1724
edit: () => store.openInEditor(),
1825
watch: (cb) => {
1926
store.onDidChange("options", cb);

config/plugins.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const store = require("./store");
2+
const { restart } = require("../providers/app-controls");
23

34
function getEnabled() {
45
const plugins = store.get("plugins");
@@ -24,16 +25,21 @@ function setOptions(plugin, options) {
2425
});
2526
}
2627

28+
function setMenuOptions(plugin, options) {
29+
setOptions(plugin, options);
30+
if (store.get("options.restartOnConfigChanges")) restart();
31+
}
32+
2733
function getOptions(plugin) {
2834
return store.get("plugins")[plugin];
2935
}
3036

3137
function enable(plugin) {
32-
setOptions(plugin, { enabled: true });
38+
setMenuOptions(plugin, { enabled: true });
3339
}
3440

3541
function disable(plugin) {
36-
setOptions(plugin, { enabled: false });
42+
setMenuOptions(plugin, { enabled: false });
3743
}
3844

3945
module.exports = {
@@ -42,5 +48,6 @@ module.exports = {
4248
enable,
4349
disable,
4450
setOptions,
51+
setMenuOptions,
4552
getOptions,
4653
};

index.js

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ unhandled({
2626
process.env.NODE_OPTIONS = "";
2727

2828
const app = electron.app;
29+
// Prevent window being garbage collected
30+
let mainWindow;
31+
autoUpdater.autoDownload = false;
32+
33+
if(config.get("options.singleInstanceLock")){
34+
const gotTheLock = app.requestSingleInstanceLock();
35+
if (!gotTheLock) app.quit();
36+
37+
app.on('second-instance', () => {
38+
if (!mainWindow) return;
39+
if (mainWindow.isMinimized()) mainWindow.restore();
40+
if (!mainWindow.isVisible()) mainWindow.show();
41+
mainWindow.focus();
42+
});
43+
}
44+
2945
app.commandLine.appendSwitch(
3046
"js-flags",
3147
// WebAssembly flags
@@ -54,10 +70,6 @@ require("electron-debug")({
5470
showDevTools: false //disable automatic devTools on new window
5571
});
5672

57-
// Prevent window being garbage collected
58-
let mainWindow;
59-
autoUpdater.autoDownload = false;
60-
6173
let icon = "assets/youtube-music.png";
6274
if (process.platform == "win32") {
6375
icon = "assets/generated/icon.ico";
@@ -160,22 +172,39 @@ function createMainWindow() {
160172
win.on("closed", onClosed);
161173

162174
win.on("move", () => {
175+
if (win.isMaximized()) return;
163176
let position = win.getPosition();
164-
config.set("window-position", { x: position[0], y: position[1] });
177+
lateSave("window-position", { x: position[0], y: position[1] });
165178
});
166179

180+
let winWasMaximized;
181+
167182
win.on("resize", () => {
168183
const windowSize = win.getSize();
169184

170-
config.set("window-maximized", win.isMaximized());
171-
if (!win.isMaximized()) {
172-
config.set("window-size", {
185+
const isMaximized = win.isMaximized();
186+
if (winWasMaximized !== isMaximized) {
187+
winWasMaximized = isMaximized;
188+
config.set("window-maximized", isMaximized);
189+
}
190+
if (!isMaximized) {
191+
lateSave("window-size", {
173192
width: windowSize[0],
174193
height: windowSize[1],
175194
});
176195
}
177196
});
178197

198+
let savedTimeouts = {};
199+
function lateSave(key, value) {
200+
if (savedTimeouts[key]) clearTimeout(savedTimeouts[key]);
201+
202+
savedTimeouts[key] = setTimeout(() => {
203+
config.set(key, value);
204+
savedTimeouts[key] = undefined;
205+
}, 1000)
206+
}
207+
179208
win.webContents.on("render-process-gone", (event, webContents, details) => {
180209
showUnresponsiveDialog(win, details);
181210
});
@@ -192,30 +221,31 @@ function createMainWindow() {
192221
}
193222

194223
app.once("browser-window-created", (event, win) => {
195-
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
196-
const originalUserAgent = win.webContents.userAgent;
197-
const userAgents = {
198-
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; rv:95.0) Gecko/20100101 Firefox/95.0",
199-
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
200-
linux: "Mozilla/5.0 (Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0",
201-
}
224+
if (config.get("options.overrideUserAgent")) {
225+
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
226+
const originalUserAgent = win.webContents.userAgent;
227+
const userAgents = {
228+
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; rv:95.0) Gecko/20100101 Firefox/95.0",
229+
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
230+
linux: "Mozilla/5.0 (Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0",
231+
}
202232

203-
const updatedUserAgent =
204-
is.macOS() ? userAgents.mac :
205-
is.windows() ? userAgents.windows :
206-
userAgents.linux;
233+
const updatedUserAgent =
234+
is.macOS() ? userAgents.mac :
235+
is.windows() ? userAgents.windows :
236+
userAgents.linux;
207237

208-
win.webContents.userAgent = updatedUserAgent;
209-
app.userAgentFallback = updatedUserAgent;
210-
211-
win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => {
212-
// this will only happen if login failed, and "retry" was pressed
213-
if (win.webContents.getURL().startsWith("https://accounts.google.com") && details.url.startsWith("https://accounts.google.com")){
214-
details.requestHeaders["User-Agent"] = originalUserAgent;
215-
}
216-
cb({ requestHeaders: details.requestHeaders });
217-
});
238+
win.webContents.userAgent = updatedUserAgent;
239+
app.userAgentFallback = updatedUserAgent;
218240

241+
win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => {
242+
// this will only happen if login failed, and "retry" was pressed
243+
if (win.webContents.getURL().startsWith("https://accounts.google.com") && details.url.startsWith("https://accounts.google.com")) {
244+
details.requestHeaders["User-Agent"] = originalUserAgent;
245+
}
246+
cb({ requestHeaders: details.requestHeaders });
247+
});
248+
}
219249

220250
setupSongInfo(win);
221251
loadPlugins(win);
@@ -325,12 +355,6 @@ app.on("ready", () => {
325355

326356
mainWindow = createMainWindow();
327357
setApplicationMenu(mainWindow);
328-
if (config.get("options.restartOnConfigChanges")) {
329-
config.watch(() => {
330-
app.relaunch();
331-
app.exit();
332-
});
333-
}
334358
setUpTray(app, mainWindow);
335359

336360
// Autostart at login

0 commit comments

Comments
 (0)