1
1
import contextMenu from 'electron-context-menu'
2
- import { BrowserWindow } from 'electron'
2
+ import { BrowserWindow , Rectangle } from 'electron'
3
3
import { v4 as uuidv4 } from 'uuid'
4
4
5
5
import { IParsedDeepLink } from 'desktopSrc/lib/app/deep-link.handlers'
6
6
import { configMain as config } from 'desktopSrc/config'
7
- import { updateTray } from 'desktopSrc/lib'
8
- import { resolveHtmlPath } from 'desktopSrc/utils'
7
+ import { electronStore , updateTray } from 'desktopSrc/lib'
8
+ import { resolveHtmlPath , getFittedBounds } from 'desktopSrc/utils'
9
+ import { ElectronStorageItem } from 'uiSrc/electron/constants'
9
10
import { initWindowHandlers } from './window.handlers'
10
11
11
12
export const windows = new Map < string , BrowserWindow > ( )
@@ -14,6 +15,7 @@ export const focusWindow = (win: BrowserWindow) => {
14
15
if ( win . isMinimized ( ) ) win . restore ( )
15
16
win . focus ( )
16
17
}
18
+ export const NEW_WINDOW_OFFSET = 24
17
19
18
20
export enum WindowType {
19
21
Splash = 'splash' ,
@@ -37,17 +39,26 @@ export const createWindow = async ({
37
39
} : ICreateWindow ) => {
38
40
let x
39
41
let y
42
+ let { width, height } = options
43
+
40
44
const currentWindow = BrowserWindow . getFocusedWindow ( )
45
+ const isNewMainWindow = currentWindow && currentWindow ?. getTitle ( ) !== config . splashWindow . title
41
46
42
- if ( currentWindow && currentWindow ?. getTitle ( ) !== config . splashWindow . title ) {
47
+ if ( isNewMainWindow ) {
43
48
const [ currentWindowX , currentWindowY ] = currentWindow . getPosition ( )
44
- x = currentWindowX + 24
45
- y = currentWindowY + 24
49
+ const [ currentWindowWidth , currentWindowHeight ] = currentWindow ?. getSize ( )
50
+ x = currentWindowX + NEW_WINDOW_OFFSET
51
+ y = currentWindowY + NEW_WINDOW_OFFSET
52
+ width = currentWindowWidth
53
+ height = currentWindowHeight
46
54
}
55
+
47
56
const newWindow : BrowserWindow | null = new BrowserWindow ( {
48
57
...options ,
49
58
x,
50
59
y,
60
+ width,
61
+ height,
51
62
webPreferences : {
52
63
...options . webPreferences ,
53
64
preload : options . preloadPath
@@ -59,6 +70,14 @@ export const createWindow = async ({
59
70
return newWindow
60
71
}
61
72
73
+ const savedBounds = electronStore ?. get ( ElectronStorageItem . bounds )
74
+ if ( ! isNewMainWindow && savedBounds ) {
75
+ const bounds = getFittedBounds ( savedBounds as Rectangle )
76
+ if ( bounds ) {
77
+ newWindow . setBounds ( bounds )
78
+ }
79
+ }
80
+
62
81
newWindow . loadURL ( resolveHtmlPath ( htmlFileName , options ?. parsedDeepLink ) )
63
82
64
83
initWindowHandlers ( newWindow , prevWindow , windows , id )
0 commit comments