mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 03:11:46 +00:00
feat: migrate to new plugin api
Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
17
src/plugins/tuna-obs/index.ts
Normal file
17
src/plugins/tuna-obs/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { createPluginBuilder } from '../utils/builder';
|
||||
|
||||
const builder = createPluginBuilder('tuna-obs', {
|
||||
name: 'Tuna OBS',
|
||||
restartNeeded: true,
|
||||
config: {
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default builder;
|
||||
|
||||
declare global {
|
||||
interface PluginBuilderList {
|
||||
[builder.id]: typeof builder;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
import { ipcMain, net, BrowserWindow } from 'electron';
|
||||
import { net } from 'electron';
|
||||
import is from 'electron-is';
|
||||
|
||||
import builder from './index';
|
||||
|
||||
import registerCallback from '../../providers/song-info';
|
||||
|
||||
const secToMilisec = (t: number) => Math.round(Number(t) * 1e3);
|
||||
@ -49,31 +51,35 @@ const post = (data: Data) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default (win: BrowserWindow) => {
|
||||
ipcMain.on('apiLoaded', () => win.webContents.send('setupTimeChangedListener'));
|
||||
ipcMain.on('timeChanged', (_, t: number) => {
|
||||
if (!data.title) {
|
||||
return;
|
||||
export default builder.createMain(({ send, handle, on }) => {
|
||||
return {
|
||||
onLoad() {
|
||||
on('apiLoaded', () => send('setupTimeChangedListener'));
|
||||
on('timeChanged', (t: number) => {
|
||||
if (!data.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.progress = secToMilisec(t);
|
||||
post(data);
|
||||
});
|
||||
|
||||
registerCallback((songInfo) => {
|
||||
if (!songInfo.title && !songInfo.artist) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.duration = secToMilisec(songInfo.songDuration);
|
||||
data.progress = secToMilisec(songInfo.elapsedSeconds ?? 0);
|
||||
data.cover = songInfo.imageSrc ?? '';
|
||||
data.cover_url = songInfo.imageSrc ?? '';
|
||||
data.album_url = songInfo.imageSrc ?? '';
|
||||
data.title = songInfo.title;
|
||||
data.artists = [songInfo.artist];
|
||||
data.status = songInfo.isPaused ? 'stopped' : 'playing';
|
||||
data.album = songInfo.album;
|
||||
post(data);
|
||||
});
|
||||
}
|
||||
|
||||
data.progress = secToMilisec(t);
|
||||
post(data);
|
||||
});
|
||||
|
||||
registerCallback((songInfo) => {
|
||||
if (!songInfo.title && !songInfo.artist) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.duration = secToMilisec(songInfo.songDuration);
|
||||
data.progress = secToMilisec(songInfo.elapsedSeconds ?? 0);
|
||||
data.cover = songInfo.imageSrc ?? '';
|
||||
data.cover_url = songInfo.imageSrc ?? '';
|
||||
data.album_url = songInfo.imageSrc ?? '';
|
||||
data.title = songInfo.title;
|
||||
data.artists = [songInfo.artist];
|
||||
data.status = songInfo.isPaused ? 'stopped' : 'playing';
|
||||
data.album = songInfo.album;
|
||||
post(data);
|
||||
});
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user