fix: load plugins

Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
JellyBrick
2023-11-28 00:34:36 +09:00
parent 2fe28cf126
commit 7a76079ff4
15 changed files with 90 additions and 39 deletions

View File

@ -28,12 +28,11 @@ interface CaptionsSelectorConfig {
lastCaptionsCode: string;
}
const captionsSettingsButton = ElementFromHtml(CaptionsSettingsButtonHTML);
export default createPlugin<
unknown,
unknown,
{
captionsSettingsButton: HTMLElement;
captionTrackList: LanguageOptions[] | null;
api: YoutubePlayer | null;
config: CaptionsSelectorConfig | null;
@ -98,6 +97,7 @@ export default createPlugin<
},
renderer: {
captionsSettingsButton: ElementFromHtml(CaptionsSettingsButtonHTML),
captionTrackList: null,
api: null,
config: null,
@ -133,7 +133,7 @@ export default createPlugin<
captionsButtonClickListener() {
if (this.config!.disableCaptions) {
setTimeout(() => this.api!.unloadModule('captions'), 100);
captionsSettingsButton.style.display = 'none';
this.captionsSettingsButton.style.display = 'none';
return;
}
@ -148,7 +148,7 @@ export default createPlugin<
});
}
captionsSettingsButton.style.display = this.captionTrackList?.length
this.captionsSettingsButton.style.display = this.captionTrackList?.length
? 'inline-block'
: 'none';
}, 250);
@ -158,20 +158,20 @@ export default createPlugin<
this.setConfig = setConfig;
},
stop() {
document.querySelector('.right-controls-buttons')?.removeChild(captionsSettingsButton);
document.querySelector('.right-controls-buttons')?.removeChild(this.captionsSettingsButton);
document.querySelector<YoutubePlayer & HTMLElement>('#movie_player')?.unloadModule('captions');
document.querySelector('video')?.removeEventListener('srcChanged', this.videoChangeListener);
captionsSettingsButton.removeEventListener('click', this.captionsButtonClickListener);
this.captionsSettingsButton.removeEventListener('click', this.captionsButtonClickListener);
},
onPlayerApiReady(playerApi) {
this.api = playerApi;
document.querySelector('.right-controls-buttons')?.append(captionsSettingsButton);
document.querySelector('.right-controls-buttons')?.append(this.captionsSettingsButton);
this.captionTrackList = this.api.getOption<LanguageOptions[]>('captions', 'tracklist') ?? [];
document.querySelector('video')?.addEventListener('srcChanged', this.videoChangeListener);
captionsSettingsButton.addEventListener('click', this.captionsButtonClickListener);
this.captionsSettingsButton.addEventListener('click', this.captionsButtonClickListener);
},
onConfigChange(newConfig) {
this.config = newConfig;

View File

@ -36,7 +36,7 @@ import { cache } from '@/providers/decorators';
import { YoutubeFormatList, type Preset, DefaultPresetList } from '../types';
import { defaultConfig, type DownloaderPluginConfig } from '../index';
import type { DownloaderPluginConfig } from '../index';
import type { BackendContext } from '@/types/contexts';
@ -91,7 +91,7 @@ export const getCookieFromWindow = async (win: BrowserWindow) => {
.join(';');
};
let config: DownloaderPluginConfig = defaultConfig;
let config: DownloaderPluginConfig;
export const onMainLoad = async ({ window: _win, getConfig, ipc }: BackendContext<DownloaderPluginConfig>) => {
win = _win;

View File

@ -5,12 +5,12 @@ import is from 'electron-is';
import { notificationImage } from './utils';
import interactive from './interactive';
import { defaultConfig, type NotificationsPluginConfig } from './index';
import registerCallback, { type SongInfo } from '@/providers/song-info';
import type { NotificationsPluginConfig } from './index';
import type { BackendContext } from '@/types/contexts';
let config: NotificationsPluginConfig = defaultConfig;
let config: NotificationsPluginConfig;
const notify = (info: SongInfo) => {
// Send the notification