mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 11:13:26 +00:00
优化窗口激活机制
This commit is contained in:
parent
dbba2a1b8f
commit
de45332543
8
electron/electron.js
vendored
8
electron/electron.js
vendored
@ -206,6 +206,14 @@ app.on('before-quit', () => {
|
|||||||
willQuitApp = true
|
willQuitApp = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.on('browser-window-blur', () => {
|
||||||
|
mainWindow.webContents.send("browserWindowBlur", {})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.on('browser-window-focus', () => {
|
||||||
|
mainWindow.webContents.send("browserWindowFocus", {})
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开文件
|
* 打开文件
|
||||||
* @param args {path}
|
* @param args {path}
|
||||||
|
|||||||
@ -59,13 +59,14 @@ export default {
|
|||||||
created() {
|
created() {
|
||||||
this.electronEvents();
|
this.electronEvents();
|
||||||
this.eeuiEvents();
|
this.eeuiEvents();
|
||||||
|
this.otherEvents();
|
||||||
|
this.synchThemeLanguage();
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
window.addEventListener('resize', this.windowSizeListener);
|
window.addEventListener('resize', this.windowSizeListener);
|
||||||
window.addEventListener('scroll', this.windowScrollListener);
|
window.addEventListener('scroll', this.windowScrollListener);
|
||||||
this.searchInter = setInterval(this.searchEnter, 1000);
|
this.searchInter = setInterval(this.searchEnter, 1000);
|
||||||
this.synchThemeLanguage();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
@ -76,6 +77,10 @@ export default {
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['ws', 'themeMode']),
|
...mapState(['ws', 'themeMode']),
|
||||||
|
|
||||||
|
isSoftware() {
|
||||||
|
return this.$Electron || this.$isEEUiApp;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
@ -175,6 +180,16 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
synchThemeLanguage() {
|
||||||
|
if (this.isSoftware) {
|
||||||
|
this.iframes = this.iframes.filter(({key}) => key != 'synchThemeLanguage')
|
||||||
|
this.iframes.push({
|
||||||
|
key: 'synchThemeLanguage',
|
||||||
|
url: $A.apiUrl(`../setting/theme_language?theme=${this.themeMode}&language=${this.languageType}`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
windowSizeListener() {
|
windowSizeListener() {
|
||||||
this.$store.state.windowWidth = $A(window).width()
|
this.$store.state.windowWidth = $A(window).width()
|
||||||
this.$store.state.windowHeight = $A(window).height()
|
this.$store.state.windowHeight = $A(window).height()
|
||||||
@ -202,6 +217,12 @@ export default {
|
|||||||
let {action, data} = args;
|
let {action, data} = args;
|
||||||
this.$store.dispatch(action, data);
|
this.$store.dispatch(action, data);
|
||||||
})
|
})
|
||||||
|
this.$Electron.registerMsgListener('browserWindowBlur', _ => {
|
||||||
|
this.$store.state.windowActive = false;
|
||||||
|
})
|
||||||
|
this.$Electron.registerMsgListener('browserWindowFocus', _ => {
|
||||||
|
this.$store.state.windowActive = true;
|
||||||
|
})
|
||||||
this.iframes.push({
|
this.iframes.push({
|
||||||
key: 'manifest',
|
key: 'manifest',
|
||||||
url: $A.apiUrl("../manifest")
|
url: $A.apiUrl("../manifest")
|
||||||
@ -214,17 +235,12 @@ export default {
|
|||||||
}
|
}
|
||||||
// 页面失活
|
// 页面失活
|
||||||
window.__onPagePause = () => {
|
window.__onPagePause = () => {
|
||||||
if (this.$openLog) {
|
this.$store.state.windowActive = false;
|
||||||
console.log('onPagePause');
|
this.$store.dispatch("getBasicData", -1);
|
||||||
}
|
|
||||||
this.$store.dispatch("getBasicData", -1)
|
|
||||||
}
|
}
|
||||||
// 页面激活
|
// 页面激活
|
||||||
window.__onPageResume = (num) => {
|
window.__onPageResume = (num) => {
|
||||||
if (this.$openLog) {
|
this.$store.state.windowActive = true;
|
||||||
console.log('onPageResume', num);
|
|
||||||
console.log('ws', this.ws, this.ws ? this.ws.readyState : null);
|
|
||||||
}
|
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
this.$store.dispatch("getBasicData", 600)
|
this.$store.dispatch("getBasicData", 600)
|
||||||
if (this.ws === null) {
|
if (this.ws === null) {
|
||||||
@ -240,13 +256,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
synchThemeLanguage() {
|
otherEvents() {
|
||||||
if (this.$Electron || this.$isEEUiApp) {
|
if (!this.isSoftware) {
|
||||||
this.iframes = this.iframes.filter(({key}) => key != 'synchThemeLanguage')
|
// 非客户端监听窗口激活
|
||||||
this.iframes.push({
|
const hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null;
|
||||||
key: 'synchThemeLanguage',
|
const visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
|
||||||
url: $A.apiUrl(`../setting/theme_language?theme=${this.themeMode}&language=${this.languageType}`)
|
document.addEventListener(visibilityChangeEvent, () => {
|
||||||
})
|
this.$store.state.windowActive = !document[hiddenProperty]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -431,7 +431,6 @@ export default {
|
|||||||
allProjectShow: false,
|
allProjectShow: false,
|
||||||
archivedProjectShow: false,
|
archivedProjectShow: false,
|
||||||
|
|
||||||
natificationHidden: false,
|
|
||||||
natificationReady: false,
|
natificationReady: false,
|
||||||
notificationManage: null,
|
notificationManage: null,
|
||||||
|
|
||||||
@ -451,7 +450,6 @@ export default {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
this.notificationInit();
|
this.notificationInit();
|
||||||
this.onVisibilityChange();
|
|
||||||
//
|
//
|
||||||
this.addTaskSubscribe = Store.subscribe('addTask', this.onAddTask);
|
this.addTaskSubscribe = Store.subscribe('addTask', this.onAddTask);
|
||||||
this.dialogMsgSubscribe = Store.subscribe('dialogMsgPush', this.addDialogMsg);
|
this.dialogMsgSubscribe = Store.subscribe('dialogMsgPush', this.addDialogMsg);
|
||||||
@ -501,6 +499,7 @@ export default {
|
|||||||
'clientNewVersion',
|
'clientNewVersion',
|
||||||
'cacheTaskBrowse',
|
'cacheTaskBrowse',
|
||||||
|
|
||||||
|
'windowActive',
|
||||||
'dialogIns',
|
'dialogIns',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
@ -663,15 +662,6 @@ export default {
|
|||||||
}, 600);
|
}, 600);
|
||||||
},
|
},
|
||||||
|
|
||||||
natificationHidden(val) {
|
|
||||||
clearTimeout(this.notificationTimeout);
|
|
||||||
if (!val && this.notificationManage) {
|
|
||||||
this.notificationTimeout = setTimeout(() => {
|
|
||||||
this.notificationManage.close();
|
|
||||||
}, 6000);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
wsOpenNum(num) {
|
wsOpenNum(num) {
|
||||||
if (num <= 1) return
|
if (num <= 1) return
|
||||||
this.$store.dispatch("getBasicData", 600).then(this.getReportUnread)
|
this.$store.dispatch("getBasicData", 600).then(this.getReportUnread)
|
||||||
@ -903,17 +893,17 @@ export default {
|
|||||||
|
|
||||||
addDialogMsg(data) {
|
addDialogMsg(data) {
|
||||||
if (!this.natificationReady && !this.$isEEUiApp) {
|
if (!this.natificationReady && !this.$isEEUiApp) {
|
||||||
return; // 通知未准备好
|
return; // 通知未准备好不通知
|
||||||
}
|
}
|
||||||
if ($A.last(this.dialogIns)?.dialog_id === data.dialog_id) {
|
if (this.windowActive && data.dialog_id === $A.last(this.dialogIns)?.dialog_id) {
|
||||||
return; // 最后打开的会话是通知的会话时不通知
|
return; // 窗口激活且最后打开的会话是通知的会话时不通知
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
const {id, dialog_id, type, msg, userid} = data;
|
const {id, dialog_id, type, msg, userid} = data;
|
||||||
if (userid == this.userId) {
|
if (userid == this.userId) {
|
||||||
return; // 自己的消息不弹出通知
|
return; // 自己的消息不通知
|
||||||
}
|
}
|
||||||
let body = '';
|
let body;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'text':
|
case 'text':
|
||||||
body = $A.getMsgTextPreview(msg.text)
|
body = $A.getMsgTextPreview(msg.text)
|
||||||
@ -1092,15 +1082,6 @@ export default {
|
|||||||
};
|
};
|
||||||
this.notificationManage.initNotification(userSelectFn);
|
this.notificationManage.initNotification(userSelectFn);
|
||||||
},
|
},
|
||||||
|
|
||||||
onVisibilityChange() {
|
|
||||||
let hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null;
|
|
||||||
let visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
|
|
||||||
let visibilityChangeListener = () => {
|
|
||||||
this.natificationHidden = !!document[hiddenProperty]
|
|
||||||
}
|
|
||||||
document.addEventListener(visibilityChangeEvent, visibilityChangeListener);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -171,7 +171,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['dialogMsgs', 'audioPlaying']),
|
...mapState(['dialogMsgs', 'audioPlaying', 'windowActive']),
|
||||||
|
|
||||||
viewClass() {
|
viewClass() {
|
||||||
const {msgData, operateAction, operateEnter} = this;
|
const {msgData, operateAction, operateEnter} = this;
|
||||||
@ -235,6 +235,11 @@ export default {
|
|||||||
},
|
},
|
||||||
immediate: true,
|
immediate: true,
|
||||||
},
|
},
|
||||||
|
windowActive(active) {
|
||||||
|
if (active) {
|
||||||
|
this.msgRead();
|
||||||
|
}
|
||||||
|
},
|
||||||
operateAction(val) {
|
operateAction(val) {
|
||||||
this.operateEnter = false;
|
this.operateEnter = false;
|
||||||
if (val) {
|
if (val) {
|
||||||
@ -255,7 +260,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
msgRead() {
|
msgRead() {
|
||||||
if (this.msgData._r === true) {
|
if (!this.windowActive || this.msgData._r === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.msgData._r = true;
|
this.msgData._r = true;
|
||||||
|
|||||||
@ -116,7 +116,7 @@
|
|||||||
|
|
||||||
<!--底部输入-->
|
<!--底部输入-->
|
||||||
<div class="dialog-footer" :class="{newmsg: msgNew > 0 && allMsgs.length > 0}" @click="onActive">
|
<div class="dialog-footer" :class="{newmsg: msgNew > 0 && allMsgs.length > 0}" @click="onActive">
|
||||||
<div class="dialog-newmsg" @click="onToBottom">{{$L('有' + msgNew + '条新消息')}}</div>
|
<div class="dialog-newmsg" @click="onToBottom">{{$L(`有${msgNew}条新消息`)}}</div>
|
||||||
<DialogUpload
|
<DialogUpload
|
||||||
ref="chatUpload"
|
ref="chatUpload"
|
||||||
class="chat-upload"
|
class="chat-upload"
|
||||||
@ -356,6 +356,7 @@ export default {
|
|||||||
'cacheDialogs',
|
'cacheDialogs',
|
||||||
'wsOpenNum',
|
'wsOpenNum',
|
||||||
'touchBackInProgress',
|
'touchBackInProgress',
|
||||||
|
'windowActive',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
isReady() {
|
isReady() {
|
||||||
@ -505,7 +506,7 @@ export default {
|
|||||||
}
|
}
|
||||||
this.allMsgs = newList;
|
this.allMsgs = newList;
|
||||||
//
|
//
|
||||||
if (scrollE > 10 && oldList.length > 0) {
|
if (!this.windowActive || (scrollE > 10 && oldList.length > 0)) {
|
||||||
const lastId = oldList[oldList.length - 1].id
|
const lastId = oldList[oldList.length - 1].id
|
||||||
const tmpList = newList.filter(item => item.id && item.id > lastId)
|
const tmpList = newList.filter(item => item.id && item.id > lastId)
|
||||||
this.msgNew += tmpList.length
|
this.msgNew += tmpList.length
|
||||||
|
|||||||
3
resources/assets/js/store/state.js
vendored
3
resources/assets/js/store/state.js
vendored
@ -8,6 +8,9 @@ const stateData = {
|
|||||||
windowLarge: $A(window).width() > 768, // 大窗口
|
windowLarge: $A(window).width() > 768, // 大窗口
|
||||||
windowSmall: $A(window).width() <= 768, // 小窗口
|
windowSmall: $A(window).width() <= 768, // 小窗口
|
||||||
|
|
||||||
|
// 窗口是否激活
|
||||||
|
windowActive: true,
|
||||||
|
|
||||||
// 播放中的音频地址
|
// 播放中的音频地址
|
||||||
audioPlaying: null,
|
audioPlaying: null,
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user