()
| 38 | // electronDragClick() |
| 39 | |
| 40 | export function createWindow() { |
| 41 | if (!isAppSetup) { |
| 42 | log.warn('App is not setup, not allowed to create main window') |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | const winState = new WindowState( |
| 47 | { |
| 48 | saveImmediately: is.dev |
| 49 | }, |
| 50 | { |
| 51 | isMaximized: true |
| 52 | } |
| 53 | ) |
| 54 | |
| 55 | const currentDisplay = |
| 56 | winState.state.x && winState.state.y |
| 57 | ? screen.getDisplayMatching({ |
| 58 | x: winState.state.x, |
| 59 | y: winState.state.y, |
| 60 | width: winState.state.width, |
| 61 | height: winState.state.height |
| 62 | }) |
| 63 | : screen.getPrimaryDisplay() |
| 64 | const screenBounds = currentDisplay.bounds |
| 65 | |
| 66 | const clamp = (value: number, min: number, max: number) => { |
| 67 | return Math.min(Math.max(value, min), max) |
| 68 | } |
| 69 | |
| 70 | const windowBounds = { |
| 71 | x: winState.state.x ?? 0, |
| 72 | y: winState.state.y ?? 0, |
| 73 | width: winState.state.width ?? screenBounds.width, |
| 74 | height: winState.state.height ?? screenBounds.height |
| 75 | } |
| 76 | |
| 77 | const boundWindow = { |
| 78 | x: clamp( |
| 79 | windowBounds.x, |
| 80 | screenBounds.x, |
| 81 | screenBounds.x + screenBounds.width - windowBounds.width |
| 82 | ), |
| 83 | y: clamp( |
| 84 | windowBounds.y, |
| 85 | screenBounds.y, |
| 86 | screenBounds.y + screenBounds.height - windowBounds.height |
| 87 | ), |
| 88 | width: Math.min(windowBounds.width, screenBounds.width), |
| 89 | height: Math.min(windowBounds.height, screenBounds.height) |
| 90 | } |
| 91 | |
| 92 | const mainWindowSession = session.fromPartition('persist:surf-app-session') |
| 93 | mainWindow = new BrowserWindow({ |
| 94 | width: boundWindow.width, |
| 95 | height: boundWindow.height, |
| 96 | minWidth: 542, |
| 97 | minHeight: 330, |
no test coverage detected