import { BrowserWindow , BrowserWindowConstructorOptions , ipcMain } from 'electron' ; import * as path from 'path' ; import { SaveConfigJson , UserConfigs } from '../config' ; import { Global } from '../global' ; import { MajsoulPlus } from '../majsoul_plus' ; import { removeDirSync , updateObject } from '../utils' ; export let ManagerWindow ; export const ManagerWindowStatus = { visible : false , muted : false } ; export function initManagerWindow ( ) { const config = { ... Global . ManagerWindowConfig } ; if ( process . platform === 'darwin' ) { config . frame = false ; config . titleBarStyle = 'hidden' ; config . vibrancy = 'medium-light' ; config . backgroundColor = 'rgba(0,0,0,0)' ; } config . width *= UserConfigs . window . zoomFactor ; config . height *= UserConfigs . window . zoomFactor ; ManagerWindow = new BrowserWindow ( config ) ; ManagerWindow . removeMenu ( ) ; ManagerWindow . once ( 'ready-to-show' , ( ) => { ManagerWindow . webContents . zoomFactor = UserConfigs . window . zoomFactor ; ManagerWindow . show ( ) ; } ) ; ManagerWindow . on ( 'page-title-updated' , event => event . preventDefault ( ) ) ; ManagerWindow . on ( 'close' , ( ) => { ipcMain . emit ( 'save-resourcepack-enabled' , { } ) ; ipcMain . emit ( 'save-extension-enabled' , { } ) ; ipcMain . emit ( 'save-tool-enabled' , { } ) ; SaveConfigJson ( UserConfigs ) ; } ) ; ManagerWindow . once ( 'closed' , ( ) => { ManagerWindow = undefined ; } ) ; ManagerWindow . loadURL ( 'file://' + path . join ( __dirname , '../manager/index.html' ) ) ; if ( process . env . NODE_ENV === 'development' ) { ManagerWindow . webContents . openDevTools ( { mode : 'detach' } ) ; } ipcMain . on ( 'clear-cache' , event => { removeDirSync ( Global . LocalCachePath ) ; event . returnValue = 0 ; } ) ; ipcMain . on ( 'update-user-config' , ( event , config ) => { updateObject ( UserConfigs , config ) ; if ( UserConfigs . window . zoomFactor < 0.2 ) { UserConfigs . window . zoomFactor = 0.2 ; } else if ( UserConfigs . window . zoomFactor > 10 ) { UserConfigs . window . zoomFactor = 10 ; } SaveConfigJson ( UserConfigs ) ; ManagerWindow . setContentSize ( Global . ManagerWindowConfig . width * UserConfigs . window . zoomFactor , Global . ManagerWindowConfig . height * UserConfigs . window . zoomFactor ) ; ManagerWindow . webContents . zoomFactor = UserConfigs . window . zoomFactor ; } ) ; }