2025-10-25 23:43:54 +08:00
|
|
|
import { BrowserWindow } from "electron";
|
|
|
|
|
import { createWindow } from "./index";
|
|
|
|
|
import { useStore } from "../store";
|
2025-11-03 23:25:22 +08:00
|
|
|
import { lyricWinUrl } from "../utils/config";
|
2025-11-06 01:07:04 +08:00
|
|
|
import mainWindow from "./main-window";
|
2025-10-25 23:43:54 +08:00
|
|
|
|
|
|
|
|
class LyricWindow {
|
|
|
|
|
private win: BrowserWindow | null = null;
|
|
|
|
|
constructor() {}
|
|
|
|
|
/**
|
|
|
|
|
* 主窗口事件
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
private event(): void {
|
|
|
|
|
if (!this.win) return;
|
2025-11-03 23:25:22 +08:00
|
|
|
// 准备好显示
|
|
|
|
|
this.win.on("ready-to-show", () => {
|
|
|
|
|
this.win?.show();
|
|
|
|
|
});
|
2025-10-25 23:43:54 +08:00
|
|
|
// 歌词窗口缩放
|
|
|
|
|
this.win?.on("resized", () => {
|
|
|
|
|
const store = useStore();
|
|
|
|
|
const bounds = this.win?.getBounds();
|
|
|
|
|
if (bounds) {
|
|
|
|
|
const { width, height } = bounds;
|
|
|
|
|
store.set("lyric", { ...store.get("lyric"), width, height });
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-11-06 01:07:04 +08:00
|
|
|
// 歌词窗口关闭
|
|
|
|
|
this.win?.on("close", () => {
|
|
|
|
|
const mainWin = mainWindow?.getWin();
|
|
|
|
|
mainWin?.webContents.send("closeDesktopLyric");
|
|
|
|
|
});
|
2025-10-25 23:43:54 +08:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 创建主窗口
|
|
|
|
|
* @returns BrowserWindow | null
|
|
|
|
|
*/
|
|
|
|
|
create(): BrowserWindow | null {
|
|
|
|
|
const store = useStore();
|
|
|
|
|
const { width, height, x, y } = store.get("lyric");
|
|
|
|
|
this.win = createWindow({
|
|
|
|
|
width: width || 800,
|
|
|
|
|
height: height || 180,
|
|
|
|
|
minWidth: 440,
|
2025-11-06 15:04:40 +08:00
|
|
|
minHeight: 140,
|
|
|
|
|
maxWidth: 1600,
|
|
|
|
|
maxHeight: 360,
|
|
|
|
|
// 没有指定位置时居中显示
|
|
|
|
|
center: !(x && y),
|
2025-10-25 23:43:54 +08:00
|
|
|
// 窗口位置
|
|
|
|
|
x,
|
|
|
|
|
y,
|
2025-11-06 15:04:40 +08:00
|
|
|
transparent: true,
|
|
|
|
|
backgroundColor: "rgba(0, 0, 0, 0)",
|
2025-10-25 23:43:54 +08:00
|
|
|
alwaysOnTop: true,
|
|
|
|
|
resizable: true,
|
|
|
|
|
movable: true,
|
|
|
|
|
show: false,
|
|
|
|
|
// 不在任务栏显示
|
2025-11-05 18:21:17 +08:00
|
|
|
// skipTaskbar: true,
|
2025-11-06 15:04:40 +08:00
|
|
|
// 窗口不能最小化
|
|
|
|
|
minimizable: false,
|
|
|
|
|
// 窗口不能最大化
|
|
|
|
|
maximizable: false,
|
|
|
|
|
// 窗口不能进入全屏状态
|
|
|
|
|
fullscreenable: false,
|
2025-10-25 23:43:54 +08:00
|
|
|
});
|
|
|
|
|
if (!this.win) return null;
|
|
|
|
|
// 加载地址
|
2025-11-03 23:25:22 +08:00
|
|
|
this.win.loadURL(lyricWinUrl);
|
2025-10-25 23:43:54 +08:00
|
|
|
// 窗口事件
|
|
|
|
|
this.event();
|
|
|
|
|
return this.win;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取窗口
|
|
|
|
|
* @returns BrowserWindow | null
|
|
|
|
|
*/
|
|
|
|
|
getWin(): BrowserWindow | null {
|
|
|
|
|
return this.win;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new LyricWindow();
|