mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
91 lines
2.5 KiB
TypeScript
91 lines
2.5 KiB
TypeScript
import prompt from 'custom-electron-prompt';
|
|
|
|
import { Electron } from 'playwright';
|
|
|
|
import { clear, connect, isConnected, registerRefresh } from './back';
|
|
|
|
import { setMenuOptions } from '../../config/plugins';
|
|
import promptOptions from '../../providers/prompt-options';
|
|
import { singleton } from '../../providers/decorators';
|
|
import config from '../../config';
|
|
|
|
const registerRefreshOnce = singleton((refreshMenu: () => void) => {
|
|
registerRefresh(refreshMenu);
|
|
});
|
|
|
|
const DiscordOptionsObj = config.get('plugins.discord');
|
|
type DiscordOptions = typeof DiscordOptionsObj;
|
|
|
|
export default (win: Electron.BrowserWindow, options: DiscordOptions, refreshMenu: () => void) => {
|
|
registerRefreshOnce(refreshMenu);
|
|
|
|
return [
|
|
{
|
|
label: isConnected() ? 'Connected' : 'Reconnect',
|
|
enabled: !isConnected(),
|
|
click: connect,
|
|
},
|
|
{
|
|
label: 'Auto reconnect',
|
|
type: 'checkbox',
|
|
checked: options.autoReconnect,
|
|
click(item: Electron.MenuItem) {
|
|
options.autoReconnect = item.checked;
|
|
setMenuOptions('discord', options);
|
|
},
|
|
},
|
|
{
|
|
label: 'Clear activity',
|
|
click: clear,
|
|
},
|
|
{
|
|
label: 'Clear activity after timeout',
|
|
type: 'checkbox',
|
|
checked: options.activityTimoutEnabled,
|
|
click(item: Electron.MenuItem) {
|
|
options.activityTimoutEnabled = item.checked;
|
|
setMenuOptions('discord', options);
|
|
},
|
|
},
|
|
{
|
|
label: 'Listen Along',
|
|
type: 'checkbox',
|
|
checked: options.listenAlong,
|
|
click(item: Electron.MenuItem) {
|
|
options.listenAlong = item.checked;
|
|
setMenuOptions('discord', options);
|
|
},
|
|
},
|
|
{
|
|
label: 'Hide duration left',
|
|
type: 'checkbox',
|
|
checked: options.hideDurationLeft,
|
|
click(item: Electron.MenuItem) {
|
|
options.hideDurationLeft = item.checked;
|
|
setMenuOptions('discord', options);
|
|
},
|
|
},
|
|
{
|
|
label: 'Set inactivity timeout',
|
|
click: () => setInactivityTimeout(win, options),
|
|
},
|
|
];
|
|
};
|
|
|
|
async function setInactivityTimeout(win: Electron.BrowserWindow, options: DiscordOptions) {
|
|
const output = await prompt({
|
|
title: 'Set Inactivity Timeout',
|
|
label: 'Enter inactivity timeout in seconds:',
|
|
value: String(Math.round((options.activityTimoutTime ?? 0) / 1e3)),
|
|
type: 'counter',
|
|
counterOptions: { minimum: 0, multiFire: true },
|
|
width: 450,
|
|
...promptOptions(),
|
|
}, win);
|
|
|
|
if (output) {
|
|
options.activityTimoutTime = Math.round(~~output * 1e3);
|
|
setMenuOptions('discord', options);
|
|
}
|
|
}
|