diff --git a/package.json b/package.json index e8d6b21..7c4a1e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rubick2", - "version": "0.0.3-beta.4", + "version": "0.0.3-beta.5", "author": "muwoo <2424880409@qq.com>", "description": "An electron-vue project", "license": null, @@ -81,6 +81,7 @@ "robotjs": "git+https://github.com/Toinane/robotjs.git", "semver": "^7.3.5", "sudo-prompt": "^9.2.1", + "systeminformation": "^5.8.0", "unzip": "^0.1.11", "uuid": "^8.3.2", "vue": "^2.5.16", diff --git a/src/main/common/icons/charger.png b/src/main/common/icons/charger.png new file mode 100644 index 0000000..be8f64f Binary files /dev/null and b/src/main/common/icons/charger.png differ diff --git a/src/main/common/icons/chip.png b/src/main/common/icons/chip.png new file mode 100644 index 0000000..20d1e4d Binary files /dev/null and b/src/main/common/icons/chip.png differ diff --git a/src/main/common/icons/hard-disk-drive.png b/src/main/common/icons/hard-disk-drive.png new file mode 100644 index 0000000..fe0bf9e Binary files /dev/null and b/src/main/common/icons/hard-disk-drive.png differ diff --git a/src/main/common/icons/internet.png b/src/main/common/icons/internet.png new file mode 100644 index 0000000..32ba236 Binary files /dev/null and b/src/main/common/icons/internet.png differ diff --git a/src/main/common/icons/power.png b/src/main/common/icons/power.png new file mode 100644 index 0000000..c4ff4c0 Binary files /dev/null and b/src/main/common/icons/power.png differ diff --git a/src/main/common/icons/ram.png b/src/main/common/icons/ram.png new file mode 100644 index 0000000..85ec3ff Binary files /dev/null and b/src/main/common/icons/ram.png differ diff --git a/src/main/common/listener.js b/src/main/common/listener.js index 7c20953..d6aada4 100644 --- a/src/main/common/listener.js +++ b/src/main/common/listener.js @@ -6,6 +6,7 @@ import ioHook from 'iohook'; import {throttle, commonConst} from './utils'; import path from 'path'; import fs from "fs"; +import mito from './monitor'; const browsers = require("../browsers")(); const {picker, separator, superPanel} = browsers; @@ -85,7 +86,13 @@ class Listener { init(mainWindow) { this.fn = throttle(({x, y}, picker) => { - const img = robot.screen.capture(parseInt(x) - 5, parseInt(y) - 5, 9, 9); + const { scaleFactor } = screen.getDisplayNearestPoint({x, y}); + const img = robot.screen.capture( + x - parseInt(5 / scaleFactor), + y - parseInt(5 / scaleFactor), + 10, + 10 + ); const colors = {} @@ -233,10 +240,21 @@ class Listener { showCloseButton: true }); + const monitor = new TouchBarPopover({ + items: mito.touchBar, + label: '系统监控', + showCloseButton: true + }); + const touchBar = new TouchBar({ - items: [plugin, ...system] + items: [ + plugin, + monitor, + ...system + ] }); mainWindow.setTouchBar(touchBar); + mito.start(mainWindow); }); } diff --git a/src/main/common/monitor.js b/src/main/common/monitor.js new file mode 100644 index 0000000..8ef56a0 --- /dev/null +++ b/src/main/common/monitor.js @@ -0,0 +1,124 @@ +const {TouchBar} = require('electron') +const path = require('path') +const si = require('systeminformation'); +const spawn = require('child_process').spawn; + +const {TouchBarButton, TouchBarSpacer} = TouchBar; + +const LOAD_NORMAL = "#2ecc71"; +const LOAD_MEDIUM = "#f1c40f"; +const LOAD_HIGH = "#d35400"; +const LOAD_SEVERE = "#e74c3c"; + +const cpu = new TouchBarButton({ + label: '', + backgroundColor: "#bdc3c7", + icon: path.join(__dirname, 'icons/chip.png'), + iconPosition: "left", + click: () => { + spawn("/System/Applications/Utilities/Activity Monitor.app/Contents/MacOS/Activity\ Monitor", []); + } +}); + +const memory = new TouchBarButton({ + label: '', + backgroundColor: "#bdc3c7", + icon: path.join(__dirname, 'icons/ram.png'), + iconPosition: "left" +}); + +const network = new TouchBarButton({ + label: '', + backgroundColor: '#3498db', + icon: path.join(__dirname, 'icons/internet.png'), + iconPosition: "left" +}); + +const battery = new TouchBarButton({ + label: '', + backgroundColor: "#bdc3c7", + icon: path.join(__dirname, 'icons/power.png'), + iconPosition: "left" +}); + +const updateData = () => { + si.currentLoad(function(data) { + if (typeof data !== 'undefined' && data){ + const load = data.currentLoad.toFixed(0) + cpu.label = load+"%" + if (load <= 20) cpu.backgroundColor = LOAD_NORMAL; + else if (load > 20 && load <= 40) cpu.backgroundColor = LOAD_MEDIUM; + else if (load > 40 && load <= 80) cpu.backgroundColor = LOAD_HIGH; + else if (load > 80 && load <= 100) cpu.backgroundColor = LOAD_SEVERE; + } + }) + si.mem(function(data) { + if (typeof data !== 'undefined' && data){ + const load = ((100* data.active ) / data.total).toFixed(0) + memory.label = load+"%" + if (load <= 20) memory.backgroundColor = LOAD_NORMAL; + else if (load > 20 && load <= 40) memory.backgroundColor = LOAD_MEDIUM; + else if (load > 40 && load <= 80) memory.backgroundColor = LOAD_HIGH; + else if (load > 80 && load <= 100) memory.backgroundColor = LOAD_SEVERE; + } + + }) + si.networkStats("", function(data) { + if (typeof data !== 'undefined' && data){ + const kbtx = (data[0].tx_sec * 0.001).toFixed(0) + const kbrx = (data[0].rx_sec * 0.001).toFixed(0) + const l = (kbtx+kbrx).toString().length + + network.label = "⇡"+ (kbtx*0.001).toFixed(2) + +" ⇣"+ (kbrx*0.001).toFixed(2) +" MB/s" + + } + }) + + si.battery( function(data) { + if (typeof data !== 'undefined' && data){ + if (data.ischarging){ + battery.icon = path.join(__dirname, 'icons/charger.png') + }else{ + battery.icon = path.join(__dirname, 'icons/power.png') + } + const load = data.percent.toFixed(0) + battery.label = load+"%" + if (load <= 20) battery.backgroundColor = LOAD_SEVERE; + else if (load > 20 && load <= 40) battery.backgroundColor = LOAD_HIGH; + else if (load > 40 && load <= 80) battery.backgroundColor = LOAD_MEDIUM; + else if (load > 80 && load <= 100) battery.backgroundColor = LOAD_NORMAL + } + }) +} + +const touchBar = new TouchBar({ + items: [ + cpu, + new TouchBarSpacer({size: 'small'}), + memory, + new TouchBarSpacer({size: 'small'}), + network, + new TouchBarSpacer({size: 'small'}), + battery, + ] +}) + +let intervalObj; + +const start = (window) => { + window.on('blur', () => { + clearInterval(intervalObj); + }); + window.on('focus', () => { + intervalObj = setInterval(() => { + updateData(); + }, 1000); + }); + updateData(); +} + +export default { + start, + touchBar, +} diff --git a/static/plugins/superPanel/index.js b/static/plugins/superPanel/index.js index 8b7148f..de0b64f 100644 --- a/static/plugins/superPanel/index.js +++ b/static/plugins/superPanel/index.js @@ -4,6 +4,7 @@ const path = require('path'); const fs = require('fs'); const { spawn } = require ('child_process'); const mineType = require("mime-types"); +const {extend} = require('../../utils'); new Vue({ el: '#app', @@ -116,7 +117,8 @@ new Vue({ this.targetOptions = this.options.common; } else { // 有文件选择 - this.targetOptions = JSON.parse(JSON.stringify(this.options.selected)); + this.targetOptions = []; + extend(this.targetOptions, this.options.selected, true); // 检测上传 (this.selectData.optionPlugin || []).forEach(plugin => { plugin.features.forEach(fe => { diff --git a/static/utils.js b/static/utils.js index 581fb21..a2b6024 100644 --- a/static/utils.js +++ b/static/utils.js @@ -20,8 +20,31 @@ function getData(path, defaultValue) { } } +const isArray = Array.isArray || + function(object){ return object instanceof Array } + +function isPlainObject(obj) { + return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype +} + +function isObject(obj) { return typeof obj == "object" } + + +function extend(target, source, deep) { + for (let key in source) + if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { + if (isPlainObject(source[key]) && !isPlainObject(target[key])) + target[key] = {} + if (isArray(source[key]) && !isArray(target[key])) + target[key] = [] + extend(target[key], source[key], deep) + } + else if (source[key] !== undefined) target[key] = source[key] +} + module.exports = { getlocalDataFile, saveData, - getData + getData, + extend }