You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
648 lines
20 KiB
648 lines
20 KiB
// Modules to control application life and create native browser window
|
|
const {app, BrowserWindow,crashReporter} = require('electron')
|
|
const ipc = require('electron').ipcMain
|
|
// Keep a global reference of the window object, if you don't, the window will
|
|
// be closed automatically when the JavaScript object is garbage collected.
|
|
const electron = require('electron')
|
|
console.log("进入程序时间:",new Date().getTime())
|
|
const Menu = electron.Menu
|
|
const Tray = electron.Tray
|
|
const path =require('path')
|
|
let showWindowFlg = null
|
|
process.argv.forEach(e=>{
|
|
showWindowFlg = e
|
|
console.log(e,showWindowFlg)
|
|
})
|
|
//托盘对象
|
|
var appTray =null
|
|
|
|
let mainWindow = null,kjMain = null,miniWindow =null,kjMain_tray =null
|
|
|
|
let dateStart,dateEnd,showMulWin,gotTheLock=false
|
|
|
|
/**
|
|
* 读取配置文件
|
|
* @type {boolean}
|
|
*/
|
|
|
|
const fs = require("fs")
|
|
|
|
const newFile_path = path.join(__dirname,'./config/config.json').replace(/\\/g,"\/")
|
|
|
|
fs.exists(newFile_path,function (exists) {
|
|
console.log(exists ? "文件存在" : "文件不存在")
|
|
if (exists) {
|
|
console.log("配置文件",newFile_path)
|
|
}
|
|
})
|
|
let temp =fs.readFileSync(newFile_path)
|
|
showMulWin = JSON.parse(temp).showMulWin
|
|
console.log("showMulWin的值",showMulWin)
|
|
|
|
//系统托盘邮件菜单
|
|
let trayMenuTemplate = [
|
|
{
|
|
label: '刷新界面',
|
|
click: function () {
|
|
// 如果kjMain 不为空则先关闭该窗口
|
|
if (kjMain !=null){
|
|
kjMain.restore()
|
|
kjMain.reload()
|
|
}
|
|
// mainWindow.reload()
|
|
},//打开相应的页面
|
|
type: 'radio'
|
|
},
|
|
{
|
|
label: '打开调试窗口',
|
|
click: function () {
|
|
//console.log(kjMain.devToolsWebContents)
|
|
if (kjMain !=null){
|
|
// kjMain.webContents.openDevTools()
|
|
kjMain.webContents.send('openDevTools',"open devTools")
|
|
}
|
|
else {
|
|
initWin()
|
|
kjMain.webContents.openDevTools()
|
|
}
|
|
},
|
|
type: 'radio',
|
|
},
|
|
,
|
|
|
|
{
|
|
label: '显示消息通知',
|
|
click: function () {
|
|
if(mainWindow !=null ){
|
|
if (kjMain!=null){
|
|
kjMain.minimize()
|
|
// kjMain.hide() //linux下需要去掉
|
|
}
|
|
mainWindow.show()
|
|
mainWindow.restore()
|
|
mainWindow.setSkipTaskbar(true)
|
|
}
|
|
},
|
|
type: 'radio'
|
|
},
|
|
{
|
|
label: '最小化消息通知',
|
|
click: function () {
|
|
// mainWindow.close()
|
|
mainWindow.hide()
|
|
console.log("hide!!!")
|
|
},
|
|
type:'radio',
|
|
},
|
|
{
|
|
label: '打开双屏模式',
|
|
click: function () {
|
|
if (kjMain_tray==null){
|
|
console.log("新建browser")
|
|
initWinKj()
|
|
} else {
|
|
console.log("已经存在新框架")
|
|
kjMain_tray.restore()
|
|
kjMain_tray.show()
|
|
}
|
|
},
|
|
type:'radio',
|
|
},
|
|
{
|
|
label: '退出框架系统',
|
|
click: function () {
|
|
if (kjMain !=null){
|
|
console.log("主进程向preload发送进程")
|
|
kjMain.webContents.send('dispatchCloseButton',"回掉退出按钮")
|
|
}
|
|
if (setDialog !=null){
|
|
setDialog.close()
|
|
}
|
|
if (kjMain_tray!=null) {
|
|
kjMain_tray.close()
|
|
}
|
|
console.log("成功退出!!!")
|
|
if (kjMain!=null){
|
|
kjMain.hide()
|
|
setTimeout(()=>{
|
|
kjMain.close()
|
|
},500)
|
|
}
|
|
mainWindow.close()
|
|
},
|
|
// icon: path.join(path.join(__dirname,'tray'),'tb2.png')
|
|
type:'radio',
|
|
}
|
|
]
|
|
function createWindow (){
|
|
console.log("chu shi hua yingyong")
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
mainWindow = new BrowserWindow({
|
|
width: 469,
|
|
height: 780,
|
|
//将页面显示在桌面右下角,x=屏幕宽度-窗口宽度 ,y=屏幕高度-窗口高度
|
|
/* x: screenWidth-widthx,
|
|
y: screenHeight-heighty,*/
|
|
x: areaSize.width-469,
|
|
y: areaSize.height-780,
|
|
fullscreen:false,
|
|
webPreferences: {
|
|
nodeIntegration: true, // 这里是否需要node.js的支持,如果true可能和空中突击旅框架中用到的require冲突,需要设置成false。
|
|
webSecurity: true
|
|
},
|
|
icon : path.join(path.join(__dirname,'tray'),'tb2.png'),
|
|
transparent:true,
|
|
hasShadow:false,
|
|
alwaysOnTop:false,
|
|
frame:false,
|
|
})
|
|
if (mainWindow !=null) {
|
|
mainWindow.minimize()
|
|
mainWindow.hide()
|
|
}
|
|
mainWindow.loadFile('msgList.html')
|
|
//系统托盘目录
|
|
let trayIcon =path.join(__dirname,'tray')
|
|
appTray = new Tray(path.join(trayIcon,'tb2.png'))
|
|
|
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
|
|
|
appTray.setToolTip('指挥信息系统') //修改托盘的名字,如果换成统行需要修改
|
|
appTray.setContextMenu(contextMenu)
|
|
|
|
//图片功能闪烁的实现
|
|
// var count = 0
|
|
// timer = null
|
|
// timer = setInterval(function () {
|
|
// count ++
|
|
// if (count % 2 ==0){
|
|
// appTray.setImage(path.join(trayIcon,'empty.png'))
|
|
// }else {
|
|
// appTray.setImage(path.join(trayIcon,'tb2.png'))
|
|
// }
|
|
// },500)
|
|
appTray.on('click',() => { //在linux平台下没有此功能
|
|
if (kjMain !=null){
|
|
mainWindow.isVisible() ?
|
|
(mainWindow.hide(),kjMain.show()) : (mainWindow.show(),kjMain.hide())
|
|
} else {
|
|
mainWindow.isVisible() ?
|
|
(mainWindow.hide()) : (mainWindow.show())
|
|
}
|
|
|
|
// mainWindow.isVisible() ?
|
|
// (mainWindow.setSkipTaskbar(false),kjMain.maximize()) : (mainWindow.setSkipTaskbar(true),kjMain.maximize())
|
|
// mainWindow.show()
|
|
console.log("dian ji shijian ")
|
|
// timer.Enable= false
|
|
})
|
|
|
|
mainWindow.webContents.on('dom-ready',()=>{
|
|
console.log("主进程开始时间:",new Date().getTime())
|
|
})
|
|
|
|
// mainWindow.on('show', () => {
|
|
// appTray.setHighlightMode('always')
|
|
// })
|
|
//
|
|
// mainWindow.on('hide', () => {
|
|
// appTray.setHighlightMode('never')
|
|
// })
|
|
}
|
|
|
|
function createMiniWindow (){
|
|
console.log("chu shi hua mini")
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
mainWindow = new BrowserWindow({
|
|
width: 469,
|
|
height: 780,
|
|
//将页面显示在桌面右下角,x=屏幕宽度-窗口宽度 ,y=屏幕高度-窗口高度
|
|
/* x: screenWidth-widthx,
|
|
y: screenHeight-heighty,*/
|
|
x: areaSize.width-469,
|
|
y: areaSize.height-780,
|
|
fullscreen:false,
|
|
webPreferences: {
|
|
nodeIntegration: true, // 这里是否需要node.js的支持,如果true可能和空中突击旅框架中用到的require冲突,需要设置成false。
|
|
webSecurity: true
|
|
},
|
|
icon : path.join(path.join(__dirname,'tray'),'tb2.png'),
|
|
transparent:true,
|
|
hasShadow:false,
|
|
alwaysOnTop:false,
|
|
frame:false,
|
|
})
|
|
if (mainWindow !=null) {
|
|
mainWindow.minimize()
|
|
mainWindow.hide()
|
|
}
|
|
mainWindow.loadFile('msgMiniList.html')
|
|
//系统托盘目录
|
|
let trayIcon =path.join(__dirname,'tray')
|
|
appTray = new Tray(path.join(trayIcon,'tb2.png'))
|
|
|
|
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate)
|
|
|
|
appTray.setToolTip('指挥信息系统') //修改托盘的名字,如果换成统行需要修改
|
|
appTray.setContextMenu(contextMenu)
|
|
|
|
appTray.on('click',() => { //在linux平台下没有此功能
|
|
if (kjMain !=null){
|
|
mainWindow.isVisible() ?
|
|
(mainWindow.hide(),kjMain.show()) : (mainWindow.show(),kjMain.hide())
|
|
} else {
|
|
mainWindow.isVisible() ?
|
|
(mainWindow.hide()) : (mainWindow.show())
|
|
}
|
|
|
|
console.log("dian ji shijian ")
|
|
// timer.Enable= false
|
|
})
|
|
mainWindow.minimize()
|
|
mainWindow.hide()
|
|
mainWindow.on('show', () => {
|
|
appTray.setHighlightMode('always')
|
|
})
|
|
|
|
mainWindow.on('hide', () => {
|
|
appTray.setHighlightMode('never')
|
|
})
|
|
|
|
}
|
|
|
|
//初始化时开启此窗口
|
|
function initWin(){
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
//window平台时使用mainWindow.hide(),银河麒麟平台时使用mainWindow.minimize()
|
|
if (mainWindow !=null) {
|
|
mainWindow.minimize()
|
|
mainWindow.hide()
|
|
}
|
|
kjMain = new BrowserWindow({
|
|
width: areaSize.width,
|
|
height: areaSize.height,
|
|
// width:1129,
|
|
// height:635,
|
|
fullscreen:true,
|
|
offScreen:false,
|
|
webPreferences: {
|
|
nodeIntegration: true, // 这里是否需要node.js的支持,如果true可能和空中突击旅框架中用到的require冲突,所以要设置成false。
|
|
webviewTag:true,
|
|
webSecurity:false //跨域策略
|
|
},
|
|
backgroundColor:'#80FFFFFF',
|
|
frame:false,
|
|
icon : path.join(path.join(__dirname,'tray'),'tb2.png'),
|
|
//show: false
|
|
})
|
|
// kjMain.hide()
|
|
kjMain.loadFile('index7.html')
|
|
// /**
|
|
// * 清除缓存
|
|
// * @type {Electron.Session}
|
|
// */
|
|
// const ses=kjMain.webContents.session
|
|
// ses.clearStorageData()
|
|
kjMain.on('closed', function () {
|
|
// Dereference the window object, usually you would store windows
|
|
// in an array if your app supports multi windows, this is the time
|
|
// when you should delete the corresponding element.
|
|
console.log("tui chu kjMain")
|
|
// mainWindow.close()
|
|
kjMain = null
|
|
})
|
|
|
|
|
|
kjMain.webContents.on('did-start-loading',()=>{
|
|
console.log("kai shi jiazai xin jiemian",new Date().getTime())
|
|
})
|
|
|
|
kjMain.webContents.on('dom-ready',()=>{
|
|
console.log("dom ready ..",new Date().getTime())
|
|
})
|
|
|
|
kjMain.webContents.on('did-stop-loading',()=>{
|
|
dateEnd =new Date().getTime()
|
|
console.log("wancheng xin jiemian jiazai",dateEnd,dateStart)
|
|
})
|
|
|
|
mainWindow.webContents.on('new-window',()=>{
|
|
console.log("new-window...",new Date().getTime())
|
|
})
|
|
}
|
|
// This method will be called when Electron has finished
|
|
// initialization and is ready to create browser windows.
|
|
// Some APIs can only be used after this event occurs.
|
|
//新加载界面
|
|
function initWinKj(){
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
kjMain_tray = new BrowserWindow({
|
|
width: areaSize.width,
|
|
height: areaSize.height,
|
|
// width:1129,
|
|
// height:635,
|
|
fullscreen:false,
|
|
offScreen:false,
|
|
webPreferences: {
|
|
nodeIntegration: true, // 这里是否需要node.js的支持,如果true可能和空中突击旅框架中用到的require冲突,所以要设置成false。
|
|
webviewTag:true,
|
|
webSecurity:false //跨域策略
|
|
},
|
|
backgroundColor:'#80FFFFFF',
|
|
frame:true,
|
|
icon : path.join(path.join(__dirname,'tray'),'tb2.png'),
|
|
//show: false
|
|
})
|
|
// kjMain.hide()
|
|
kjMain_tray.loadFile('index_tray.html')
|
|
kjMain_tray.on("maximize",()=>{
|
|
kjMain_tray.setMenuBarVisibility(false)
|
|
kjMain_tray.setFullScreen(true)
|
|
})
|
|
//登陆界面最小化
|
|
kjMain_tray.on('window-min-tray',()=>{
|
|
if (kjMain_tray!=null){
|
|
kjMain_tray.minimize()
|
|
kjMain_tray.hide()
|
|
}
|
|
console.log("最小化框架kjmain_tray")
|
|
})
|
|
|
|
kjMain_tray.on('closed', function () {
|
|
// Dereference the window object, usually you would store windows
|
|
// in an array if your app supports multi windows, this is the time
|
|
// when you should delete the corresponding element.
|
|
console.log("tui chu kjMain_tray")
|
|
// mainWindow.close()
|
|
kjMain_tray = null
|
|
})
|
|
}
|
|
app.commandLine.appendSwitch("--disable-http-cache") // 功能类似于Chrome 调试下“disable cache”禁止缓存的功能。必须在app.on('ready')前使用
|
|
//设置当个实例的例子
|
|
|
|
gotTheLock = app.requestSingleInstanceLock()
|
|
console.log("huo qu gotTheLock de value",gotTheLock)
|
|
|
|
console.log(showMulWin,"111")
|
|
|
|
if (showMulWin =="true"){
|
|
gotTheLock = showMulWin
|
|
console.log("she zhi gotTheLock de value",gotTheLock)
|
|
}
|
|
if (!gotTheLock) {
|
|
console.log("app的信息",app)
|
|
app.quit()
|
|
} else {
|
|
app.on('second-instance',(event,commandLine,workingDirectory)=>{
|
|
//当运行到第二个实例时,将会聚焦到myWindow这个窗口
|
|
if (mainWindow){
|
|
if (kjMain == null){
|
|
initWin()
|
|
kjMain.focus()
|
|
kjMain.restore()
|
|
//kjMain.maximize()
|
|
}else if (kjMain.isMinimized!=undefined && kjMain.isMinimized()){ //如果最小化,就将最小化恢复
|
|
kjMain.focus()
|
|
kjMain.restore()
|
|
}else {
|
|
kjMain.focus()
|
|
kjMain.restore()
|
|
kjMain.maximize()
|
|
}
|
|
//else if (kjMain == null){
|
|
// initWin()
|
|
//kjMain.maximize()
|
|
// }
|
|
|
|
}
|
|
console.log("23232323")
|
|
|
|
})
|
|
if (showWindowFlg == 'tray'){
|
|
app.on('ready',createMiniWindow)
|
|
} else {
|
|
app.on('ready', createWindow)
|
|
}
|
|
|
|
// app.on('ready', () =>{
|
|
// initWin();
|
|
// })
|
|
}
|
|
|
|
app.commandLine.appendSwitch('ignore-gpu-blacklist') //解决飞腾麒麟服务器显示3D地图报cesium.js的问题
|
|
// Quit when all windows are closed.
|
|
app.on('window-all-closed', function () {
|
|
// On macOS it is common for applications and their menu bar
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
if (process.platform !== 'darwin') app.quit()
|
|
})
|
|
|
|
app.on('activate', function () {
|
|
// On macOS it's common to re-create a window in the app when the
|
|
// dock icon is clicked and there are no other windows open.
|
|
if (mainWindow === null) createWindow()
|
|
})
|
|
|
|
// app.setPath("temp","app/launhcer/custom")
|
|
//crashReporter.start()
|
|
|
|
// //登陆界面最大化
|
|
ipc.on('window-max',function (){
|
|
if (mainWindow.isMaximized()){
|
|
mainWindow.restore()
|
|
} else {
|
|
mainWindow.maximize()
|
|
}
|
|
})
|
|
|
|
|
|
// const areaSize1 = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
|
|
global.sharedObject ={
|
|
setMsgArr : [],
|
|
someProperty : 'new value',
|
|
dialogNum : 0
|
|
} //渲染进程间共享数据
|
|
|
|
//消息对话弹框
|
|
let dialogWin = []
|
|
ipc.on('msgLatest',(event,arg,num)=> {
|
|
//console.log("mainwindow的状态",mainWindow.isMaximized(),mainWindow.isMaximized(),mainWindow.isVisible(),"kjMain的状态",kjMain.isVisible(),kjMain.isMaximized(),kjMain.isMinimized())
|
|
if ( !mainWindow.isVisible()&&kjMain.isMinimized()||!mainWindow.isVisible()&&!kjMain.isVisible()){
|
|
let areaSize1 = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
let y_height = areaSize1.height
|
|
// let y_height = y_height+3
|
|
dialogWin[num] = new BrowserWindow({
|
|
width: 460 ,
|
|
height: 360,
|
|
// fullscreen:true,
|
|
x: areaSize1.width-460,
|
|
y: y_height-360-3*num,
|
|
webPreferences: {
|
|
nodeIntegration: true // 这里是否需要node.js的支持,如果true可能和空中突击旅框架中用到的require冲突,所以要设置成false。
|
|
},
|
|
frame:false,
|
|
icon : path.join(path.join(__dirname,'tray'),'tb2.png'),
|
|
})
|
|
dialogWin[num].loadFile('msg_diag.html')
|
|
dialogWin[num].setAlwaysOnTop(true)
|
|
console.log(arg,num)
|
|
}
|
|
})
|
|
|
|
//消息设置窗口
|
|
let setDialog = null
|
|
ipc.on('openSetDialog',(event,arg)=>{
|
|
if(setDialog !=null){
|
|
setDialog.restore()
|
|
}
|
|
else {
|
|
console.log(arg)
|
|
let areaSize1 = require('electron').screen.getPrimaryDisplay().workAreaSize
|
|
// let y_height = y_height+3
|
|
setDialog = new BrowserWindow({
|
|
width: 460 ,
|
|
height: 360,
|
|
// fullscreen:true,
|
|
x: areaSize1.width-1200,
|
|
y: areaSize1.height-500,
|
|
webPreferences: {
|
|
nodeIntegration: true // 这里是否需要node.js的支持,如果true可能和空中突击旅框架中用到的require冲突,所以要设置成false。
|
|
},
|
|
frame:false,
|
|
icon : path.join(path.join(__dirname,'tray'),'tb2.png'),
|
|
})
|
|
setDialog.loadFile('setDialog.html')
|
|
}
|
|
|
|
})
|
|
|
|
// 启动时初始化软件框架
|
|
ipc.on('rjkj',()=> {
|
|
console.log("chu shi hua shi dakai")
|
|
dateStart = new Date().getTime()
|
|
initWin()
|
|
})
|
|
//发送通信机制来显示框架
|
|
ipc.on('displayKJ',()=> {
|
|
if (kjMain != null) {
|
|
mainWindow.minimize()
|
|
console.log("da kai renjia kuagnjia",kjMain.isMinimized(),!kjMain.isVisible)
|
|
if (kjMain.isMinimized() || kjMain.isVisible){ //如果最小化,就将最小化恢复
|
|
kjMain.focus()
|
|
kjMain.restore()
|
|
kjMain.show()
|
|
//kjMain.maximize()
|
|
}else {
|
|
kjMain.focus()
|
|
kjMain.restore()
|
|
//kjMain.maximize()
|
|
console.log("启动人机框架")
|
|
}
|
|
//kjMain.maximize()
|
|
|
|
}else {
|
|
console.log("diaoyong kj")
|
|
initWin()
|
|
}
|
|
})
|
|
console.log("完成程序时间:",new Date().getTime())
|
|
// 获取最新消息时弹出消息通知
|
|
ipc.on('displayNotice',()=> {
|
|
console.log("get latest data")
|
|
console.log(mainWindow.isVisible())
|
|
if (kjMain !=null) {
|
|
console.log("zhi xing 1",kjMain.isVisible(),kjMain.isMinimized())
|
|
if (!(mainWindow.isVisible()) && kjMain.isMinimized()){
|
|
console.log("only show message 1 ")
|
|
mainWindow.show();
|
|
}
|
|
}
|
|
else {
|
|
console.log("zhi xing 2")
|
|
if (!(mainWindow.isVisible()) ){
|
|
console.log("only show message 2")
|
|
mainWindow.show();
|
|
}
|
|
}
|
|
})
|
|
|
|
//登陆界面最小化
|
|
ipc.on('window-min',()=>{
|
|
if (kjMain != null) {
|
|
console.log("kjmain的Minized的值:",kjMain.isMinimized())
|
|
kjMain.minimize()
|
|
}
|
|
console.log("最小化kjMain")
|
|
})
|
|
//登陆界面最小化
|
|
ipc.on('window-min-tray',()=>{
|
|
if (kjMain_tray != null) {
|
|
console.log("kjmain_tray的minisized值是:",kjMain_tray.isMinimized())
|
|
kjMain_tray.minimize()
|
|
}
|
|
console.log("最小化框架kjmain_tray")
|
|
})
|
|
//登陆界面最关闭
|
|
ipc.on('window-close',()=>{
|
|
console.log("tuichu kj")
|
|
if (kjMain !=null){
|
|
kjMain.close()
|
|
}
|
|
if (kjMain_tray!=null){
|
|
kjMain_tray.close()
|
|
}
|
|
if (mainWindow !=null){
|
|
mainWindow.close()
|
|
}else {
|
|
mainWindow.close()
|
|
}
|
|
})
|
|
|
|
//登陆界面最关闭
|
|
ipc.on('window-close-tray',()=>{
|
|
console.log("tuichu kj")
|
|
if (kjMain!=null){
|
|
kjMain.close()
|
|
}
|
|
if (kjMain_tray!=null){
|
|
kjMain_tray.close()
|
|
}
|
|
if (mainWindow !=null){
|
|
mainWindow.close()
|
|
}else {
|
|
mainWindow.close()
|
|
}
|
|
})
|
|
|
|
//关闭弹窗提醒窗口
|
|
ipc.on('openDialog',(event,arg)=> {
|
|
const {dialog ,shell ,nativeImage} =require('electron')
|
|
dialog.showMessageBox({
|
|
type: "info",
|
|
title: "消息",
|
|
message : arg.text,
|
|
buttons : ["确定","取消"],
|
|
icon:nativeImage.createFromPath("./tray/close_button.png"),
|
|
|
|
})
|
|
})
|
|
|
|
|
|
ipc.on('closeDialog',(event,arg) =>{
|
|
// dialogWin="dialogWin"+arg
|
|
console.log("guan bi tanchuan",arg)
|
|
if (dialogWin[arg] !=null){
|
|
dialogWin[arg].close()
|
|
}
|
|
|
|
})
|
|
|
|
ipc.on('closeSetDialog',(event,arg) =>{
|
|
setDialog.close()
|
|
setDialog = null
|
|
})
|
|
// In this file you can include the rest of your app's specific main process
|
|
// code. You can also put them in separate files and require them here.
|
|
|
|
|