Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(in-app-menu): enable in-app-menu by default (in Windows) #1311

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ const defaultConfig = {
playlistMaxItems: undefined as number | undefined,
},
'exponential-volume': {},
'in-app-menu': {},
'in-app-menu': {
/**
* true in Windows, false in Linux and macOS (see youtube-music/config/store.ts)
*/
enabled: false,
},
'last-fm': {
enabled: false,
token: undefined as string | undefined, // Token used for authentication
Expand Down
10 changes: 9 additions & 1 deletion config/store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import Store from 'electron-store';
import Conf from 'conf';
import is from 'electron-is';

import defaults from './defaults';

const getDefaults = () => {
if (is.windows()) {
defaults.plugins['in-app-menu'].enabled = true;
}
return defaults;
};

const setDefaultPluginOptions = (store: Conf<Record<string, unknown>>, plugin: keyof typeof defaults.plugins) => {
if (!store.get(`plugins.${plugin}`)) {
store.set(`plugins.${plugin}`, defaults.plugins[plugin]);
Expand Down Expand Up @@ -118,7 +126,7 @@ const migrations = {
};

export default new Store({
defaults,
defaults: getDefaults(),
clearInvalidConfig: false,
migrations,
});
2 changes: 2 additions & 0 deletions plugins/in-app-menu/back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ export default (win: BrowserWindow) => {
ipcMain.handle('window-close', () => win.close());
ipcMain.handle('window-minimize', () => win.minimize());
ipcMain.handle('window-maximize', () => win.maximize());
win.on('maximize', () => win.webContents.send('window-maximize'));
ipcMain.handle('window-unmaximize', () => win.unmaximize());
win.on('unmaximize', () => win.webContents.send('window-unmaximize'));
};
13 changes: 10 additions & 3 deletions plugins/in-app-menu/front.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default async () => {
let hideMenu = config.get('options.hideMenu');
const titleBar = document.createElement('title-bar');
const navBar = document.querySelector<HTMLDivElement>('#nav-bar-background');
let maximizeButton: HTMLButtonElement;
if (isMacOS) titleBar.style.setProperty('--offset-left', '70px');

logo.classList.add('title-bar-icon');
Expand Down Expand Up @@ -55,7 +56,7 @@ export default async () => {
minimizeButton.appendChild(minimize);
minimizeButton.onclick = () => ipcRenderer.invoke('window-minimize');

const maximizeButton = document.createElement('button');
maximizeButton = document.createElement('button');
if (await ipcRenderer.invoke('window-is-maximized')) {
maximizeButton.classList.add('window-control');
maximizeButton.appendChild(unmaximize);
Expand Down Expand Up @@ -135,8 +136,14 @@ export default async () => {

document.title = 'Youtube Music';

ipcRenderer.on('refreshMenu', () => {
updateMenu();
ipcRenderer.on('refreshMenu', () => updateMenu());
ipcRenderer.on('window-maximize', () => {
maximizeButton.removeChild(maximizeButton.firstChild!);
maximizeButton.appendChild(unmaximize);
});
ipcRenderer.on('window-unmaximize', () => {
maximizeButton.removeChild(maximizeButton.firstChild!);
maximizeButton.appendChild(maximize);
});

if (isEnabled('picture-in-picture')) {
Expand Down