mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-05 07:20:50 +08:00
72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
const { BrowserWindow } = require('electron');
|
|
const path = require('path');
|
|
|
|
let lyricWindow = null;
|
|
|
|
const createWin = () => {
|
|
lyricWindow = new BrowserWindow({
|
|
width: 800,
|
|
height: 300,
|
|
frame: false,
|
|
show: false,
|
|
transparent: true,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
preload: `${__dirname}/preload.js`,
|
|
contextIsolation: false,
|
|
},
|
|
});
|
|
};
|
|
const loadLyricWindow = (ipcMain) => {
|
|
ipcMain.on('open-lyric', () => {
|
|
if (lyricWindow) {
|
|
if (lyricWindow.isMinimized()) lyricWindow.restore();
|
|
lyricWindow.focus();
|
|
lyricWindow.show();
|
|
return;
|
|
}
|
|
createWin();
|
|
if (process.env.NODE_ENV === 'development') {
|
|
lyricWindow.webContents.openDevTools({ mode: 'detach' });
|
|
lyricWindow.loadURL('http://localhost:4678/#/lyric');
|
|
} else {
|
|
const distPath = path.resolve(__dirname, '../dist');
|
|
lyricWindow.loadURL(`file://${distPath}/index.html#/lyric`);
|
|
}
|
|
|
|
lyricWindow.setMinimumSize(600, 200);
|
|
|
|
// 隐藏任务栏
|
|
lyricWindow.setSkipTaskbar(true);
|
|
|
|
lyricWindow.show();
|
|
});
|
|
|
|
ipcMain.on('send-lyric', (e, data) => {
|
|
if (lyricWindow) {
|
|
lyricWindow.webContents.send('receive-lyric', data);
|
|
}
|
|
});
|
|
|
|
ipcMain.on('top-lyric', (e, data) => {
|
|
lyricWindow.setAlwaysOnTop(data);
|
|
});
|
|
|
|
ipcMain.on('close-lyric', () => {
|
|
lyricWindow.close();
|
|
lyricWindow = null;
|
|
});
|
|
|
|
ipcMain.on('mouseenter-lyric', () => {
|
|
lyricWindow.setIgnoreMouseEvents(true);
|
|
});
|
|
|
|
ipcMain.on('mouseleave-lyric', () => {
|
|
lyricWindow.setIgnoreMouseEvents(false);
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
loadLyricWindow,
|
|
};
|