mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-24 16:27:23 +08:00
启动默认显示缩略图控制按钮。
(cherry picked from commit 1f438e391ab7bb37e38a31ec571724d33f35310b)
This commit is contained in:
+41
-16
@@ -20,7 +20,7 @@ const store = new Store();
|
|||||||
|
|
||||||
// 保存主窗口引用,以便在 activate 事件中使用
|
// 保存主窗口引用,以便在 activate 事件中使用
|
||||||
let mainWindowInstance: BrowserWindow | null = null;
|
let mainWindowInstance: BrowserWindow | null = null;
|
||||||
|
let isPlaying = false;
|
||||||
// 保存迷你模式前的窗口状态
|
// 保存迷你模式前的窗口状态
|
||||||
let preMiniModeState: WindowState = {
|
let preMiniModeState: WindowState = {
|
||||||
width: DEFAULT_MAIN_WIDTH,
|
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监听
|
* 初始化窗口管理相关的IPC监听
|
||||||
*/
|
*/
|
||||||
@@ -179,7 +211,7 @@ export function initializeWindowManager() {
|
|||||||
// 再次验证窗口大小
|
// 再次验证窗口大小
|
||||||
const [width, height] = win.getSize();
|
const [width, height] = win.getSize();
|
||||||
if (Math.abs(width - preMiniModeState.width) > 2 ||
|
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}`);
|
console.log(`恢复后窗口大小不一致,再次调整: 当前=${width}x${height}, 目标=${preMiniModeState.width}x${preMiniModeState.height}`);
|
||||||
win.setSize(preMiniModeState.width, preMiniModeState.height, false);
|
win.setSize(preMiniModeState.width, preMiniModeState.height, false);
|
||||||
}
|
}
|
||||||
@@ -191,19 +223,9 @@ export function initializeWindowManager() {
|
|||||||
|
|
||||||
|
|
||||||
ipcMain.on('update-play-state', (_, playing: boolean) => {
|
ipcMain.on('update-play-state', (_, playing: boolean) => {
|
||||||
let isPlaying = playing;
|
isPlaying = playing;
|
||||||
if (mainWindowInstance) {
|
if (mainWindowInstance) {
|
||||||
let mainWindow = mainWindowInstance;
|
setThumbarButtons(mainWindowInstance);
|
||||||
mainWindow.setThumbarButtons([
|
|
||||||
{
|
|
||||||
tooltip: isPlaying ? 'pause' : 'play',
|
|
||||||
icon: nativeImage
|
|
||||||
.createFromPath(join(app.getAppPath(), 'resources/icons', isPlaying ? 'pause.png' : 'play.png')),
|
|
||||||
click() {
|
|
||||||
mainWindow.webContents.send('global-shortcut', 'togglePlay');
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -268,6 +290,10 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
|
|||||||
preMiniModeState = { ...savedState };
|
preMiniModeState = { ...savedState };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainWindow.on('show', () => {
|
||||||
|
setThumbarButtons(mainWindow);
|
||||||
|
});
|
||||||
|
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
const [width, height] = mainWindow.getSize();
|
const [width, height] = mainWindow.getSize();
|
||||||
console.log(`窗口显示前的大小: ${width}x${height}`);
|
console.log(`窗口显示前的大小: ${width}x${height}`);
|
||||||
@@ -279,7 +305,6 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
|
|||||||
|
|
||||||
// 显示窗口
|
// 显示窗口
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
|
|
||||||
// 应用页面内容缩放
|
// 应用页面内容缩放
|
||||||
applyContentZoom(mainWindow);
|
applyContentZoom(mainWindow);
|
||||||
|
|
||||||
@@ -289,7 +314,7 @@ export function createMainWindow(icon: Electron.NativeImage): BrowserWindow {
|
|||||||
const [currentWidth, currentHeight] = mainWindow.getSize();
|
const [currentWidth, currentHeight] = mainWindow.getSize();
|
||||||
if (savedState && !savedState.isMaximized) {
|
if (savedState && !savedState.isMaximized) {
|
||||||
if (Math.abs(currentWidth - savedState.width) > 2 ||
|
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}`);
|
console.log(`窗口大小不匹配,再次调整: 当前=${currentWidth}x${currentHeight}, 目标=${savedState.width}x${savedState.height}`);
|
||||||
mainWindow.setSize(savedState.width, savedState.height, false);
|
mainWindow.setSize(savedState.width, savedState.height, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user