mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 12:42:06 +00:00
feat: Album Color Theme plugin
Co-authored-by: EdiBOI25 <86252338+EdiBOI25@users.noreply.github.com>
This commit is contained in:
39
plugins/album-color-theme/back.ts
Normal file
39
plugins/album-color-theme/back.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { getAverageColor } from 'fast-average-color-node';
|
||||
import { BrowserWindow } from 'electron';
|
||||
|
||||
import { injectCSS } from '../utils';
|
||||
import registerCallback from '../../providers/song-info';
|
||||
|
||||
|
||||
export default (win: BrowserWindow) => {
|
||||
injectCSS(win.webContents, path.join(__dirname, 'style.css'));
|
||||
|
||||
registerCallback((songInfo) => {
|
||||
const songTitle = songInfo.title;
|
||||
const songImage = songInfo.imageSrc;
|
||||
|
||||
if (songImage && songTitle) {
|
||||
getAverageColor(songImage)
|
||||
.then((color) => {
|
||||
//div.style.backgroundColor = color.rgba;
|
||||
//console.log('Average color', color);
|
||||
if (color.hex === '#000000') {
|
||||
color.rgb = 'rgb(238,238,238)';
|
||||
color.isDark = false;
|
||||
color.isLight = true;
|
||||
} else if (color.hex === '#ffffff') {
|
||||
color.rgb = 'rgb(0,0,0)';
|
||||
color.isDark = true;
|
||||
color.isLight = false;
|
||||
}
|
||||
win.webContents.send('album-color-changed', color);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user