Skip to content

Commit e98140d

Browse files
authored
Merge pull request #495 from MoYingJi/feat-window
feat: 记忆窗口最大化状态
2 parents ac47b38 + 1b6ad16 commit e98140d

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

electron/main/index.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { app, shell, BrowserWindow, BrowserWindowConstructorOptions } from "elec
22
import { electronApp } from "@electron-toolkit/utils";
33
import { join } from "path";
44
import { release, type } from "os";
5-
import { isDev, isMac, appName } from "./utils";
5+
import { isDev, isMac, appName, isLinux } from "./utils";
66
import { unregisterShortcuts } from "./shortcut";
77
import { initTray, MainTray } from "./tray";
88
import { initThumbar, Thumbar } from "./thumbar";
@@ -237,14 +237,16 @@ class MainProcess {
237237
this.mainWindow?.on("ready-to-show", () => {
238238
if (!this.mainWindow) return;
239239
this.thumbar = initThumbar(this.mainWindow);
240+
const isMaximized = this.store?.get("window").maximized;
241+
if (isMaximized) this.mainWindow.maximize();
240242
});
241243
this.mainWindow?.on("show", () => {
242244
// this.mainWindow?.webContents.send("lyricsScroll");
243245
});
244246
this.mainWindow?.on("focus", () => {
245247
this.saveBounds();
246248
});
247-
// 移动或缩放
249+
// 移动、缩放、最大化、取消最大化
248250
this.mainWindow?.on("resized", () => {
249251
// 若处于全屏则不保存
250252
if (this.mainWindow?.isFullScreen()) return;
@@ -253,6 +255,24 @@ class MainProcess {
253255
this.mainWindow?.on("moved", () => {
254256
this.saveBounds();
255257
});
258+
this.mainWindow?.on("maximize", () => {
259+
this.saveBounds();
260+
});
261+
this.mainWindow?.on("unmaximize", () => {
262+
this.saveBounds();
263+
})
264+
265+
// Linux 无法使用 resized 和 moved
266+
if (isLinux) {
267+
this.mainWindow?.on("resize", () => {
268+
// 若处于全屏则不保存
269+
if (this.mainWindow?.isFullScreen()) return;
270+
this.saveBounds();
271+
})
272+
this.mainWindow?.on("move", () => {
273+
this.saveBounds();
274+
});
275+
}
256276

257277
// 歌词窗口缩放
258278
this.lyricWindow?.on("resized", () => {
@@ -276,8 +296,11 @@ class MainProcess {
276296
// 更新窗口大小
277297
saveBounds() {
278298
if (this.mainWindow?.isFullScreen()) return;
279-
const bounds = this.mainWindow?.getBounds();
280-
if (bounds) this.store?.set("window", bounds);
299+
const bounds: any = this.mainWindow?.getBounds();
300+
if (bounds) {
301+
bounds.maximized = this.mainWindow?.isMaximized();
302+
this.store?.set("window", bounds);
303+
}
281304
}
282305
// 显示窗口
283306
showWindow() {

electron/main/store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface StoreType {
1010
height: number;
1111
x?: number;
1212
y?: number;
13+
maximized?: boolean;
1314
};
1415
lyric: {
1516
fontSize: number;

0 commit comments

Comments
 (0)