feat: run prettier

This commit is contained in:
JellyBrick
2023-11-30 11:59:27 +09:00
parent 44c42310f1
commit a3104fda4b
116 changed files with 2928 additions and 1254 deletions

View File

@ -12,11 +12,12 @@ export type ShortcutsPluginConfig = {
overrideMediaKeys: boolean;
global: ShortcutMappingType;
local: ShortcutMappingType;
}
};
export default createPlugin({
name: 'Shortcuts (& MPRIS)',
description: 'Allows setting global hotkeys for playback (play/pause/next/previous) + disable media osd by overriding media keys + enable Ctrl/CMD + F to search + enable linux mpris support for mediakeys + custom hotkeys for advanced users',
description:
'Allows setting global hotkeys for playback (play/pause/next/previous) + disable media osd by overriding media keys + enable Ctrl/CMD + F to search + enable linux mpris support for mediakeys + custom hotkeys for advanced users',
restartNeeded: true,
config: {
enabled: false,

View File

@ -9,20 +9,30 @@ import type { ShortcutMappingType, ShortcutsPluginConfig } from './index';
import type { BackendContext } from '@/types/contexts';
function _registerGlobalShortcut(webContents: Electron.WebContents, shortcut: string, action: (webContents: Electron.WebContents) => void) {
function _registerGlobalShortcut(
webContents: Electron.WebContents,
shortcut: string,
action: (webContents: Electron.WebContents) => void,
) {
globalShortcut.register(shortcut, () => {
action(webContents);
});
}
function _registerLocalShortcut(win: BrowserWindow, shortcut: string, action: (webContents: Electron.WebContents) => void) {
function _registerLocalShortcut(
win: BrowserWindow,
shortcut: string,
action: (webContents: Electron.WebContents) => void,
) {
registerElectronLocalShortcut(win, shortcut, () => {
action(win.webContents);
});
}
export const onMainLoad = async ({ getConfig, window }: BackendContext<ShortcutsPluginConfig>) => {
export const onMainLoad = async ({
getConfig,
window,
}: BackendContext<ShortcutsPluginConfig>) => {
const config = await getConfig();
const songControls = getSongControls(window);
@ -45,7 +55,10 @@ export const onMainLoad = async ({ getConfig, window }: BackendContext<Shortcuts
const shortcutOptions = { global, local };
for (const optionType in shortcutOptions) {
registerAllShortcuts(shortcutOptions[optionType as 'global' | 'local'], optionType);
registerAllShortcuts(
shortcutOptions[optionType as 'global' | 'local'],
optionType,
);
}
function registerAllShortcuts(container: ShortcutMappingType, type: string) {
@ -57,7 +70,12 @@ export const onMainLoad = async ({ getConfig, window }: BackendContext<Shortcuts
continue; // Action accelerator is empty
}
console.debug(`Registering ${type} shortcut`, container[action], ':', action);
console.debug(
`Registering ${type} shortcut`,
container[action],
':',
action,
);
const actionCallback: () => void = songControls[action];
if (typeof actionCallback !== 'function') {
console.warn('Invalid action', action);
@ -65,8 +83,13 @@ export const onMainLoad = async ({ getConfig, window }: BackendContext<Shortcuts
}
if (type === 'global') {
_registerGlobalShortcut(window.webContents, container[action], actionCallback);
} else { // Type === "local"
_registerGlobalShortcut(
window.webContents,
container[action],
actionCallback,
);
} else {
// Type === "local"
_registerLocalShortcut(window, local[action], actionCallback);
}
}

View File

@ -7,33 +7,49 @@ import type { BrowserWindow } from 'electron';
import type { MenuContext } from '@/types/contexts';
import type { MenuTemplate } from '@/menu';
export const onMenu = async ({ window, getConfig, setConfig }: MenuContext<ShortcutsPluginConfig>): Promise<MenuTemplate> => {
export const onMenu = async ({
window,
getConfig,
setConfig,
}: MenuContext<ShortcutsPluginConfig>): Promise<MenuTemplate> => {
const config = await getConfig();
/**
* Helper function for keybind prompt
*/
const kb = (label_: string, value_: string, default_?: string): KeybindOptions => ({ value: value_, label: label_, default: default_ });
const kb = (
label_: string,
value_: string,
default_?: string,
): KeybindOptions => ({ value: value_, label: label_, default: default_ });
async function promptKeybind(config: ShortcutsPluginConfig, win: BrowserWindow) {
const output = await prompt({
title: 'Global Keybinds',
label: 'Choose Global Keybinds for Songs Control:',
type: 'keybind',
keybindOptions: [ // If default=undefined then no default is used
kb('Previous', 'previous', config.global?.previous),
kb('Play / Pause', 'playPause', config.global?.playPause),
kb('Next', 'next', config.global?.next),
],
height: 270,
...promptOptions(),
}, win);
async function promptKeybind(
config: ShortcutsPluginConfig,
win: BrowserWindow,
) {
const output = await prompt(
{
title: 'Global Keybinds',
label: 'Choose Global Keybinds for Songs Control:',
type: 'keybind',
keybindOptions: [
// If default=undefined then no default is used
kb('Previous', 'previous', config.global?.previous),
kb('Play / Pause', 'playPause', config.global?.playPause),
kb('Next', 'next', config.global?.next),
],
height: 270,
...promptOptions(),
},
win,
);
if (output) {
const newConfig = { ...config };
for (const { value, accelerator } of output) {
newConfig.global[value as keyof ShortcutsPluginConfig['global']] = accelerator;
newConfig.global[value as keyof ShortcutsPluginConfig['global']] =
accelerator;
}
setConfig(config);

View File

@ -3,7 +3,6 @@ declare module '@jellybrick/mpris-service' {
import { interface as dbusInterface } from 'dbus-next';
interface RootInterfaceOptions {
identity: string;
supportedUriSchemes: string[];
@ -105,14 +104,11 @@ declare module '@jellybrick/mpris-service' {
setProperty(property: string, valuePlain: unknown): void;
}
interface RootInterface {
}
interface RootInterface {}
interface PlayerInterface {
}
interface PlayerInterface {}
interface TracklistInterface {
TrackListReplaced(tracks: Track[]): void;
TrackAdded(afterTrack: string): void;
@ -121,7 +117,6 @@ declare module '@jellybrick/mpris-service' {
}
interface PlaylistsInterface {
PlaylistChanged(playlist: unknown[]): void;
setActivePlaylistId(playlistId: string): void;

View File

@ -21,14 +21,17 @@ function setupMPRIS() {
function registerMPRIS(win: BrowserWindow) {
const songControls = getSongControls(win);
const { playPause, next, previous, volumeMinus10, volumePlus10, shuffle } = songControls;
const { playPause, next, previous, volumeMinus10, volumePlus10, shuffle } =
songControls;
try {
// TODO: "Typing" for this arguments
const secToMicro = (n: unknown) => Math.round(Number(n) * 1e6);
const microToSec = (n: unknown) => Math.round(Number(n) / 1e6);
const seekTo = (e: { position: unknown }) => win.webContents.send('seekTo', microToSec(e.position));
const seekBy = (o: unknown) => win.webContents.send('seekBy', microToSec(o));
const seekTo = (e: { position: unknown }) =>
win.webContents.send('seekTo', microToSec(e.position));
const seekBy = (o: unknown) =>
win.webContents.send('seekBy', microToSec(o));
const player = setupMPRIS();
@ -42,7 +45,7 @@ function registerMPRIS(win: BrowserWindow) {
ipcMain.on('seeked', (_, t: number) => player.seeked(secToMicro(t)));
let currentSeconds = 0;
ipcMain.on('timeChanged', (_, t: number) => currentSeconds = t);
ipcMain.on('timeChanged', (_, t: number) => (currentSeconds = t));
ipcMain.on('repeatChanged', (_, mode: string) => {
switch (mode) {
@ -63,7 +66,11 @@ function registerMPRIS(win: BrowserWindow) {
});
player.on('loopStatus', (status: string) => {
// SwitchRepeat cycles between states in that order
const switches = [mpris.LOOP_STATUS_NONE, mpris.LOOP_STATUS_PLAYLIST, mpris.LOOP_STATUS_TRACK];
const switches = [
mpris.LOOP_STATUS_NONE,
mpris.LOOP_STATUS_PLAYLIST,
mpris.LOOP_STATUS_TRACK,
];
const currentIndex = switches.indexOf(player.loopStatus);
const targetIndex = switches.indexOf(status);
@ -91,7 +98,10 @@ function registerMPRIS(win: BrowserWindow) {
}
});
player.on('playpause', () => {
player.playbackStatus = player.playbackStatus === mpris.PLAYBACK_STATUS_PLAYING ? mpris.PLAYBACK_STATUS_PAUSED : mpris.PLAYBACK_STATUS_PLAYING;
player.playbackStatus =
player.playbackStatus === mpris.PLAYBACK_STATUS_PLAYING
? mpris.PLAYBACK_STATUS_PAUSED
: mpris.PLAYBACK_STATUS_PLAYING;
playPause();
});
@ -106,7 +116,9 @@ function registerMPRIS(win: BrowserWindow) {
shuffle();
}
});
player.on('open', (args: { uri: string }) => { win.loadURL(args.uri); });
player.on('open', (args: { uri: string }) => {
win.loadURL(args.uri);
});
let mprisVolNewer = false;
let autoUpdate = false;
@ -166,7 +178,9 @@ function registerMPRIS(win: BrowserWindow) {
player.metadata = data;
player.seeked(secToMicro(songInfo.elapsedSeconds));
player.playbackStatus = songInfo.isPaused ? mpris.PLAYBACK_STATUS_PAUSED : mpris.PLAYBACK_STATUS_PLAYING;
player.playbackStatus = songInfo.isPaused
? mpris.PLAYBACK_STATUS_PAUSED
: mpris.PLAYBACK_STATUS_PLAYING;
}
});
} catch (error) {