From fc4c091f0dec6db6f5fd437fbb9508972ad3c1ff Mon Sep 17 00:00:00 2001 From: gaoshuaixing <530353222@qq.com> Date: Tue, 12 Oct 2021 16:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=B1=8F=E5=B9=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/ipc/example.js | 71 ++++++++++++++++++- frontend/src/config/router.config.js | 7 +- frontend/src/layouts/DemoMenu.vue | 8 ++- .../src/views/demo/notification/Index.vue | 4 +- .../src/views/demo/powermonitor/Index.vue | 4 +- frontend/src/views/demo/screen/Index.vue | 66 +++++++++++++++++ frontend/src/views/demo/window/Index.vue | 4 +- 7 files changed, 153 insertions(+), 11 deletions(-) create mode 100644 frontend/src/views/demo/screen/Index.vue diff --git a/electron/ipc/example.js b/electron/ipc/example.js index 53ecf1a..94c51e8 100644 --- a/electron/ipc/example.js +++ b/electron/ipc/example.js @@ -9,7 +9,7 @@ * @param arg 接收到的消息 */ -const {app, dialog, BrowserWindow, BrowserView, Notification, powerMonitor} = require('electron'); +const {app, dialog, BrowserWindow, BrowserView, Notification, powerMonitor, screen} = require('electron'); const path = require('path'); const _ = require('lodash'); @@ -108,7 +108,7 @@ exports.removeViewContent = function () { /** * 打开新窗口 */ - exports.createWindow = function (event, channel, arg) { +exports.createWindow = function (event, channel, arg) { let content = null; if (arg.type == 'html') { content = path.join('file://', app.getAppPath(), arg.content) @@ -130,7 +130,7 @@ exports.removeViewContent = function () { /** * 创建系统通知 */ - exports.sendNotification = function (event, channel, arg) { +exports.sendNotification = function (event, channel, arg) { if (!Notification.isSupported()) { return '当前系统不支持通知'; } @@ -213,4 +213,69 @@ exports.initPowerMonitor = function (event, channel, arg) { }); return true +} + +/** + * 获取屏幕信息 + */ +exports.getScreen = function (event, channel, arg) { + + let data = []; + let res = {}; + if (arg == 0) { + let res = screen.getCursorScreenPoint(); + data = [ + { + title: '横坐标', + desc: res.x + }, + { + title: '纵坐标', + desc: res.y + }, + ] + + return data; + } + if (arg == 1) { + res = screen.getPrimaryDisplay(); + } + if (arg == 2) { + let resArr = screen.getAllDisplays(); + // 数组,只取一个吧 + res = resArr[0]; + } + // console.log('[electron] [ipc] [example] [getScreen] res:', res); + data = [ + { + title: '分辨率', + desc: res.bounds.width + ' x ' + res.bounds.height + }, + { + title: '单色显示器', + desc: res.monochrome ? '是' : '否' + }, + { + title: '色深', + desc: res. colorDepth + }, + { + title: '色域', + desc: res.colorSpace + }, + { + title: 'scaleFactor', + desc: res.scaleFactor + }, + { + title: '加速器', + desc: res.accelerometerSupport + }, + { + title: '触控', + desc: res.touchSupport == 'unknown' ? '不支持' : '支持' + }, + ] + + return data; } \ No newline at end of file diff --git a/frontend/src/config/router.config.js b/frontend/src/config/router.config.js index 72151b2..efcd6bc 100644 --- a/frontend/src/config/router.config.js +++ b/frontend/src/config/router.config.js @@ -47,7 +47,12 @@ export const constantRouterMap = [ path: '/demo/powermonitor/index', name: 'DemoPowerMonitorIndex', component: () => import('@/views/demo/powermonitor/Index') - }, + }, + { + path: '/demo/screen/index', + name: 'DemoScreenIndex', + component: () => import('@/views/demo/screen/Index') + }, { path: '/demo/shortcut/index', name: 'DemoShortcutIndex', diff --git a/frontend/src/layouts/DemoMenu.vue b/frontend/src/layouts/DemoMenu.vue index dd7d8c5..f7a231b 100644 --- a/frontend/src/layouts/DemoMenu.vue +++ b/frontend/src/layouts/DemoMenu.vue @@ -59,7 +59,13 @@ export default { title: '电源监控', pageName: 'DemoPowerMonitorIndex', params: {} - }, + }, + 'menu_404' : { + icon: 'profile', + title: '屏幕信息', + pageName: 'DemoScreenIndex', + params: {} + }, 'menu_500' : { icon: 'profile', title: '软件调用', diff --git a/frontend/src/views/demo/notification/Index.vue b/frontend/src/views/demo/notification/Index.vue index 5a8b281..793b843 100644 --- a/frontend/src/views/demo/notification/Index.vue +++ b/frontend/src/views/demo/notification/Index.vue @@ -1,5 +1,5 @@