MCPcopy Create free account
hub / github.com/corbt/agent.exe / createMainWindow

Function createMainWindow

src/main/window.ts:80–159  ·  view source on GitHub ↗
(
  getAssetPath: (...paths: string[]) => string,
)

Source from the content-addressed store, hash-verified

78}
79
80export async function createMainWindow(
81 getAssetPath: (...paths: string[]) => string,
82): Promise<BrowserWindow> {
83 const primaryDisplay = screen.getPrimaryDisplay();
84 const { width, height } = primaryDisplay.workAreaSize;
85
86 mainWindow = new BrowserWindow({
87 show: false,
88 width: 350,
89 height: 600,
90 x: width - 350,
91 y: 0,
92 frame: false,
93 transparent: true,
94 alwaysOnTop: true,
95 icon: getAssetPath('icon.png'),
96 webPreferences: {
97 preload: app.isPackaged
98 ? path.join(__dirname, 'preload.js')
99 : path.join(__dirname, '../../.erb/dll/preload.js'),
100 },
101 });
102
103 mainWindow.loadURL(resolveHtmlPath('index.html'));
104
105 mainWindow.on('ready-to-show', () => {
106 if (!mainWindow) {
107 throw new Error('"mainWindow" is not defined');
108 }
109 if (process.env.START_MINIMIZED) {
110 mainWindow.minimize();
111 } else {
112 // Use immediate=true for initial show
113 fadeWindow(true, true);
114 }
115 });
116
117 mainWindow.on('closed', () => {
118 if (fadeInterval) {
119 clearInterval(fadeInterval);
120 }
121 if (showTimeout) {
122 clearTimeout(showTimeout);
123 }
124 mainWindow = null;
125 });
126
127 const menuBuilder = new MenuBuilder(mainWindow);
128 menuBuilder.buildMenu();
129
130 mainWindow.webContents.setWindowOpenHandler((edata) => {
131 shell.openExternal(edata.url);
132 return { action: 'deny' };
133 });
134
135 ipcMain.handle('minimize-window', () => {
136 mainWindow?.minimize();
137 });

Callers 1

initializeAppFunction · 0.90

Calls 4

buildMenuMethod · 0.95
resolveHtmlPathFunction · 0.90
getAssetPathFunction · 0.85
fadeWindowFunction · 0.85

Tested by

no test coverage detected