修复软件关闭时的bug
parent
78e1b7128a
commit
d06c66ad39
|
@ -121,66 +121,42 @@ const getDisplayOrigin = (display: any) => {
|
||||||
return origin
|
return origin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var windows:Array<BrowserWindow> = [];
|
||||||
|
|
||||||
function createWindow(option: any, url: any) {
|
function createWindow(option: any, url: any) {
|
||||||
const win = new BrowserWindow(option)
|
const win = new BrowserWindow(option)
|
||||||
|
|
||||||
if (URl_REGEX.test(url)) {
|
if (URl_REGEX.test(url)) {
|
||||||
win.loadURL(url)
|
win.loadURL(url)
|
||||||
} else {
|
} else {
|
||||||
win.loadFile(url)
|
win.loadFile(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isWindows = process.platform === 'win32';
|
|
||||||
let needsFocusFix = false;
|
|
||||||
let triggeringProgrammaticBlur = false;
|
|
||||||
|
|
||||||
//弹出警报窗口后 input获取不到焦点
|
|
||||||
win.on('blur', (event: any) => {
|
|
||||||
if(!triggeringProgrammaticBlur) {
|
|
||||||
needsFocusFix = true;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
win.on('focus', (event: any) => {
|
|
||||||
if(isWindows && needsFocusFix) {
|
|
||||||
needsFocusFix = false;
|
|
||||||
triggeringProgrammaticBlur = true;
|
|
||||||
//弹出弹窗后重新聚焦导致windows任务栏显示,重新隐藏底部windows任务栏
|
|
||||||
win.minimize(); //最小化函数
|
|
||||||
win.restore(); //取消最小化函数(从最小化窗口还原函数)
|
|
||||||
setTimeout(function () {
|
|
||||||
win.blur(); //失去焦点函数
|
|
||||||
win.focus(); //获取焦点函数
|
|
||||||
setTimeout(function () {
|
|
||||||
triggeringProgrammaticBlur = false;
|
|
||||||
}, 100);
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if(process.env.NODE_ENV === 'development') win.webContents.openDevTools()
|
if(process.env.NODE_ENV === 'development') win.webContents.openDevTools()
|
||||||
|
windows.push(win);
|
||||||
ipcMain.on('CLOSE', (event) => {
|
|
||||||
const res = dialog.showMessageBox({
|
|
||||||
type: 'warning',
|
|
||||||
title: '警告',
|
|
||||||
message: '确定要关闭软件吗?',
|
|
||||||
detail: '关闭软件',
|
|
||||||
cancelId: 1, // 按esc默认点击索引按钮
|
|
||||||
defaultId: 0, // 默认高亮的按钮下标
|
|
||||||
buttons: ['确认', '取消'], // 按钮按索引从右往左排序
|
|
||||||
})
|
|
||||||
|
|
||||||
res.then((data)=>{
|
|
||||||
if(data.response == 0){
|
|
||||||
win.close()
|
|
||||||
}else{
|
|
||||||
console.log('not close software')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipcMain.on('CLOSE', (event) => {
|
||||||
|
const res = dialog.showMessageBox({
|
||||||
|
type: 'warning',
|
||||||
|
title: '警告',
|
||||||
|
message: '确定要关闭软件吗?',
|
||||||
|
detail: '关闭软件',
|
||||||
|
cancelId: 1, // 按esc默认点击索引按钮
|
||||||
|
defaultId: 0, // 默认高亮的按钮下标
|
||||||
|
buttons: ['确认', '取消'], // 按钮按索引从右往左排序
|
||||||
|
})
|
||||||
|
|
||||||
|
res.then((data)=>{
|
||||||
|
if(data.response == 0){
|
||||||
|
windows.forEach((key:BrowserWindow) => {
|
||||||
|
key.close();
|
||||||
|
});
|
||||||
|
windows = [];
|
||||||
|
}else{
|
||||||
|
console.log('not close software')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
launch()
|
launch()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue