Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
feat(disable-autoplay): add apply once, resolve #9
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick committed Oct 2, 2023
1 parent 61b04e9 commit 042083b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ const defaultConfig = {
'lyric-genius': {
romanizedLyrics: false,
},
'disable-autoplay': {
applyOnce: false,
},
'discord': {
enabled: false,
autoReconnect: true, // If enabled, will try to reconnect to discord every 5 seconds after disconnecting or failing to connect
Expand Down
17 changes: 11 additions & 6 deletions plugins/disable-autoplay/front.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
export default () => {
import type { ConfigType } from '../../config/dynamic';

export default (options: ConfigType<'disable-autoplay'>) => {
const timeUpdateListener = (e: Event) => {
if (e.target instanceof HTMLVideoElement) {
e.target.pause();
}
};

document.addEventListener('apiLoaded', (apiEvent) => {
apiEvent.detail.addEventListener('videodatachange', (name: string) => {
const eventListener = (name: string) => {
if (options.applyOnce) {
apiEvent.detail.removeEventListener('videodatachange', eventListener);
}

if (name === 'dataloaded') {
apiEvent.detail.pauseVideo();
document.querySelector<HTMLVideoElement>('video')?.addEventListener('timeupdate', timeUpdateListener);
} else {
document.querySelector<HTMLVideoElement>('video')?.removeEventListener('timeupdate', timeUpdateListener);
document.querySelector<HTMLVideoElement>('video')?.addEventListener('timeupdate', timeUpdateListener, { once: true });
}
});
};
apiEvent.detail.addEventListener('videodatachange', eventListener);
}, { once: true, passive: true });
};
20 changes: 20 additions & 0 deletions plugins/disable-autoplay/menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BrowserWindow } from 'electron';

import { setMenuOptions } from '../../config/plugins';

import { MenuTemplate } from '../../menu';

import type { ConfigType } from '../../config/dynamic';

export default (_: BrowserWindow, options: ConfigType<'disable-autoplay'>): MenuTemplate => [
{
label: 'Applies only on startup',
type: 'checkbox',
checked: options.applyOnce,
click() {
setMenuOptions('disable-autoplay', {
applyOnce: !options.applyOnce,
});
}
}
];

0 comments on commit 042083b

Please sign in to comment.