mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 02:51:46 +00:00
feat: run prettier
This commit is contained in:
@ -36,7 +36,8 @@ export const defaultConfig: NotificationsPluginConfig = {
|
||||
|
||||
export default createPlugin({
|
||||
name: 'Notifications',
|
||||
description: 'Display a notification when a song starts playing (interactive notifications are available on windows)',
|
||||
description:
|
||||
'Display a notification when a song starts playing (interactive notifications are available on windows)',
|
||||
restartNeeded: true,
|
||||
config: defaultConfig,
|
||||
menu: onMenu,
|
||||
|
||||
@ -108,13 +108,19 @@ export default (
|
||||
}
|
||||
|
||||
return `\
|
||||
content="${config().toastStyle ? '' : kind.charAt(0).toUpperCase() + kind.slice(1)}"\
|
||||
content="${
|
||||
config().toastStyle
|
||||
? ''
|
||||
: kind.charAt(0).toUpperCase() + kind.slice(1)
|
||||
}"\
|
||||
imageUri="file:///${selectIcon(kind)}"
|
||||
`;
|
||||
};
|
||||
|
||||
const getButton = (kind: keyof typeof mediaIcons) =>
|
||||
`<action ${display(kind)} activationType="protocol" arguments="youtubemusic://${kind}"/>`;
|
||||
`<action ${display(
|
||||
kind,
|
||||
)} activationType="protocol" arguments="youtubemusic://${kind}"/>`;
|
||||
|
||||
const getButtons = (isPaused: boolean) => `\
|
||||
<actions>
|
||||
@ -136,19 +142,32 @@ export default (
|
||||
${getButtons(isPaused)}
|
||||
</toast>`;
|
||||
|
||||
const xmlImage = ({ title, artist, isPaused }: SongInfo, imgSrc: string, placement: string) => toast(`\
|
||||
const xmlImage = (
|
||||
{ title, artist, isPaused }: SongInfo,
|
||||
imgSrc: string,
|
||||
placement: string,
|
||||
) =>
|
||||
toast(
|
||||
`\
|
||||
<image id="1" src="${imgSrc}" name="Image" ${placement}/>
|
||||
<text id="1">${title}</text>
|
||||
<text id="2">${artist}</text>\
|
||||
`, isPaused ?? false);
|
||||
`,
|
||||
isPaused ?? false,
|
||||
);
|
||||
|
||||
const xmlLogo = (songInfo: SongInfo, imgSrc: string) => xmlImage(songInfo, imgSrc, 'placement="appLogoOverride"');
|
||||
const xmlLogo = (songInfo: SongInfo, imgSrc: string) =>
|
||||
xmlImage(songInfo, imgSrc, 'placement="appLogoOverride"');
|
||||
|
||||
const xmlHero = (songInfo: SongInfo, imgSrc: string) => xmlImage(songInfo, imgSrc, 'placement="hero"');
|
||||
const xmlHero = (songInfo: SongInfo, imgSrc: string) =>
|
||||
xmlImage(songInfo, imgSrc, 'placement="hero"');
|
||||
|
||||
const xmlBannerBottom = (songInfo: SongInfo, imgSrc: string) => xmlImage(songInfo, imgSrc, '');
|
||||
const xmlBannerBottom = (songInfo: SongInfo, imgSrc: string) =>
|
||||
xmlImage(songInfo, imgSrc, '');
|
||||
|
||||
const xmlBannerTopCustom = (songInfo: SongInfo, imgSrc: string) => toast(`\
|
||||
const xmlBannerTopCustom = (songInfo: SongInfo, imgSrc: string) =>
|
||||
toast(
|
||||
`\
|
||||
<image id="1" src="${imgSrc}" name="Image" />
|
||||
<text>ㅤ</text>
|
||||
<group>
|
||||
@ -158,37 +177,62 @@ export default (
|
||||
</subgroup>
|
||||
${xmlMoreData(songInfo)}
|
||||
</group>\
|
||||
`, songInfo.isPaused ?? false);
|
||||
`,
|
||||
songInfo.isPaused ?? false,
|
||||
);
|
||||
|
||||
const xmlMoreData = ({ album, elapsedSeconds, songDuration }: SongInfo) => `\
|
||||
<subgroup hint-textStacking="bottom">
|
||||
${album
|
||||
? `<text hint-style="captionSubtle" hint-wrap="true" hint-align="right">${album}</text>` : ''}
|
||||
<text hint-style="captionSubtle" hint-wrap="true" hint-align="right">${secondsToMinutes(elapsedSeconds ?? 0)} / ${secondsToMinutes(songDuration)}</text>
|
||||
${
|
||||
album
|
||||
? `<text hint-style="captionSubtle" hint-wrap="true" hint-align="right">${album}</text>`
|
||||
: ''
|
||||
}
|
||||
<text hint-style="captionSubtle" hint-wrap="true" hint-align="right">${secondsToMinutes(
|
||||
elapsedSeconds ?? 0,
|
||||
)} / ${secondsToMinutes(songDuration)}</text>
|
||||
</subgroup>\
|
||||
`;
|
||||
|
||||
const xmlBannerCenteredBottom = ({ title, artist, isPaused }: SongInfo, imgSrc: string) => toast(`\
|
||||
const xmlBannerCenteredBottom = (
|
||||
{ title, artist, isPaused }: SongInfo,
|
||||
imgSrc: string,
|
||||
) =>
|
||||
toast(
|
||||
`\
|
||||
<text>ㅤ</text>
|
||||
<group>
|
||||
<subgroup hint-weight="1" hint-textStacking="center">
|
||||
<text hint-align="center" hint-style="${titleFontPicker(title)}">${title}</text>
|
||||
<text hint-align="center" hint-style="${titleFontPicker(
|
||||
title,
|
||||
)}">${title}</text>
|
||||
<text hint-align="center" hint-style="SubtitleSubtle">${artist}</text>
|
||||
</subgroup>
|
||||
</group>
|
||||
<image id="1" src="${imgSrc}" name="Image" hint-removeMargin="true" />\
|
||||
`, isPaused ?? false);
|
||||
`,
|
||||
isPaused ?? false,
|
||||
);
|
||||
|
||||
const xmlBannerCenteredTop = ({ title, artist, isPaused }: SongInfo, imgSrc: string) => toast(`\
|
||||
const xmlBannerCenteredTop = (
|
||||
{ title, artist, isPaused }: SongInfo,
|
||||
imgSrc: string,
|
||||
) =>
|
||||
toast(
|
||||
`\
|
||||
<image id="1" src="${imgSrc}" name="Image" />
|
||||
<text>ㅤ</text>
|
||||
<group>
|
||||
<subgroup hint-weight="1" hint-textStacking="center">
|
||||
<text hint-align="center" hint-style="${titleFontPicker(title)}">${title}</text>
|
||||
<text hint-align="center" hint-style="${titleFontPicker(
|
||||
title,
|
||||
)}">${title}</text>
|
||||
<text hint-align="center" hint-style="SubtitleSubtle">${artist}</text>
|
||||
</subgroup>
|
||||
</group>\
|
||||
`, isPaused ?? false);
|
||||
`,
|
||||
isPaused ?? false,
|
||||
);
|
||||
|
||||
const titleFontPicker = (title: string) => {
|
||||
if (title.length <= 13) {
|
||||
@ -206,7 +250,6 @@ export default (
|
||||
return 'Subtitle';
|
||||
};
|
||||
|
||||
|
||||
songControls = getSongControls(win);
|
||||
|
||||
let currentSeconds = 0;
|
||||
@ -226,8 +269,9 @@ export default (
|
||||
}
|
||||
|
||||
savedSongInfo = { ...songInfo };
|
||||
if (!songInfo.isPaused
|
||||
&& (songInfo.url !== lastUrl || config().unpauseNotification)
|
||||
if (
|
||||
!songInfo.isPaused &&
|
||||
(songInfo.url !== lastUrl || config().unpauseNotification)
|
||||
) {
|
||||
lastUrl = songInfo.url;
|
||||
sendNotification(songInfo);
|
||||
@ -260,24 +304,21 @@ export default (
|
||||
savedNotification?.close();
|
||||
});
|
||||
|
||||
changeProtocolHandler(
|
||||
(cmd) => {
|
||||
if (Object.keys(songControls).includes(cmd)) {
|
||||
songControls[cmd as keyof typeof songControls]();
|
||||
if (config().refreshOnPlayPause && (
|
||||
cmd === 'pause'
|
||||
|| (cmd === 'play' && !config().unpauseNotification)
|
||||
)
|
||||
) {
|
||||
setImmediate(() =>
|
||||
sendNotification({
|
||||
...savedSongInfo,
|
||||
isPaused: cmd === 'pause',
|
||||
elapsedSeconds: currentSeconds,
|
||||
}),
|
||||
);
|
||||
}
|
||||
changeProtocolHandler((cmd) => {
|
||||
if (Object.keys(songControls).includes(cmd)) {
|
||||
songControls[cmd as keyof typeof songControls]();
|
||||
if (
|
||||
config().refreshOnPlayPause &&
|
||||
(cmd === 'pause' || (cmd === 'play' && !config().unpauseNotification))
|
||||
) {
|
||||
setImmediate(() =>
|
||||
sendNotification({
|
||||
...savedSongInfo,
|
||||
isPaused: cmd === 'pause',
|
||||
elapsedSeconds: currentSeconds,
|
||||
}),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -31,7 +31,10 @@ const setup = () => {
|
||||
let currentUrl: string | undefined;
|
||||
|
||||
registerCallback((songInfo: SongInfo) => {
|
||||
if (!songInfo.isPaused && (songInfo.url !== currentUrl || config.unpauseNotification)) {
|
||||
if (
|
||||
!songInfo.isPaused &&
|
||||
(songInfo.url !== currentUrl || config.unpauseNotification)
|
||||
) {
|
||||
// Close the old notification
|
||||
oldNotification?.close();
|
||||
currentUrl = songInfo.url;
|
||||
@ -43,11 +46,14 @@ const setup = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const onMainLoad = async (context: BackendContext<NotificationsPluginConfig>) => {
|
||||
export const onMainLoad = async (
|
||||
context: BackendContext<NotificationsPluginConfig>,
|
||||
) => {
|
||||
config = await context.getConfig();
|
||||
|
||||
// Register the callback for new song information
|
||||
if (is.windows() && config.interactive) interactive(context.window, () => config, context);
|
||||
if (is.windows() && config.interactive)
|
||||
interactive(context.window, () => config, context);
|
||||
else setup();
|
||||
};
|
||||
|
||||
|
||||
@ -8,7 +8,10 @@ import type { NotificationsPluginConfig } from './index';
|
||||
import type { MenuTemplate } from '@/menu';
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
|
||||
export const onMenu = async ({ getConfig, setConfig }: MenuContext<NotificationsPluginConfig>): Promise<MenuTemplate> => {
|
||||
export const onMenu = async ({
|
||||
getConfig,
|
||||
setConfig,
|
||||
}: MenuContext<NotificationsPluginConfig>): Promise<MenuTemplate> => {
|
||||
const config = await getConfig();
|
||||
|
||||
const getToastStyleMenuItems = (options: NotificationsPluginConfig) => {
|
||||
@ -38,7 +41,7 @@ export const onMenu = async ({ getConfig, setConfig }: MenuContext<Notifications
|
||||
checked: config.urgency === level.value,
|
||||
click: () => setConfig({ urgency: level.value }),
|
||||
})),
|
||||
}
|
||||
},
|
||||
];
|
||||
} else if (is.windows()) {
|
||||
return [
|
||||
@ -57,19 +60,22 @@ export const onMenu = async ({ getConfig, setConfig }: MenuContext<Notifications
|
||||
label: 'Open/Close on tray click',
|
||||
type: 'checkbox',
|
||||
checked: config.trayControls,
|
||||
click: (item: MenuItem) => setConfig({ trayControls: item.checked }),
|
||||
click: (item: MenuItem) =>
|
||||
setConfig({ trayControls: item.checked }),
|
||||
},
|
||||
{
|
||||
label: 'Hide Button Text',
|
||||
type: 'checkbox',
|
||||
checked: config.hideButtonText,
|
||||
click: (item: MenuItem) => setConfig({ hideButtonText: item.checked }),
|
||||
click: (item: MenuItem) =>
|
||||
setConfig({ hideButtonText: item.checked }),
|
||||
},
|
||||
{
|
||||
label: 'Refresh on Play/Pause',
|
||||
type: 'checkbox',
|
||||
checked: config.refreshOnPlayPause,
|
||||
click: (item: MenuItem) => setConfig({ refreshOnPlayPause: item.checked }),
|
||||
click: (item: MenuItem) =>
|
||||
setConfig({ refreshOnPlayPause: item.checked }),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@ -14,7 +14,6 @@ const userData = app.getPath('userData');
|
||||
const temporaryIcon = path.join(userData, 'tempIcon.png');
|
||||
const temporaryBanner = path.join(userData, 'tempBanner.png');
|
||||
|
||||
|
||||
export const ToastStyles = {
|
||||
logo: 1,
|
||||
banner_centered_top: 2,
|
||||
@ -43,7 +42,10 @@ const nativeImageToLogo = cache((nativeImage: NativeImage) => {
|
||||
});
|
||||
});
|
||||
|
||||
export const notificationImage = (songInfo: SongInfo, config: NotificationsPluginConfig) => {
|
||||
export const notificationImage = (
|
||||
songInfo: SongInfo,
|
||||
config: NotificationsPluginConfig,
|
||||
) => {
|
||||
if (!songInfo.image) {
|
||||
return youtubeMusicIcon;
|
||||
}
|
||||
@ -76,11 +78,10 @@ export const saveImage = cache((img: NativeImage, savePath: string) => {
|
||||
return savePath;
|
||||
});
|
||||
|
||||
export const snakeToCamel = (string_: string) => string_.replaceAll(/([-_][a-z]|^[a-z])/g, (group) =>
|
||||
group.toUpperCase()
|
||||
.replace('-', ' ')
|
||||
.replace('_', ' '),
|
||||
);
|
||||
export const snakeToCamel = (string_: string) =>
|
||||
string_.replaceAll(/([-_][a-z]|^[a-z])/g, (group) =>
|
||||
group.toUpperCase().replace('-', ' ').replace('_', ' '),
|
||||
);
|
||||
|
||||
export const secondsToMinutes = (seconds: number) => {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
|
||||
Reference in New Issue
Block a user