Skip to content

Commit

Permalink
bugfix: #45, #40
Browse files Browse the repository at this point in the history
  • Loading branch information
muwoo committed Sep 16, 2021
1 parent 511b357 commit 1eeb0fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubick2",
"version": "0.0.6",
"version": "0.0.6-beta.1",
"author": "muwoo <2424880409@qq.com>",
"description": "An electron-vue project",
"license": null,
Expand Down
32 changes: 22 additions & 10 deletions src/main/common/listener.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import {app, nativeImage, BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen, TouchBar} from "electron";
import {
app,
nativeImage,
BrowserWindow,
clipboard,
globalShortcut,
ipcMain,
Notification,
screen,
TouchBar
} from 'electron';
import {exec, spawn} from "child_process";
import robot from "robotjs";
import Api from "./api";
Expand Down Expand Up @@ -54,7 +64,7 @@ class Listener {
// 注册偏好快捷键
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
const {x, y} = screen.getCursorScreenPoint();
const currentDisplay = screen.getDisplayNearestPoint({ x, y });
const currentDisplay = screen.getDisplayNearestPoint({x, y});
const wx = parseInt(currentDisplay.workArea.x + currentDisplay.workArea.width / 2 - 400);
const wy = parseInt(currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200);

Expand Down Expand Up @@ -86,7 +96,7 @@ class Listener {

init(mainWindow) {
this.fn = throttle(({x, y}, picker) => {
const { scaleFactor } = screen.getDisplayNearestPoint({x, y});
const {scaleFactor} = screen.getDisplayNearestPoint({x, y});
const img = robot.screen.capture(
x - parseInt(5 / scaleFactor),
y - parseInt(5 / scaleFactor),
Expand All @@ -96,7 +106,7 @@ class Listener {

const colors = {}

for(let i = 0; i< 9; i++) {
for (let i = 0; i < 9; i++) {
colors[i] = {};
for (let j = 0; j < 9; j++) {
colors[i][j] = img.colorAt(j, i);
Expand Down Expand Up @@ -142,7 +152,7 @@ class Listener {

const colors = {}

for(let i = 0; i< 9; i++) {
for (let i = 0; i < 9; i++) {
colors[i] = {};
for (let j = 0; j < 9; j++) {
colors[i][j] = img.colorAt(j, i);
Expand Down Expand Up @@ -173,7 +183,7 @@ class Listener {
let y = e.y
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y)));
new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show();
new Notification({title: 'Rubick 通知', body: `${color} 已保存到剪切板`}).show();
this.closePicker();
}
});
Expand All @@ -195,7 +205,7 @@ class Listener {

initTouchBar(mainWindow) {
if (!commonConst.macOS()) return;
const { TouchBarButton, TouchBarGroup, TouchBarPopover } = TouchBar;
const {TouchBarButton, TouchBarGroup, TouchBarPopover} = TouchBar;
let items = [];
let system = [];
ipcMain.on('pluginInit', (e, args) => {
Expand All @@ -218,7 +228,7 @@ class Listener {
}).filter(Boolean);

system = args.plugins.map((item) => {
if(item.type === 'system') {
if (item.type === 'system') {
return new TouchBarButton({
icon: nativeImage.createFromDataURL(item.logo).resize({width: 20, height: 20}),
click() {
Expand Down Expand Up @@ -364,6 +374,7 @@ class Listener {
windowMoveInit(win) {
let hasInit = false;
ipcMain.on('window-move', () => {
let bounds = win.getBounds();
if (!hasInit) {
hasInit = true;
ioHook.start(false);
Expand All @@ -377,8 +388,9 @@ class Listener {
const cursorPosition = screen.getCursorScreenPoint();
const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
let {x, y} = {x: dx, y: dy};
win.setPosition(parseInt(x), parseInt(y));
bounds.x = parseInt(dx);
bounds.y = parseInt(dy);
win.setBounds(bounds);
});

ioHook.on('mouseup', e => {
Expand Down

0 comments on commit 1eeb0fa

Please sign in to comment.