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

@ -20,14 +20,16 @@ const validateVolumeLevel = (value: number) => {
// Number between 0 and 1?
if (!Number.isNaN(value) && value >= 0 && value <= 1) {
// Yup, that's fine
} else {
// Abort and throw an exception
throw new TypeError('Number between 0 and 1 expected as volume!');
}
};
type VolumeLogger = <Params extends unknown[]>(message: string, ...args: Params) => void;
type VolumeLogger = <Params extends unknown[]>(
message: string,
...args: Params
) => void;
interface VolumeFaderOptions {
/**
* logging `function(stuff, …)` for execution information (default: no logging)
@ -71,7 +73,6 @@ export class VolumeFader {
private active: boolean = false;
private fade: VolumeFade | undefined;
/**
* VolumeFader Constructor
*
@ -119,17 +120,17 @@ export class VolumeFader {
// Default dynamic range?
if (
options.fadeScaling === undefined
|| options.fadeScaling === 'logarithmic'
options.fadeScaling === undefined ||
options.fadeScaling === 'logarithmic'
) {
// Set default of 60 dB
dynamicRange = 3;
}
// Custom dynamic range?
else if (
typeof options.fadeScaling === 'number'
&& !Number.isNaN(options.fadeScaling)
&& options.fadeScaling > 0
typeof options.fadeScaling === 'number' &&
!Number.isNaN(options.fadeScaling) &&
options.fadeScaling > 0
) {
// Turn amplitude dB into a multiple of 10 power dB
dynamicRange = options.fadeScaling / 2 / 10;
@ -151,13 +152,13 @@ export class VolumeFader {
};
// Log setting if not default
options.fadeScaling
&& this.logger
&& this.logger(
'Using logarithmic fading with '
+ String(10 * dynamicRange)
+ ' dB dynamic range.',
);
options.fadeScaling &&
this.logger &&
this.logger(
'Using logarithmic fading with ' +
String(10 * dynamicRange) +
' dB dynamic range.',
);
}
// Set initial volume?
@ -169,10 +170,8 @@ export class VolumeFader {
this.media.volume = options.initialVolume;
// Log setting
this.logger
&& this.logger(
'Set initial volume to ' + String(this.media.volume) + '.',
);
this.logger &&
this.logger('Set initial volume to ' + String(this.media.volume) + '.');
}
// Fade duration given?
@ -237,8 +236,8 @@ export class VolumeFader {
this.fadeDuration = fadeDuration;
// Log setting
this.logger
&& this.logger('Set fade duration to ' + String(fadeDuration) + ' ms.');
this.logger &&
this.logger('Set fade duration to ' + String(fadeDuration) + ' ms.');
} else {
// Abort and throw an exception
throw new TypeError('Positive number expected as fade duration!');
@ -308,13 +307,14 @@ export class VolumeFader {
// Time left for fading?
if (now < this.fade.time.end) {
// Compute current fade progress
const progress
= (now - this.fade.time.start)
/ (this.fade.time.end - this.fade.time.start);
const progress =
(now - this.fade.time.start) /
(this.fade.time.end - this.fade.time.start);
// Compute current level on internal scale
const level
= (progress * (this.fade.volume.end - this.fade.volume.start)) + this.fade.volume.start;
const level =
(progress * (this.fade.volume.end - this.fade.volume.start)) +
this.fade.volume.start;
// Map fade level to volume level and apply it to media element
this.media.volume = this.scale.internalToVolume(level);
@ -323,10 +323,8 @@ export class VolumeFader {
window.requestAnimationFrame(this.updateVolume.bind(this));
} else {
// Log end of fade
this.logger
&& this.logger(
'Fade to ' + String(this.fade.volume.end) + ' complete.',
);
this.logger &&
this.logger('Fade to ' + String(this.fade.volume.end) + ' complete.');
// Time is up, jump to target volume
this.media.volume = this.scale.internalToVolume(this.fade.volume.end);
@ -389,5 +387,5 @@ export class VolumeFader {
}
export default {
VolumeFader
VolumeFader,
};

View File

@ -18,7 +18,7 @@ export type CrossfadePluginConfig = {
fadeOutDuration: number;
secondsBeforeEnd: number;
fadeScaling: 'linear' | 'logarithmic' | number;
}
};
export default createPlugin<
unknown,
@ -61,7 +61,10 @@ export default createPlugin<
fadeScaling: 'linear',
},
menu({ window, getConfig, setConfig }) {
const promptCrossfadeValues = async (win: BrowserWindow, options: CrossfadePluginConfig): Promise<Omit<CrossfadePluginConfig, 'enabled'> | undefined> => {
const promptCrossfadeValues = async (
win: BrowserWindow,
options: CrossfadePluginConfig,
): Promise<Omit<CrossfadePluginConfig, 'enabled'> | undefined> => {
const res = await prompt(
{
title: 'Crossfade Options',
@ -89,8 +92,7 @@ export default createPlugin<
},
{
label: 'Crossfade x seconds before end',
value:
options.secondsBeforeEnd,
value: options.secondsBeforeEnd,
inputAttrs: {
type: 'number',
required: true,
@ -135,7 +137,10 @@ export default createPlugin<
{
label: 'Advanced',
async click() {
const newOptions = await promptCrossfadeValues(window, await getConfig());
const newOptions = await promptCrossfadeValues(
window,
await getConfig(),
);
if (newOptions) {
setConfig(newOptions);
}
@ -170,11 +175,14 @@ export default createPlugin<
let firstVideo = true;
let waitForTransition: Promise<unknown>;
const getStreamURL = async (videoID: string): Promise<string> => this.ipc?.invoke('audio-url', videoID);
const getStreamURL = async (videoID: string): Promise<string> =>
this.ipc?.invoke('audio-url', videoID);
const getVideoIDFromURL = (url: string) => new URLSearchParams(url.split('?')?.at(-1)).get('v');
const getVideoIDFromURL = (url: string) =>
new URLSearchParams(url.split('?')?.at(-1)).get('v');
const isReadyToCrossfade = () => transitionAudio && transitionAudio.state() === 'loaded';
const isReadyToCrossfade = () =>
transitionAudio && transitionAudio.state() === 'loaded';
const watchVideoIDChanges = (cb: (id: string) => void) => {
window.navigation.addEventListener('navigate', (event) => {
@ -184,9 +192,9 @@ export default createPlugin<
const nextVideoID = getVideoIDFromURL(event.destination.url ?? '');
if (
nextVideoID
&& currentVideoID
&& (firstVideo || nextVideoID !== currentVideoID)
nextVideoID &&
currentVideoID &&
(firstVideo || nextVideoID !== currentVideoID)
) {
if (isReadyToCrossfade()) {
crossfade(() => {
@ -245,8 +253,9 @@ export default createPlugin<
// Exit just before the end for the transition
const transitionBeforeEnd = () => {
if (
video.currentTime >= video.duration - this.config!.secondsBeforeEnd
&& isReadyToCrossfade()
video.currentTime >=
video.duration - this.config!.secondsBeforeEnd &&
isReadyToCrossfade()
) {
video.removeEventListener('timeupdate', transitionBeforeEnd);
@ -294,6 +303,6 @@ export default createPlugin<
createAudioForCrossfade(url);
});
}
}
},
},
});