@@ -2,7 +2,7 @@ import { app, shell, BrowserWindow, BrowserWindowConstructorOptions } from "elec
22import { electronApp } from "@electron-toolkit/utils" ;
33import { join } from "path" ;
44import { release , type } from "os" ;
5- import { isDev , isMac , appName } from "./utils" ;
5+ import { isDev , isMac , appName , isLinux } from "./utils" ;
66import { unregisterShortcuts } from "./shortcut" ;
77import { initTray , MainTray } from "./tray" ;
88import { 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 ( ) {
0 commit comments