mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 03:11:46 +00:00
chore: improve readability
This commit is contained in:
31
src/index.ts
31
src/index.ts
@ -43,7 +43,7 @@ import {
|
||||
setupProtocolHandler,
|
||||
} from '@/providers/protocol-handler';
|
||||
|
||||
import youtubeMusicCSS from '@/youtube-music.css?inline';
|
||||
import musicPlayerCss from '@/music-player.css?inline';
|
||||
|
||||
import {
|
||||
forceLoadMainPlugin,
|
||||
@ -131,7 +131,7 @@ if (config.get('options.disableHardwareAcceleration')) {
|
||||
|
||||
if (is.linux()) {
|
||||
// Overrides WM_CLASS for X11 to correspond to icon filename
|
||||
app.setName('com.github.th_ch.youtube_music');
|
||||
app.setName('com.github.th_ch.pear_music');
|
||||
|
||||
// Stops chromium from launching its own MPRIS service
|
||||
if (await config.plugins.isEnabled('shortcuts')) {
|
||||
@ -165,7 +165,7 @@ electronDebug({
|
||||
showDevTools: false, // Disable automatic devTools on new window
|
||||
});
|
||||
|
||||
let icon = 'assets/youtube-music.png';
|
||||
let icon = 'assets/icon.png';
|
||||
if (process.platform === 'win32') {
|
||||
icon = 'assets/generated/icon.ico';
|
||||
} else if (process.platform === 'darwin') {
|
||||
@ -178,7 +178,7 @@ function onClosed() {
|
||||
mainWindow = null;
|
||||
}
|
||||
|
||||
ipcMain.handle('ytmd:get-main-plugin-names', async () =>
|
||||
ipcMain.handle('peard:get-main-plugin-names', async () =>
|
||||
Object.keys(await mainPlugins()),
|
||||
);
|
||||
|
||||
@ -186,14 +186,14 @@ const initHook = async (win: BrowserWindow) => {
|
||||
const allPluginStubs = await allPlugins();
|
||||
|
||||
ipcMain.handle(
|
||||
'ytmd:get-config',
|
||||
'peard:get-config',
|
||||
(_, id: string) =>
|
||||
deepmerge(
|
||||
allPluginStubs[id].config ?? { enabled: false },
|
||||
config.get(`plugins.${id}`) ?? {},
|
||||
) as PluginConfig,
|
||||
);
|
||||
ipcMain.handle('ytmd:set-config', (_, name: string, obj: object) =>
|
||||
ipcMain.handle('peard:set-config', (_, name: string, obj: object) =>
|
||||
config.setPartial(`plugins.${name}`, obj, allPluginStubs[name].config),
|
||||
);
|
||||
|
||||
@ -292,7 +292,7 @@ const showNeedToRestartDialog = async (id: string) => {
|
||||
};
|
||||
|
||||
function initTheme(win: BrowserWindow) {
|
||||
injectCSS(win.webContents, youtubeMusicCSS);
|
||||
injectCSS(win.webContents, musicPlayerCss);
|
||||
// Load user CSS
|
||||
const themes: string[] = config.get('options.themes');
|
||||
if (Array.isArray(themes)) {
|
||||
@ -503,11 +503,14 @@ async function createMainWindow() {
|
||||
const url = new URL(event.url);
|
||||
|
||||
// Workarounds for regions where YTM is restricted
|
||||
if (url.hostname.endsWith('youtube.com') && url.pathname === '/premium') {
|
||||
if (
|
||||
url.hostname.endsWith('\u0079\u006f\u0075\u0074\u0075\u0062\u0065.com') &&
|
||||
url.pathname === '/premium'
|
||||
) {
|
||||
event.preventDefault();
|
||||
|
||||
win.webContents.loadURL(
|
||||
'https://accounts.google.com/ServiceLogin?ltmpl=music&service=youtube&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26next%3Dhttps%253A%252F%252Fmusic.youtube.com%252F',
|
||||
'https://accounts.google.com/ServiceLogin?ltmpl=music&service=\u0079\u006f\u0075\u0074\u0075\u0062\u0065&continue=https%3A%2F%2Fwww.\u0079\u006f\u0075\u0074\u0075\u0062\u0065.com%2Fsignin%3Faction_handle_signin%3Dtrue%26next%3Dhttps%253A%252F%252Fmusic.\u0079\u006f\u0075\u0074\u0075\u0062\u0065.com%252F',
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -660,7 +663,7 @@ app.whenReady().then(async () => {
|
||||
|
||||
// Register appID on windows
|
||||
if (is.windows()) {
|
||||
const appID = 'com.github.th-ch.youtube-music';
|
||||
const appID = 'com.github.th-ch.pear-music';
|
||||
app.setAppUserModelId(appID);
|
||||
const appLocation = process.execPath;
|
||||
const appData = app.getPath('appData');
|
||||
@ -675,7 +678,7 @@ app.whenReady().then(async () => {
|
||||
'Windows',
|
||||
'Start Menu',
|
||||
'Programs',
|
||||
'YouTube Music.lnk',
|
||||
'Pear Desktop.lnk',
|
||||
);
|
||||
try {
|
||||
// Check if shortcut is registered and valid
|
||||
@ -695,7 +698,7 @@ app.whenReady().then(async () => {
|
||||
{
|
||||
target: appLocation,
|
||||
cwd: path.dirname(appLocation),
|
||||
description: 'YouTube Music Desktop App - including custom plugins',
|
||||
description: 'Pear Desktop App - including custom plugins',
|
||||
appUserModelId: appID,
|
||||
},
|
||||
);
|
||||
@ -804,7 +807,7 @@ app.whenReady().then(async () => {
|
||||
}, 2000);
|
||||
autoUpdater.on('update-available', () => {
|
||||
const downloadLink =
|
||||
'https://github.com/th-ch/youtube-music/releases/latest';
|
||||
'https://github.com/pear-devs/pear-desktop/releases/latest';
|
||||
const dialogOptions: Electron.MessageBoxOptions = {
|
||||
type: 'info',
|
||||
buttons: [
|
||||
@ -943,7 +946,7 @@ function removeContentSecurityPolicy(
|
||||
!details.responseHeaders['access-control-allow-origin'] &&
|
||||
!details.responseHeaders['Access-Control-Allow-Origin']
|
||||
) {
|
||||
details.responseHeaders['access-control-allow-origin'] = ['https://music.youtube.com'];
|
||||
details.responseHeaders['access-control-allow-origin'] = ['https://music.\u0079\u006f\u0075\u0074\u0075\u0062\u0065.com'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user