Sets up a transparent, always-on-top, frameless Electron window hosting a Three.js scene that loads assets/avatar.vrm via @pixiv/three-vrm and plays the bundled .vrma clips through @pixiv/three-vrm-animation. Fixes the default CSP (which blocked texture-loading blob: fetches) and frames the camera on the model automatically. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
|
import { join } from 'path'
|
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
|
|
|
let mainWindow: BrowserWindow | null = null
|
|
|
|
function createWindow(): void {
|
|
mainWindow = new BrowserWindow({
|
|
width: 420,
|
|
height: 720,
|
|
show: false,
|
|
frame: false,
|
|
transparent: true,
|
|
backgroundColor: '#00000000',
|
|
hasShadow: false,
|
|
alwaysOnTop: true,
|
|
resizable: false,
|
|
skipTaskbar: true,
|
|
webPreferences: {
|
|
preload: join(__dirname, '../preload/index.js'),
|
|
sandbox: false
|
|
}
|
|
})
|
|
|
|
mainWindow.setAlwaysOnTop(true, 'screen-saver')
|
|
mainWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
|
|
|
|
mainWindow.on('ready-to-show', () => {
|
|
mainWindow?.show()
|
|
})
|
|
|
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
|
shell.openExternal(details.url)
|
|
return { action: 'deny' }
|
|
})
|
|
|
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
|
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
|
} else {
|
|
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
|
}
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
electronApp.setAppUserModelId('com.forgeavatar.app')
|
|
|
|
if (!is.dev) {
|
|
app.setLoginItemSettings({ openAtLogin: true })
|
|
}
|
|
|
|
app.on('browser-window-created', (_, window) => {
|
|
optimizer.watchWindowShortcuts(window)
|
|
})
|
|
|
|
ipcMain.on(
|
|
'set-ignore-mouse-events',
|
|
(_event, ignore: boolean, options?: { forward: boolean }) => {
|
|
mainWindow?.setIgnoreMouseEvents(ignore, options)
|
|
}
|
|
)
|
|
|
|
createWindow()
|
|
|
|
app.on('activate', function () {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit()
|
|
}
|
|
})
|