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.
212 lines
7.5 KiB
212 lines
7.5 KiB
const {BrowserWindow} = require('electron');
|
|
const ipc = require('electron').ipcMain;
|
|
// const screen = require('electron').screen;
|
|
const store = require('./windows/lib/store');
|
|
const {create: createMainWindow} = require('./windows/main')
|
|
// const { create: createLoginWindow } = require('./windows/login')
|
|
// const { create: createAppWindow } = require('./windows/app')
|
|
|
|
const {MAIN_WINDOW_FLAG, SUSPENSION_WINDOW_FLAG} = require('./constant');
|
|
// const installApp = require('./ipc/installApp');
|
|
// const getApps = require('./ipc/getApps');
|
|
// const removeApp = require('./ipc/removeApp');
|
|
|
|
|
|
module.exports = () => {
|
|
let winStartPostion = {x: 0, y: 0};
|
|
let mouseStartPosition = {x: 0, y: 0};
|
|
let movingInterVal = null;
|
|
ipc.on('getUnReadMessage', (events, callback) => {
|
|
const msg = store.get('unReadMessage');
|
|
// console.log('msg', msg);
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const found = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
found.webContents.send("getUnReadMessage", [msg])
|
|
});
|
|
ipc.on('setUnReadMessage', (events, message) => {
|
|
// console.log('set', message);
|
|
store.set('unReadMessage', message);
|
|
// 消息需要实时同步
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const win = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
if (win) {
|
|
// let winWidth = win.getSize()[0];
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
|
|
const x = win.getPosition()[0];
|
|
const y = win.getPosition()[1];
|
|
let sWidth = areaSize.width;
|
|
// console.log(sWidth - x);
|
|
if (sWidth - x === 130) {
|
|
win.setSize(640, 130, true);
|
|
win.setPosition(sWidth - 660, y, true);
|
|
}
|
|
win.webContents.send("getUnReadMessage", [message])
|
|
}
|
|
|
|
});
|
|
ipc.on("showSuspensionWindow",()=>{
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const win = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
console.log('恢复原始大小')
|
|
win.setSize(640, 130, true);
|
|
const y = win.getPosition()[1];
|
|
win.setPosition(areaSize.width - win.getSize()[0], y, true);
|
|
win.webContents.send("winResize", [win.getSize()])
|
|
|
|
})
|
|
ipc.on('resizeWindow', () => {
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const win = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
const startWidth = win.getSize()[0];
|
|
if(startWidth < 640){
|
|
const x = win.getPosition()[0];
|
|
const y = win.getPosition()[1];
|
|
win.setSize(640, 130, true);
|
|
if(x > areaSize.width - win.getSize()[0] ){
|
|
win.setPosition(areaSize.width - win.getSize()[0] - 50, y, true);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
ipc.on('windowMoveHandle', (events, canMoving) => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const win = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
const screen = require('electron').screen;
|
|
/**
|
|
* 窗口移动事件
|
|
*/
|
|
if (canMoving) {
|
|
if (!win) return;
|
|
//读取原位置
|
|
const winPosition = win.getPosition();
|
|
winStartPostion = {x: winPosition[0], y: winPosition[1]};
|
|
mouseStartPosition = screen.getCursorScreenPoint();
|
|
//清除
|
|
if (movingInterVal) {
|
|
clearInterval(movingInterVal);
|
|
}
|
|
//新开
|
|
movingInterVal = setInterval(() => {
|
|
const cursorPosition = screen.getCursorScreenPoint();
|
|
const x = winStartPostion.x + cursorPosition.x - mouseStartPosition.x;
|
|
const y = winStartPostion.y + cursorPosition.y - mouseStartPosition.y;
|
|
|
|
win.setPosition(x, y, true)
|
|
}, 20)
|
|
} else {
|
|
clearInterval(movingInterVal);
|
|
let areaSize = require('electron').screen.getPrimaryDisplay().workAreaSize;
|
|
const x = win.getPosition()[0];
|
|
const y = win.getPosition()[1];
|
|
store.set("position",{x,y});
|
|
let sWidth = areaSize.width;
|
|
let winWidth = win.getSize()[0];
|
|
// console.log(x + winWidth >= sWidth, sWidth - x - winWidth);
|
|
// 靠边吸附效果
|
|
console.log("0000000",x + winWidth >= sWidth,sWidth - x - winWidth <= 20)
|
|
if (x + winWidth >= sWidth || sWidth - x - winWidth <= 20) {
|
|
win.setResizable(true);
|
|
win.setSize(130,130,true)
|
|
|
|
win.setPosition(sWidth - 130, y, true);
|
|
win.setResizable(false);
|
|
console.log("靠边吸附",win.getSize(),win.getPosition())
|
|
//通知渲染进程大小发生改变
|
|
}else{
|
|
win.setSize(650,130,true)
|
|
}
|
|
win.webContents.send("winResize", [win.getSize()])
|
|
movingInterVal = null;
|
|
}
|
|
});
|
|
ipc.on('showMainWindow', (event, arg) => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const found = windows.find((window) => {
|
|
return window[MAIN_WINDOW_FLAG]
|
|
})
|
|
if (found) {
|
|
found.restore();
|
|
found.show();
|
|
} else {
|
|
createMainWindow()
|
|
}
|
|
return true
|
|
});
|
|
ipc.on('hideMainWindow', () => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const found = windows.find((window) => {
|
|
return window[MAIN_WINDOW_FLAG]
|
|
})
|
|
if (found) {
|
|
found.hide();
|
|
}
|
|
return true
|
|
});
|
|
ipc.on('minimize', () => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const found = windows.find((window) => {
|
|
return window[MAIN_WINDOW_FLAG]
|
|
})
|
|
if (found) {
|
|
found.minimize();
|
|
}
|
|
return true
|
|
});
|
|
|
|
ipc.on('hideSuspensionWindow', (event, arg) => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const found = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
if (found) {
|
|
found.close()
|
|
}
|
|
return true
|
|
});
|
|
|
|
ipc.on('openDevTools', (event, arg) => {
|
|
event.sender.webContents.openDevTools()
|
|
return true
|
|
});
|
|
|
|
ipc.on('exitSystem', () => {
|
|
const windows = BrowserWindow.getAllWindows()
|
|
const mainWindow = windows.find((window) => {
|
|
return window[MAIN_WINDOW_FLAG]
|
|
})
|
|
const suspWindow = windows.find((window) => {
|
|
return window[SUSPENSION_WINDOW_FLAG]
|
|
});
|
|
store.delete("unReadMessage");
|
|
mainWindow && mainWindow.close();
|
|
suspWindow && suspWindow.close();
|
|
});
|
|
// ipcMain.handle('openWidget', (event, widget = {}) => {
|
|
// createAppWindow(widget)
|
|
// return true
|
|
// });
|
|
//
|
|
// ipcMain.handle('openDevTools', (event, arg) => {
|
|
// event.sender.webContents.openDevTools()
|
|
// return true
|
|
// });
|
|
|
|
// ipcMain.handle('installApp', installApp);
|
|
//
|
|
// ipcMain.handle('getApps', getApps);
|
|
//
|
|
// ipcMain.handle('removeApp', removeApp);
|
|
}
|