mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 04:11:47 +00:00
feat: add startingPage unset option
This commit is contained in:
31
index.ts
31
index.ts
@ -1,6 +1,6 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import electron, { BrowserWindow } from 'electron';
|
import { BrowserWindow, app, screen, globalShortcut, session, shell, dialog } from 'electron';
|
||||||
import enhanceWebRequest from 'electron-better-web-request';
|
import enhanceWebRequest from 'electron-better-web-request';
|
||||||
import is from 'electron-is';
|
import is from 'electron-is';
|
||||||
import unhandled from 'electron-unhandled';
|
import unhandled from 'electron-unhandled';
|
||||||
@ -28,7 +28,6 @@ unhandled({
|
|||||||
// Disable Node options if the env var is set
|
// Disable Node options if the env var is set
|
||||||
process.env.NODE_OPTIONS = '';
|
process.env.NODE_OPTIONS = '';
|
||||||
|
|
||||||
const { app } = electron;
|
|
||||||
// Prevent window being garbage collected
|
// Prevent window being garbage collected
|
||||||
let mainWindow: Electron.BrowserWindow | null;
|
let mainWindow: Electron.BrowserWindow | null;
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
@ -40,7 +39,7 @@ if (!gotTheLock) {
|
|||||||
|
|
||||||
// SharedArrayBuffer: Required for downloader (@ffmpeg/core-mt)
|
// SharedArrayBuffer: Required for downloader (@ffmpeg/core-mt)
|
||||||
// OverlayScrollbar: Required for overlay scrollbars
|
// OverlayScrollbar: Required for overlay scrollbars
|
||||||
app.commandLine.appendSwitch('enable-features', 'OverlayScrollbar,SharedArrayBuffer');
|
app.commandLine.appendSwitch('enable-features', 'OverlayScrollbar,FluentScrollbar,SharedArrayBuffer');
|
||||||
if (config.get('options.disableHardwareAcceleration')) {
|
if (config.get('options.disableHardwareAcceleration')) {
|
||||||
if (is.dev()) {
|
if (is.dev()) {
|
||||||
console.log('Disabling hardware acceleration');
|
console.log('Disabling hardware acceleration');
|
||||||
@ -157,7 +156,7 @@ function createMainWindow() {
|
|||||||
const { x, y } = windowPosition;
|
const { x, y } = windowPosition;
|
||||||
const winSize = win.getSize();
|
const winSize = win.getSize();
|
||||||
const displaySize
|
const displaySize
|
||||||
= electron.screen.getDisplayNearestPoint(windowPosition).bounds;
|
= screen.getDisplayNearestPoint(windowPosition).bounds;
|
||||||
if (
|
if (
|
||||||
x + winSize[0] < displaySize.x - 8
|
x + winSize[0] < displaySize.x - 8
|
||||||
|| x - winSize[0] > displaySize.x + displaySize.width
|
|| x - winSize[0] > displaySize.x + displaySize.width
|
||||||
@ -340,7 +339,7 @@ app.on('window-all-closed', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unregister all shortcuts.
|
// Unregister all shortcuts.
|
||||||
electron.globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
@ -361,7 +360,7 @@ app.on('ready', () => {
|
|||||||
console.log('Clearing app cache.');
|
console.log('Clearing app cache.');
|
||||||
}
|
}
|
||||||
|
|
||||||
electron.session.defaultSession.clearCache();
|
session.defaultSession.clearCache();
|
||||||
clearTimeout(clearCacheTimeout);
|
clearTimeout(clearCacheTimeout);
|
||||||
}, 20_000);
|
}, 20_000);
|
||||||
}
|
}
|
||||||
@ -376,7 +375,7 @@ app.on('ready', () => {
|
|||||||
if (!is.dev() && !appLocation.startsWith(path.join(appData, '..', 'Local', 'Temp'))) {
|
if (!is.dev() && !appLocation.startsWith(path.join(appData, '..', 'Local', 'Temp'))) {
|
||||||
const shortcutPath = path.join(appData, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'YouTube Music.lnk');
|
const shortcutPath = path.join(appData, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'YouTube Music.lnk');
|
||||||
try { // Check if shortcut is registered and valid
|
try { // Check if shortcut is registered and valid
|
||||||
const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // Throw error if doesn't exist yet
|
const shortcutDetails = shell.readShortcutLink(shortcutPath); // Throw error if doesn't exist yet
|
||||||
if (
|
if (
|
||||||
shortcutDetails.target !== appLocation
|
shortcutDetails.target !== appLocation
|
||||||
|| shortcutDetails.appUserModelId !== appID
|
|| shortcutDetails.appUserModelId !== appID
|
||||||
@ -384,7 +383,7 @@ app.on('ready', () => {
|
|||||||
throw 'needUpdate';
|
throw 'needUpdate';
|
||||||
}
|
}
|
||||||
} catch (error) { // If not valid -> Register shortcut
|
} catch (error) { // If not valid -> Register shortcut
|
||||||
electron.shell.writeShortcutLink(
|
shell.writeShortcutLink(
|
||||||
shortcutPath,
|
shortcutPath,
|
||||||
error === 'needUpdate' ? 'update' : 'create',
|
error === 'needUpdate' ? 'update' : 'create',
|
||||||
{
|
{
|
||||||
@ -453,11 +452,11 @@ app.on('ready', () => {
|
|||||||
message: 'A new version is available',
|
message: 'A new version is available',
|
||||||
detail: `A new version is available and can be downloaded at ${downloadLink}`,
|
detail: `A new version is available and can be downloaded at ${downloadLink}`,
|
||||||
};
|
};
|
||||||
electron.dialog.showMessageBox(dialogOptions).then((dialogOutput) => {
|
dialog.showMessageBox(dialogOptions).then((dialogOutput) => {
|
||||||
switch (dialogOutput.response) {
|
switch (dialogOutput.response) {
|
||||||
// Download
|
// Download
|
||||||
case 1: {
|
case 1: {
|
||||||
electron.shell.openExternal(downloadLink);
|
shell.openExternal(downloadLink);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +475,7 @@ app.on('ready', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.get('options.hideMenu') && !config.get('options.hideMenuWarned')) {
|
if (config.get('options.hideMenu') && !config.get('options.hideMenuWarned')) {
|
||||||
electron.dialog.showMessageBox(mainWindow, {
|
dialog.showMessageBox(mainWindow, {
|
||||||
type: 'info', title: 'Hide Menu Enabled',
|
type: 'info', title: 'Hide Menu Enabled',
|
||||||
message: "Menu is hidden, use 'Alt' to show it (or 'Escape' if using in-app-menu)",
|
message: "Menu is hidden, use 'Alt' to show it (or 'Escape' if using in-app-menu)",
|
||||||
});
|
});
|
||||||
@ -509,7 +508,7 @@ function showUnresponsiveDialog(win: BrowserWindow, details: Electron.RenderProc
|
|||||||
console.log('Unresponsive Error!\n' + JSON.stringify(details, null, '\t'));
|
console.log('Unresponsive Error!\n' + JSON.stringify(details, null, '\t'));
|
||||||
}
|
}
|
||||||
|
|
||||||
electron.dialog.showMessageBox(win, {
|
dialog.showMessageBox(win, {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
title: 'Window Unresponsive',
|
title: 'Window Unresponsive',
|
||||||
message: 'The Application is Unresponsive',
|
message: 'The Application is Unresponsive',
|
||||||
@ -534,15 +533,15 @@ function showUnresponsiveDialog(win: BrowserWindow, details: Electron.RenderProc
|
|||||||
// HACK: electron-better-web-request's typing is wrong
|
// HACK: electron-better-web-request's typing is wrong
|
||||||
type BetterSession = Omit<Electron.Session, 'webRequest'> & { webRequest: BetterWebRequest & Electron.WebRequest };
|
type BetterSession = Omit<Electron.Session, 'webRequest'> & { webRequest: BetterWebRequest & Electron.WebRequest };
|
||||||
function removeContentSecurityPolicy(
|
function removeContentSecurityPolicy(
|
||||||
session: BetterSession = electron.session.defaultSession as BetterSession,
|
betterSession: BetterSession = session.defaultSession as BetterSession,
|
||||||
) {
|
) {
|
||||||
// Allows defining multiple "onHeadersReceived" listeners
|
// Allows defining multiple "onHeadersReceived" listeners
|
||||||
// by enhancing the session.
|
// by enhancing the session.
|
||||||
// Some plugins (e.g. adblocker) also define a "onHeadersReceived" listener
|
// Some plugins (e.g. adblocker) also define a "onHeadersReceived" listener
|
||||||
enhanceWebRequest(session);
|
enhanceWebRequest(betterSession);
|
||||||
|
|
||||||
// Custom listener to tweak the content security policy
|
// Custom listener to tweak the content security policy
|
||||||
session.webRequest.onHeadersReceived((details, callback) => {
|
betterSession.webRequest.onHeadersReceived((details, callback) => {
|
||||||
details.responseHeaders ??= {};
|
details.responseHeaders ??= {};
|
||||||
|
|
||||||
// Remove the content security policy
|
// Remove the content security policy
|
||||||
@ -554,7 +553,7 @@ function removeContentSecurityPolicy(
|
|||||||
|
|
||||||
type ResolverListener = { apply: () => Promise<Record<string, unknown>>; context: unknown };
|
type ResolverListener = { apply: () => Promise<Record<string, unknown>>; context: unknown };
|
||||||
// When multiple listeners are defined, apply them all
|
// When multiple listeners are defined, apply them all
|
||||||
session.webRequest.setResolver('onHeadersReceived', async (listeners: ResolverListener[]) => {
|
betterSession.webRequest.setResolver('onHeadersReceived', async (listeners: ResolverListener[]) => {
|
||||||
return listeners.reduce<Promise<Record<string, unknown>>>(
|
return listeners.reduce<Promise<Record<string, unknown>>>(
|
||||||
async (accumulator: Promise<Record<string, unknown>>, listener: ResolverListener) => {
|
async (accumulator: Promise<Record<string, unknown>>, listener: ResolverListener) => {
|
||||||
const acc = await accumulator;
|
const acc = await accumulator;
|
||||||
|
|||||||
29
menu.ts
29
menu.ts
@ -95,14 +95,25 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Starting page',
|
label: 'Starting page',
|
||||||
submenu: Object.keys(startingPages).map((name) => ({
|
submenu: (() => {
|
||||||
label: name,
|
const subMenuArray: Electron.MenuItemConstructorOptions[] = Object.keys(startingPages).map((name) => ({
|
||||||
type: 'radio',
|
label: name,
|
||||||
checked: config.get('options.startingPage') === name,
|
type: 'radio',
|
||||||
click() {
|
checked: config.get('options.startingPage') === name,
|
||||||
config.set('options.startingPage', name);
|
click() {
|
||||||
},
|
config.set('options.startingPage', name);
|
||||||
})),
|
},
|
||||||
|
}));
|
||||||
|
subMenuArray.unshift({
|
||||||
|
label: 'Unset',
|
||||||
|
type: 'radio',
|
||||||
|
checked: config.get('options.startingPage') === '',
|
||||||
|
click() {
|
||||||
|
config.set('options.startingPage', '');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return subMenuArray;
|
||||||
|
})(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Visual Tweaks',
|
label: 'Visual Tweaks',
|
||||||
@ -274,7 +285,7 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
|
|||||||
{
|
{
|
||||||
label: 'Proxy',
|
label: 'Proxy',
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
checked: !!(config.get('options.proxy')),
|
checked: !!(config.get('options.proxy')) && config.get('options.proxy') !== '',
|
||||||
click(item) {
|
click(item) {
|
||||||
setProxy(item, win);
|
setProxy(item, win);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user