Merge pull request #495 from MoYingJi/feat-window

feat: 记忆窗口最大化状态
This commit is contained in:
底层用户
2025-10-18 23:32:11 +08:00
committed by GitHub
2 changed files with 28 additions and 4 deletions

View File

@@ -2,7 +2,7 @@ import { app, shell, BrowserWindow, BrowserWindowConstructorOptions } from "elec
import { electronApp } from "@electron-toolkit/utils";
import { join } from "path";
import { release, type } from "os";
import { isDev, isMac, appName } from "./utils";
import { isDev, isMac, appName, isLinux } from "./utils";
import { unregisterShortcuts } from "./shortcut";
import { initTray, MainTray } from "./tray";
import { initThumbar, Thumbar } from "./thumbar";
@@ -237,6 +237,8 @@ class MainProcess {
this.mainWindow?.on("ready-to-show", () => {
if (!this.mainWindow) return;
this.thumbar = initThumbar(this.mainWindow);
const isMaximized = this.store?.get("window").maximized;
if (isMaximized) this.mainWindow.maximize();
});
this.mainWindow?.on("show", () => {
// this.mainWindow?.webContents.send("lyricsScroll");
@@ -244,7 +246,7 @@ class MainProcess {
this.mainWindow?.on("focus", () => {
this.saveBounds();
});
// 移动缩放
// 移动缩放、最大化、取消最大化
this.mainWindow?.on("resized", () => {
// 若处于全屏则不保存
if (this.mainWindow?.isFullScreen()) return;
@@ -253,6 +255,24 @@ class MainProcess {
this.mainWindow?.on("moved", () => {
this.saveBounds();
});
this.mainWindow?.on("maximize", () => {
this.saveBounds();
});
this.mainWindow?.on("unmaximize", () => {
this.saveBounds();
})
// Linux 无法使用 resized 和 moved
if (isLinux) {
this.mainWindow?.on("resize", () => {
// 若处于全屏则不保存
if (this.mainWindow?.isFullScreen()) return;
this.saveBounds();
})
this.mainWindow?.on("move", () => {
this.saveBounds();
});
}
// 歌词窗口缩放
this.lyricWindow?.on("resized", () => {
@@ -276,8 +296,11 @@ class MainProcess {
// 更新窗口大小
saveBounds() {
if (this.mainWindow?.isFullScreen()) return;
const bounds = this.mainWindow?.getBounds();
if (bounds) this.store?.set("window", bounds);
const bounds: any = this.mainWindow?.getBounds();
if (bounds) {
bounds.maximized = this.mainWindow?.isMaximized();
this.store?.set("window", bounds);
}
}
// 显示窗口
showWindow() {

View File

@@ -10,6 +10,7 @@ export interface StoreType {
height: number;
x?: number;
y?: number;
maximized?: boolean;
};
lyric: {
fontSize: number;