feat: bootstrap secure cross-platform assistant

Establish the Electron foundation and pluggable agent runtime so desktop workflows can evolve safely across supported platforms.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
lofyer
2026-07-29 22:42:30 +08:00
co-authored by factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
commit 1b6178b841
30 changed files with 12017 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
import { BrowserWindow, shell } from 'electron'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const currentDirectory = dirname(fileURLToPath(import.meta.url))
function isAllowedExternalUrl(url: string): boolean {
try {
return new URL(url).protocol === 'https:'
} catch {
return false
}
}
export function createMainWindow(shouldQuit: () => boolean): BrowserWindow {
const window = new BrowserWindow({
width: 1180,
height: 760,
minWidth: 920,
minHeight: 620,
show: false,
backgroundColor: '#f4f1ea',
titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : 'default',
webPreferences: {
preload: join(currentDirectory, '../preload/index.cjs'),
contextIsolation: true,
nodeIntegration: false,
sandbox: true
}
})
window.once('ready-to-show', () => {
window.show()
})
window.on('close', (event) => {
if (!shouldQuit()) {
event.preventDefault()
window.hide()
}
})
window.webContents.setWindowOpenHandler(({ url }) => {
if (isAllowedExternalUrl(url)) {
void shell.openExternal(url)
}
return { action: 'deny' }
})
window.webContents.on('will-navigate', (event, url) => {
const developmentUrl = process.env.ELECTRON_RENDERER_URL
if (!developmentUrl || !url.startsWith(developmentUrl)) {
event.preventDefault()
}
})
if (process.env.ELECTRON_RENDERER_URL) {
void window.loadURL(process.env.ELECTRON_RENDERER_URL)
} else {
void window.loadFile(join(currentDirectory, '../renderer/index.html'))
}
return window
}
export function showWindow(window: BrowserWindow): void {
if (window.isMinimized()) {
window.restore()
}
window.show()
window.focus()
}
export function toggleWindow(window: BrowserWindow): void {
if (window.isVisible() && window.isFocused()) {
window.hide()
return
}
showWindow(window)
}