From bebeb49ae4f3bda64d4b824820884a5bff50bf7a Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 2 Dec 2022 10:23:54 +0800 Subject: [PATCH] no message --- electron/electron.js | 33 ++++++++--- resources/assets/js/App.vue | 2 +- resources/assets/js/app.js | 57 +++++++++---------- .../js/pages/manage/setting/keyboard.vue | 11 +++- 4 files changed, 61 insertions(+), 42 deletions(-) diff --git a/electron/electron.js b/electron/electron.js index a057dafde..e60cecb1b 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -201,13 +201,9 @@ if (!getTheLock) { } // 截图对象 screenshotObj = new Screenshots({ - singleWindow: true + singleWindow: true, + mainWindow: mainWindow }) - globalShortcut.register("esc", () => { - if (screenshotObj.$win?.isFocused()) { - screenshotObj.endCapture().then(_ => {}); - } - }); }) } @@ -229,6 +225,10 @@ app.on('before-quit', () => { willQuitApp = true }) +app.on("will-quit",function(){ + globalShortcut.unregisterAll(); +}) + app.on('browser-window-blur', () => { if (mainWindow) { mainWindow.webContents.send("browserWindowBlur", {}) @@ -473,7 +473,10 @@ ipcMain.on('bindScreenshotKey', (event, args) => { if (key) { screenshotKey = key globalShortcut.register(key, () => { - screenshotObj.startCapture().then(_ => {}) + screenshotObj.startCapture().then(_ => { + screenshotObj.view.webContents.executeJavaScript('if(typeof window.__initializeShortcuts===\'undefined\'){window.__initializeShortcuts=true;document.addEventListener(\'keydown\',function(e){console.log(e);if(e.keyCode===27){window.screenshots.cancel()}})}', true).catch(() => {}); + screenshotObj.view.webContents.focus() + }) }) } } @@ -483,8 +486,20 @@ ipcMain.on('bindScreenshotKey', (event, args) => { /** * 执行截图 */ -ipcMain.on('onScreenshot', (event) => { - screenshotObj.startCapture().then(_ => {}) +ipcMain.on('openScreenshot', (event) => { + if (screenshotObj) { + screenshotObj.startCapture().then(_ => {}) + } + event.returnValue = "ok" +}) + +/** + * 关闭截图 + */ +ipcMain.on('closeScreenshot', (event) => { + if (screenshotObj && screenshotObj.window?.isFocused()) { + screenshotObj.endCapture().then(_ => {}); + } event.returnValue = "ok" }) diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index 6325d8b49..6d97018f7 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -118,7 +118,7 @@ export default { }, 6000) } // - if (this.$openLog) { + if ($A.openLog) { $A.loadScript('js/vconsole.min.js', (e) => { if (e !== null || typeof window.VConsole !== 'function') { $A.modalError("vConsole 组件加载失败!"); diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index a9a2f28eb..e28592450 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -135,6 +135,7 @@ Vue.prototype.goBack = function () { }; // 全局对象/变量 +$A.L = $L; $A.Electron = null; $A.Platform = "web"; $A.isMainElectron = false; @@ -148,35 +149,7 @@ if (isElectron) { $A.isSubElectron = /\s+SubTaskWindow\//.test(window.navigator.userAgent); } -Vue.prototype.$A = $A; -Vue.prototype.$L = $L; -Vue.prototype.$Electron = $A.Electron; -Vue.prototype.$Platform = $A.Platform; -Vue.prototype.$isMainElectron = $A.isMainElectron; -Vue.prototype.$isSubElectron = $A.isSubElectron; -Vue.prototype.$isEEUiApp = $A.isEEUiApp; -Vue.prototype.$openLog = $A.openLog; - -Vue.config.productionTip = false; -Vue.mixin(mixin) - -const app = new Vue({ - el: '#app', - router, - store, - template: '', - components: { App } -}); - - -$A.goForward = app.goForward; -$A.goBack = app.goBack; -$A.Message = app.$Message; -$A.Notice = app.$Notice; -$A.Modal = app.$Modal; -$A.store = app.$store; -$A.L = app.$L; - +// 子窗口给主窗口发送指令相关 $A.execMainDispatch = (action, data) => { if ($A.isSubElectron) { $A.Electron.sendMessage('sendForwardMain', { @@ -193,6 +166,7 @@ $A.execMainCacheJudge = (key) => { return val }; +// 绑定截图快捷键 $A.bindScreenshotKey = (data) => { let key = ""; if (data.screenshot_key && (data.screenshot_mate || data.screenshot_shift)) { @@ -206,3 +180,28 @@ $A.bindScreenshotKey = (data) => { } $A.Electron.sendMessage('bindScreenshotKey', {key}); }; + +Vue.prototype.$A = $A; +Vue.prototype.$L = $L; +Vue.prototype.$Electron = $A.Electron; +Vue.prototype.$Platform = $A.Platform; +Vue.prototype.$isMainElectron = $A.isMainElectron; +Vue.prototype.$isSubElectron = $A.isSubElectron; +Vue.prototype.$isEEUiApp = $A.isEEUiApp; + +Vue.config.productionTip = false; +Vue.mixin(mixin) + +const app = new Vue({ + el: '#app', + router, + store, + template: '', + components: { App } +}); + +$A.goForward = app.goForward; +$A.goBack = app.goBack; +$A.Message = app.$Message; +$A.Notice = app.$Notice; +$A.Modal = app.$Modal; diff --git a/resources/assets/js/pages/manage/setting/keyboard.vue b/resources/assets/js/pages/manage/setting/keyboard.vue index 2012dbca4..f8aa4a299 100644 --- a/resources/assets/js/pages/manage/setting/keyboard.vue +++ b/resources/assets/js/pages/manage/setting/keyboard.vue @@ -12,7 +12,7 @@ @@ -65,8 +65,13 @@ export default { this.formData_bak = $A.cloneJSON(this.formData); }, - onKeydown({key}) { - this.formData.screenshot_key = key && key.length === 1 ? key.toUpperCase() : "" + onKeydown({key, keyCode}) { + if (keyCode !== 8) { + key = key && key.length === 1 ? key.toUpperCase() : "" + if (key) { + this.formData.screenshot_key = key + } + } }, submitForm() {