Skip to content

Commit 55a442e

Browse files
committed
lint
1 parent 764f08e commit 55a442e

File tree

2 files changed

+136
-137
lines changed

2 files changed

+136
-137
lines changed

config/dynamic.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
const { ipcRenderer, ipcMain } = require('electron');
1+
const { ipcRenderer, ipcMain } = require("electron");
22

3-
const defaultConfig = require('./defaults');
4-
const { getOptions, setOptions, setMenuOptions } = require('./plugins');
5-
const { sendToFront } = require('../providers/app-controls');
3+
const defaultConfig = require("./defaults");
4+
const { getOptions, setOptions, setMenuOptions } = require("./plugins");
5+
const { sendToFront } = require("../providers/app-controls");
66

77
const activePlugins = {};
88
/**
99
* [!IMPORTANT!]
1010
* The method is **sync** in the main process and **async** in the renderer process.
1111
*/
1212
module.exports.getActivePlugins =
13-
process.type === 'renderer'
14-
? async () => ipcRenderer.invoke('get-active-plugins')
13+
process.type === "renderer"
14+
? async () => ipcRenderer.invoke("get-active-plugins")
1515
: () => activePlugins;
1616

17-
if (process.type === 'browser') {
18-
ipcMain.handle('get-active-plugins', this.getActivePlugins);
17+
if (process.type === "browser") {
18+
ipcMain.handle("get-active-plugins", this.getActivePlugins);
1919
}
2020

2121
/**
2222
* [!IMPORTANT!]
2323
* The method is **sync** in the main process and **async** in the renderer process.
2424
*/
2525
module.exports.isActive =
26-
process.type === 'renderer'
26+
process.type === "renderer"
2727
? async (plugin) =>
28-
plugin in (await ipcRenderer.invoke('get-active-plugins'))
28+
plugin in (await ipcRenderer.invoke("get-active-plugins"))
2929
: (plugin) => plugin in activePlugins;
3030

3131
/**
@@ -99,8 +99,8 @@ module.exports.PluginConfig = class PluginConfig {
9999
};
100100

101101
setAll = (options) => {
102-
if (!options || typeof options !== 'object')
103-
throw new Error('Options must be an object.');
102+
if (!options || typeof options !== "object")
103+
throw new Error("Options must be an object.");
104104

105105
let changed = false;
106106
for (const [key, val] of Object.entries(options)) {
@@ -148,11 +148,11 @@ module.exports.PluginConfig = class PluginConfig {
148148
}
149149

150150
#setupFront() {
151-
const ignoredMethods = ['subscribe', 'subscribeAll'];
151+
const ignoredMethods = ["subscribe", "subscribeAll"];
152152

153-
if (process.type === 'renderer') {
153+
if (process.type === "renderer") {
154154
for (const [fnName, fn] of Object.entries(this)) {
155-
if (typeof fn !== 'function' || fn.name in ignoredMethods) return;
155+
if (typeof fn !== "function" || fn.name in ignoredMethods) return;
156156
this[fnName] = async (...args) => {
157157
return await ipcRenderer.invoke(
158158
`${this.name}-config-${fnName}`,
@@ -181,9 +181,9 @@ module.exports.PluginConfig = class PluginConfig {
181181
ipcRenderer.send(`${this.name}-config-subscribe-all`);
182182
};
183183
}
184-
} else if (process.type === 'browser') {
184+
} else if (process.type === "browser") {
185185
for (const [fnName, fn] of Object.entries(this)) {
186-
if (typeof fn !== 'function' || fn.name in ignoredMethods) return;
186+
if (typeof fn !== "function" || fn.name in ignoredMethods) return;
187187
ipcMain.handle(`${this.name}-config-${fnName}`, (_, ...args) => {
188188
return fn(...args);
189189
});

plugins/crossfade/front.js

Lines changed: 119 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,155 @@
1-
const { ipcRenderer } = require('electron');
2-
const { Howl } = require('howler');
1+
const { ipcRenderer } = require("electron");
2+
const { Howl } = require("howler");
33

44
// Extracted from https://github.com/bitfasching/VolumeFader
5-
require('./fader');
5+
require("./fader");
66

77
let transitionAudio; // Howler audio used to fade out the current music
88
let firstVideo = true;
99
let waitForTransition;
1010

11-
const defaultConfig = require('../../config/defaults').plugins.crossfade;
11+
const defaultConfig = require("../../config/defaults").plugins.crossfade;
1212

13-
const configProvider = require('./config');
14-
let config = configProvider.getAll();
15-
16-
console.log({ config });
17-
18-
configProvider.subscribeAll((newConfig) => {
19-
config = newConfig;
20-
});
13+
const configProvider = require("./config");
14+
let config;
2115

2216
const configGetNum = (key) => Number(config[key]) || defaultConfig[key];
2317

2418
const getStreamURL = async (videoID) => {
25-
const url = await ipcRenderer.invoke('audio-url', videoID);
26-
return url;
19+
const url = await ipcRenderer.invoke("audio-url", videoID);
20+
return url;
2721
};
2822

2923
const getVideoIDFromURL = (url) => {
30-
return new URLSearchParams(url.split('?')?.at(-1)).get('v');
24+
return new URLSearchParams(url.split("?")?.at(-1)).get("v");
3125
};
3226

3327
const isReadyToCrossfade = () => {
34-
return transitionAudio && transitionAudio.state() === 'loaded';
28+
return transitionAudio && transitionAudio.state() === "loaded";
3529
};
3630

3731
const watchVideoIDChanges = (cb) => {
38-
navigation.addEventListener('navigate', (event) => {
39-
const currentVideoID = getVideoIDFromURL(
40-
event.currentTarget.currentEntry.url,
41-
);
42-
const nextVideoID = getVideoIDFromURL(event.destination.url);
43-
44-
if (
45-
nextVideoID &&
46-
currentVideoID &&
47-
(firstVideo || nextVideoID !== currentVideoID)
48-
) {
49-
if (isReadyToCrossfade()) {
50-
crossfade(() => {
51-
cb(nextVideoID);
52-
});
53-
} else {
54-
cb(nextVideoID);
55-
firstVideo = false;
56-
}
57-
}
58-
});
32+
navigation.addEventListener("navigate", (event) => {
33+
const currentVideoID = getVideoIDFromURL(
34+
event.currentTarget.currentEntry.url,
35+
);
36+
const nextVideoID = getVideoIDFromURL(event.destination.url);
37+
38+
if (
39+
nextVideoID &&
40+
currentVideoID &&
41+
(firstVideo || nextVideoID !== currentVideoID)
42+
) {
43+
if (isReadyToCrossfade()) {
44+
crossfade(() => {
45+
cb(nextVideoID);
46+
});
47+
} else {
48+
cb(nextVideoID);
49+
firstVideo = false;
50+
}
51+
}
52+
});
5953
};
6054

6155
const createAudioForCrossfade = async (url) => {
62-
if (transitionAudio) {
63-
transitionAudio.unload();
64-
}
65-
transitionAudio = new Howl({
66-
src: url,
67-
html5: true,
68-
volume: 0,
69-
});
70-
await syncVideoWithTransitionAudio();
56+
if (transitionAudio) {
57+
transitionAudio.unload();
58+
}
59+
transitionAudio = new Howl({
60+
src: url,
61+
html5: true,
62+
volume: 0,
63+
});
64+
await syncVideoWithTransitionAudio();
7165
};
7266

7367
const syncVideoWithTransitionAudio = async () => {
74-
const video = document.querySelector('video');
75-
76-
const videoFader = new VolumeFader(video, {
77-
fadeScaling: configGetNum('fadeScaling'),
78-
fadeDuration: configGetNum('fadeInDuration'),
79-
});
80-
81-
await transitionAudio.play();
82-
await transitionAudio.seek(video.currentTime);
83-
84-
video.onseeking = () => {
85-
transitionAudio.seek(video.currentTime);
86-
};
87-
video.onpause = () => {
88-
transitionAudio.pause();
89-
};
90-
video.onplay = async () => {
91-
await transitionAudio.play();
92-
await transitionAudio.seek(video.currentTime);
93-
94-
// Fade in
95-
const videoVolume = video.volume;
96-
video.volume = 0;
97-
videoFader.fadeTo(videoVolume);
98-
};
99-
100-
// Exit just before the end for the transition
101-
const transitionBeforeEnd = () => {
102-
if (
103-
video.currentTime >=
104-
video.duration - configGetNum('secondsBeforeEnd') &&
105-
isReadyToCrossfade()
106-
) {
107-
video.removeEventListener('timeupdate', transitionBeforeEnd);
108-
109-
// Go to next video - XXX: does not support "repeat 1" mode
110-
document.querySelector('.next-button').click();
111-
}
112-
};
113-
video.ontimeupdate = transitionBeforeEnd;
68+
const video = document.querySelector("video");
69+
70+
const videoFader = new VolumeFader(video, {
71+
fadeScaling: configGetNum("fadeScaling"),
72+
fadeDuration: configGetNum("fadeInDuration"),
73+
});
74+
75+
await transitionAudio.play();
76+
await transitionAudio.seek(video.currentTime);
77+
78+
video.onseeking = () => {
79+
transitionAudio.seek(video.currentTime);
80+
};
81+
video.onpause = () => {
82+
transitionAudio.pause();
83+
};
84+
video.onplay = async () => {
85+
await transitionAudio.play();
86+
await transitionAudio.seek(video.currentTime);
87+
88+
// Fade in
89+
const videoVolume = video.volume;
90+
video.volume = 0;
91+
videoFader.fadeTo(videoVolume);
92+
};
93+
94+
// Exit just before the end for the transition
95+
const transitionBeforeEnd = () => {
96+
if (
97+
video.currentTime >= video.duration - configGetNum("secondsBeforeEnd") &&
98+
isReadyToCrossfade()
99+
) {
100+
video.removeEventListener("timeupdate", transitionBeforeEnd);
101+
102+
// Go to next video - XXX: does not support "repeat 1" mode
103+
document.querySelector(".next-button").click();
104+
}
105+
};
106+
video.ontimeupdate = transitionBeforeEnd;
114107
};
115108

116109
const onApiLoaded = () => {
117-
watchVideoIDChanges(async (videoID) => {
118-
await waitForTransition;
119-
const url = await getStreamURL(videoID);
120-
await createAudioForCrossfade(url);
121-
});
110+
watchVideoIDChanges(async (videoID) => {
111+
await waitForTransition;
112+
const url = await getStreamURL(videoID);
113+
await createAudioForCrossfade(url);
114+
});
122115
};
123116

124117
const crossfade = async (cb) => {
125-
if (!isReadyToCrossfade()) {
126-
cb();
127-
return;
128-
}
129-
130-
let resolveTransition;
131-
waitForTransition = new Promise(function (resolve, reject) {
132-
resolveTransition = resolve;
133-
});
134-
135-
const video = document.querySelector('video');
136-
137-
const fader = new VolumeFader(transitionAudio._sounds[0]._node, {
138-
initialVolume: video.volume,
139-
fadeScaling: configGetNum('fadeScaling'),
140-
fadeDuration: configGetNum('fadeOutDuration'),
141-
});
142-
143-
// Fade out the music
144-
video.volume = 0;
145-
fader.fadeOut(() => {
146-
resolveTransition();
147-
cb();
148-
});
118+
if (!isReadyToCrossfade()) {
119+
cb();
120+
return;
121+
}
122+
123+
let resolveTransition;
124+
waitForTransition = new Promise(function (resolve, reject) {
125+
resolveTransition = resolve;
126+
});
127+
128+
const video = document.querySelector("video");
129+
130+
const fader = new VolumeFader(transitionAudio._sounds[0]._node, {
131+
initialVolume: video.volume,
132+
fadeScaling: configGetNum("fadeScaling"),
133+
fadeDuration: configGetNum("fadeOutDuration"),
134+
});
135+
136+
// Fade out the music
137+
video.volume = 0;
138+
fader.fadeOut(() => {
139+
resolveTransition();
140+
cb();
141+
});
149142
};
150143

151-
module.exports = () => {
152-
document.addEventListener('apiLoaded', onApiLoaded, {
153-
once: true,
154-
passive: true,
155-
});
144+
module.exports = async () => {
145+
config = await configProvider.getAll();
146+
147+
configProvider.subscribeAll((newConfig) => {
148+
config = newConfig;
149+
});
150+
151+
document.addEventListener("apiLoaded", onApiLoaded, {
152+
once: true,
153+
passive: true,
154+
});
156155
};

0 commit comments

Comments
 (0)