mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-18 19:47:29 +08:00
@@ -1,5 +1,5 @@
|
||||
import { is } from '@electron-toolkit/utils';
|
||||
import { app, BrowserWindow, globalShortcut, ipcMain, screen, session, shell } from 'electron';
|
||||
import { app, BrowserWindow, nativeImage, globalShortcut, ipcMain, screen, session, shell } from 'electron';
|
||||
import Store from 'electron-store';
|
||||
import { join } from 'path';
|
||||
import {
|
||||
@@ -20,7 +20,7 @@ const store = new Store();
|
||||
|
||||
// 保存主窗口引用,以便在 activate 事件中使用
|
||||
let mainWindowInstance: BrowserWindow | null = null;
|
||||
|
||||
let isPlaying = false;
|
||||
// 保存迷你模式前的窗口状态
|
||||
let preMiniModeState: WindowState = {
|
||||
width: DEFAULT_MAIN_WIDTH,
|
||||
@@ -56,6 +56,38 @@ function initializeProxy() {
|
||||
}
|
||||
}
|
||||
|
||||
function setThumbarButtons(window: BrowserWindow) {
|
||||
window.setThumbarButtons([
|
||||
{
|
||||
tooltip: 'prev',
|
||||
icon: nativeImage
|
||||
.createFromPath(join(app.getAppPath(), 'resources/icons', 'prev.png')),
|
||||
click() {
|
||||
window.webContents.send('global-shortcut', 'prevPlay');
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
tooltip: isPlaying ? 'pause' : 'play',
|
||||
icon: nativeImage
|
||||
.createFromPath(join(app.getAppPath(), 'resources/icons', isPlaying ? 'pause.png' : 'play.png')),
|
||||
click() {
|
||||
window.webContents.send('global-shortcut', 'togglePlay');
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
tooltip: 'next',
|
||||
icon: nativeImage
|
||||
.createFromPath(join(app.getAppPath(), 'resources/icons', 'next.png')),
|
||||
click() {
|
||||
window.webContents.send('global-shortcut', 'nextPlay');
|
||||
},
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化窗口管理相关的IPC监听
|
||||
*/
|
||||
@@ -179,7 +211,7 @@ export function initializeWindowManager() {
|
||||
// 再次验证窗口大小
|
||||
const [width, height] = win.getSize();
|
||||
if (Math.abs(width - preMiniModeState.width) > 2 ||
|
||||
Math.abs(height - preMiniModeState.height) > 2) {
|
||||
Math.abs(height - preMiniModeState.height) > 2) {
|
||||
console.log(`恢复后窗口大小不一致,再次调整: 当前=${width}x${height}, 目标=${preMiniModeState.width}x${preMiniModeState.height}`);
|
||||
win.setSize(preMiniModeState.width, preMiniModeState.height, false);
|
||||
}
|
||||
@@ -189,6 +221,14 @@ export function initializeWindowManager() {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ipcMain.on('update-play-state', (_, playing: boolean) => {
|
||||
isPlaying = playing;
|
||||
if (mainWindowInstance) {
|
||||
setThumbarButtons(mainWindowInstance);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听代理设置变化
|
||||
store.onDidChange('set.proxyConfig', () => {
|
||||
initializeProxy();
|
||||
@@ -250,6 +290,10 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
|
||||
preMiniModeState = { ...savedState };
|
||||
}
|
||||
|
||||
mainWindow.on('show', () => {
|
||||
setThumbarButtons(mainWindow);
|
||||
});
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
const [width, height] = mainWindow.getSize();
|
||||
console.log(`窗口显示前的大小: ${width}x${height}`);
|
||||
@@ -261,7 +305,6 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
|
||||
|
||||
// 显示窗口
|
||||
mainWindow.show();
|
||||
|
||||
// 应用页面内容缩放
|
||||
applyContentZoom(mainWindow);
|
||||
|
||||
@@ -271,7 +314,7 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
|
||||
const [currentWidth, currentHeight] = mainWindow.getSize();
|
||||
if (savedState && !savedState.isMaximized) {
|
||||
if (Math.abs(currentWidth - savedState.width) > 2 ||
|
||||
Math.abs(currentHeight - savedState.height) > 2) {
|
||||
Math.abs(currentHeight - savedState.height) > 2) {
|
||||
console.log(`窗口大小不匹配,再次调整: 当前=${currentWidth}x${currentHeight}, 目标=${savedState.width}x${savedState.height}`);
|
||||
mainWindow.setSize(savedState.width, savedState.height, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user