'use strict' import {app, session} from 'electron' import InitWindow from './services/windowManager' import disableButton from './hook/disableButtonHook' import {initTray} from './services/trayManager' import domains from "./config/domains"; import server from "./server"; function onAppReady() { new InitWindow().initWindow() initTray() disableButton.disableF12() if (process.env.NODE_ENV === 'development') { const {VUEJS_DEVTOOLS} = require("electron-devtools-vendor"); session.defaultSession.loadExtension(VUEJS_DEVTOOLS, { allowFileAccess: true, }).then(r => { console.log('已安装: vue-devtools'); }); //添加启动内置服务器 server.StartServer().then((r) => { console.log('内置服务器已启动'); }) } } app.whenReady().then(onAppReady) //禁止程序多开;需要单例锁的时候用 // const gotTheLock = app.requestSingleInstanceLock() // if (!gotTheLock) { // console.log("检测到应用单例锁") // app.quit() // } // 由于9.x版本问题,需要加入该配置关闭跨域问题 app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') app.on('window-all-closed', () => { // 所有平台均为所有窗口关闭就退出软件 app.quit() }) app.on('browser-window-created', () => { console.log('window-created') }) /** * 安全检查 * 创建WebView前先检查内容来源 */ app.on('web-contents-created', (event, contents) => { contents.on('will-attach-webview', (event, webPreferences, params) => { let isSafe = 0; domains.some((d) => { // 验证正在加载的 URL if (!params.src.startsWith(d)) { isSafe -= 1; } }) if (isSafe < 0) { // 禁用 Node.js 集成 // webPreferences.nodeIntegration = false; // event.preventDefault() // 如果未使用,则删除预加载脚本或验证其位置是否合法 // delete webPreferences.preload } }) }) if (process.defaultApp) { if (process.argv.length >= 2) { app.removeAsDefaultProtocolClient('Hi-sass-frame') console.log('由于框架特殊性,开发环境下无法使用') } } else { app.setAsDefaultProtocolClient('Hi-sass-frame') }