import * as path from 'path' ; import { effect , stop , unref } from '@vue/reactivity' ; import { app , BrowserWindow , ipcMain } from 'electron' ; import { globalHandler } from '../utils/handler' ; import { loadCustomCSS } from './addon' ; import { hasWindow , getLastWindow } from './frame' ; import { createTouchBar , createWindowMenu } from './menu' ; import { handleEvents } from './message' ; import { useThemeOptions } from './theme' ; function createWindow ( ... args ) { const options = { show : false , title : app . name , width : ( 8 * 80 ) + ( 2 * 8 ) + 180 , minWidth : ( 8 * 40 ) + ( 2 * 8 ) + 180 , height : ( 17 * 25 ) + ( 2 * 4 ) + 36 , titleBarStyle : process . platform === 'darwin' ? 'hiddenInset' as const : 'hidden' as const , transparent : process . platform !== 'win32' , acceptFirstMouse : true , webPreferences : { nodeIntegration : true , contextIsolation : false , additionalArguments : [ '--' , ... args . filter ( arg => ( arg as string | undefined ) !== undefined ) , ] , } , } ; if ( hasWindow ( ) ) { const rect = getLastWindow ( ) . getBounds ( ) ; Object . assign ( options , { x : rect . x + 30 , y : rect . y + 30 , } ) ; } const frame = new BrowserWindow ( options ) ; frame . loadFile ( path . resolve ( __dirname , '../../renderer/dist/index.html' ) ) ; if ( process . platform === 'darwin' ) { /**  https frame . webContents . once ( 'dom-ready' , ( ) => { frame . show ( ) ; } ) ; } else { frame . once ( 'ready-to-show' , ( ) => { frame . show ( ) ; } ) ; } loadCustomCSS ( frame ) ; handleEvents ( frame ) ; const themeOptionsRef = useThemeOptions ( ) ; const reactiveEffect = effect ( ( ) => { const themeOptions = unref ( themeOptionsRef ) ; if ( process . platform === 'darwin' ) { createTouchBar ( frame ) ; } else { createWindowMenu ( frame ) ; } frame . setBackgroundColor ( themeOptions . backgroundColor ) ; frame . setVibrancy ( themeOptions . vibrancy ?? null ) ; } ) ; frame . on ( 'closed' , ( ) => { stop ( reactiveEffect ) ; } ) ; return frame ; } function handleWindowMessages ( ) { ipcMain . handle ( 'open-window' , ( ) => { createWindow ( ) ; } ) ; globalHandler . handle ( 'global:open-window' , ( ) => { createWindow ( ) ; } ) ; } export { createWindow , handleWindowMessages , } ;