MCPcopy Create free account
hub / github.com/deta/surf / createWindow

Function createWindow

app/src/main/mainWindow.ts:40–391  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38// electronDragClick()
39
40export 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,

Callers 3

handleOpenUrlFunction · 0.90
initializeAppFunction · 0.90
setupApplicationFunction · 0.90

Calls 15

manageMethod · 0.95
isMacFunction · 0.90
getWebRequestManagerFunction · 0.90
checkSurfProtocolRequestFunction · 0.90
parseURLFunction · 0.90
applyCSPToSessionFunction · 0.90
setupPermissionHandlersFunction · 0.90
initAdblockerFunction · 0.90
initDownloadManagerFunction · 0.90
attachWCViewManagerFunction · 0.90
getHeaderValueFunction · 0.85

Tested by

no test coverage detected