mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 04:41:47 +00:00
in-app-menu
This commit is contained in:
@ -1,21 +1,28 @@
|
|||||||
import titlebarStyle from './titlebar.css?inline';
|
import titlebarStyle from './titlebar.css?inline';
|
||||||
|
import { createPlugin } from '@/utils';
|
||||||
|
import { onMainLoad } from '@/plugins/in-app-menu/main';
|
||||||
|
import { onMenu } from '@/plugins/in-app-menu/menu';
|
||||||
|
import { onPlayerApiReady, onRendererLoad } from '@/plugins/in-app-menu/renderer';
|
||||||
|
|
||||||
import { createPluginBuilder } from '../utils/builder';
|
export interface InAppMenuConfig {
|
||||||
|
enabled: boolean;
|
||||||
|
hideDOMWindowControls: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const builder = createPluginBuilder('in-app-menu', {
|
export default createPlugin({
|
||||||
name: 'In-App Menu',
|
name: 'In-App Menu',
|
||||||
restartNeeded: true,
|
restartNeeded: true,
|
||||||
config: {
|
config: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
hideDOMWindowControls: false,
|
hideDOMWindowControls: false,
|
||||||
|
} as InAppMenuConfig,
|
||||||
|
stylesheets: [titlebarStyle],
|
||||||
|
menu: onMenu,
|
||||||
|
|
||||||
|
backend: onMainLoad,
|
||||||
|
renderer: {
|
||||||
|
start: onRendererLoad,
|
||||||
|
onPlayerApiReady,
|
||||||
},
|
},
|
||||||
styles: [titlebarStyle],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default builder;
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface PluginBuilderList {
|
|
||||||
[builder.id]: typeof builder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -2,12 +2,10 @@ import { register } from 'electron-localshortcut';
|
|||||||
|
|
||||||
import { BrowserWindow, Menu, MenuItem, ipcMain, nativeImage } from 'electron';
|
import { BrowserWindow, Menu, MenuItem, ipcMain, nativeImage } from 'electron';
|
||||||
|
|
||||||
import builder from './index';
|
import { BackendContext } from '@/types/contexts';
|
||||||
|
import { InAppMenuConfig } from '@/plugins/in-app-menu/index';
|
||||||
|
|
||||||
export default builder.createMain(({ handle, send }) => {
|
export const onMainLoad = ({ window: win, ipc: { handle, send } }: BackendContext<InAppMenuConfig>) => {
|
||||||
|
|
||||||
return {
|
|
||||||
onLoad(win) {
|
|
||||||
win.on('close', () => {
|
win.on('close', () => {
|
||||||
send('close-all-in-app-menu-panel');
|
send('close-all-in-app-menu-panel');
|
||||||
});
|
});
|
||||||
@ -71,6 +69,4 @@ export default builder.createMain(({ handle, send }) => {
|
|||||||
const nativeImageIcon = nativeImage.createFromPath(imagePath);
|
const nativeImageIcon = nativeImage.createFromPath(imagePath);
|
||||||
return nativeImageIcon?.toDataURL();
|
return nativeImageIcon?.toDataURL();
|
||||||
});
|
});
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import is from 'electron-is';
|
import is from 'electron-is';
|
||||||
|
|
||||||
import builder from './index';
|
import { setMenuOptions } from '@/config/plugins';
|
||||||
|
|
||||||
import { setMenuOptions } from '../../config/plugins';
|
import type { InAppMenuConfig } from './index';
|
||||||
|
import type { MenuContext } from '@/types/contexts';
|
||||||
|
import type { MenuTemplate } from '@/menu';
|
||||||
|
|
||||||
export default builder.createMenu(async ({ getConfig }) => {
|
export const onMenu = async ({ getConfig }: MenuContext<InAppMenuConfig>): Promise<MenuTemplate> => {
|
||||||
const config = await getConfig();
|
const config = await getConfig();
|
||||||
|
|
||||||
if (is.linux()) {
|
if (is.linux()) {
|
||||||
@ -22,4 +24,4 @@ export default builder.createMenu(async ({ getConfig }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
});
|
};
|
||||||
|
|||||||
@ -6,16 +6,15 @@ import minimizeRaw from './assets/minimize.svg?inline';
|
|||||||
import maximizeRaw from './assets/maximize.svg?inline';
|
import maximizeRaw from './assets/maximize.svg?inline';
|
||||||
import unmaximizeRaw from './assets/unmaximize.svg?inline';
|
import unmaximizeRaw from './assets/unmaximize.svg?inline';
|
||||||
|
|
||||||
import builder from './index';
|
|
||||||
|
|
||||||
import type { Menu } from 'electron';
|
import type { Menu } from 'electron';
|
||||||
|
|
||||||
|
import type { RendererContext } from '@/types/contexts';
|
||||||
|
import type { InAppMenuConfig } from '@/plugins/in-app-menu/index';
|
||||||
|
|
||||||
const isMacOS = navigator.userAgent.includes('Macintosh');
|
const isMacOS = navigator.userAgent.includes('Macintosh');
|
||||||
const isNotWindowsOrMacOS = !navigator.userAgent.includes('Windows') && !isMacOS;
|
const isNotWindowsOrMacOS = !navigator.userAgent.includes('Windows') && !isMacOS;
|
||||||
|
|
||||||
export default builder.createRenderer(({ getConfig, invoke, on }) => {
|
export const onRendererLoad = async ({ getConfig, ipc: { invoke, on } }: RendererContext<InAppMenuConfig>) => {
|
||||||
return {
|
|
||||||
async onLoad() {
|
|
||||||
const config = await getConfig();
|
const config = await getConfig();
|
||||||
|
|
||||||
const hideDOMWindowControls = config.hideDOMWindowControls;
|
const hideDOMWindowControls = config.hideDOMWindowControls;
|
||||||
@ -140,7 +139,7 @@ export default builder.createRenderer(({ getConfig, invoke, on }) => {
|
|||||||
});
|
});
|
||||||
panelClosers = [];
|
panelClosers = [];
|
||||||
|
|
||||||
const menu = await invoke<Menu | null>('get-menu');
|
const menu = await invoke('get-menu') as Menu | null;
|
||||||
if (!menu) return;
|
if (!menu) return;
|
||||||
|
|
||||||
menu.items.forEach((menuItem) => {
|
menu.items.forEach((menuItem) => {
|
||||||
@ -182,14 +181,12 @@ export default builder.createRenderer(({ getConfig, invoke, on }) => {
|
|||||||
updateMenu();
|
updateMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
// Increases the right margin of Navbar background when the scrollbar is visible to avoid blocking it (z-index doesn't affect it)
|
|
||||||
onPlayerApiReady() {
|
export const onPlayerApiReady = () => {
|
||||||
const htmlHeadStyle = document.querySelector('head > div > style');
|
const htmlHeadStyle = document.querySelector('head > div > style');
|
||||||
if (htmlHeadStyle) {
|
if (htmlHeadStyle) {
|
||||||
// HACK: This is a hack to remove the scrollbar width
|
// HACK: This is a hack to remove the scrollbar width
|
||||||
htmlHeadStyle.innerHTML = htmlHeadStyle.innerHTML.replace('html::-webkit-scrollbar {width: var(--ytmusic-scrollbar-width);', 'html::-webkit-scrollbar {');
|
htmlHeadStyle.innerHTML = htmlHeadStyle.innerHTML.replace('html::-webkit-scrollbar {width: var(--ytmusic-scrollbar-width);', 'html::-webkit-scrollbar {');
|
||||||
}
|
}
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user