MCPcopy
hub / github.com/vercel/hyper / createWindow

Function createWindow

app/index.ts:91–148  ·  view source on GitHub ↗
(
        fn?: (win: BrowserWindow) => void,
        options: {size?: [number, number]; position?: [number, number]} = {}
      )

Source from the content-addressed store, hash-verified

89 installDevExtensions(isDev)
90 .then(() => {
91 function createWindow(
92 fn?: (win: BrowserWindow) => void,
93 options: {size?: [number, number]; position?: [number, number]} = {}
94 ) {
95 const cfg = plugins.getDecoratedConfig();
96
97 const winSet = config.getWin();
98 let [startX, startY] = winSet.position;
99
100 const [width, height] = options.size ? options.size : cfg.windowSize || winSet.size;
101
102 const winPos = options.position;
103
104 // Open the new window roughly the height of the header away from the
105 // previous window. This also ensures in multi monitor setups that the
106 // new terminal is on the correct screen.
107 const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();
108 // In case of options defaults position and size, we should ignore the focusedWindow.
109 if (winPos !== undefined) {
110 [startX, startY] = winPos;
111 } else if (focusedWindow) {
112 const points = focusedWindow.getPosition();
113 const currentScreen = screen.getDisplayNearestPoint({
114 x: points[0],
115 y: points[1]
116 });
117
118 const biggestX = points[0] + 100 + width - currentScreen.bounds.x;
119 const biggestY = points[1] + 100 + height - currentScreen.bounds.y;
120
121 if (biggestX > currentScreen.size.width) {
122 startX = 50;
123 } else {
124 startX = points[0] + 34;
125 }
126 if (biggestY > currentScreen.size.height) {
127 startY = 50;
128 } else {
129 startY = points[1] + 34;
130 }
131 }
132
133 if (!windowUtils.positionIsValid([startX, startY])) {
134 [startX, startY] = config.windowDefaults.windowPosition;
135 }
136
137 const hwin = newWindow({width, height, x: startX, y: startY}, cfg, fn);
138 windowSet.add(hwin);
139 void hwin.loadURL(url);
140
141 // the window can be closed by the browser process itself
142 hwin.on('close', () => {
143 hwin.clean();
144 windowSet.delete(hwin);
145 });
146
147 return hwin;
148 }

Callers 2

index.tsFile · 0.85
clickFunction · 0.85

Calls 4

newWindowFunction · 0.90
onMethod · 0.80
addMethod · 0.45
cleanMethod · 0.45

Tested by

no test coverage detected