mirror of
https://github.com/rubickCenter/rubick
synced 2025-07-21 23:59:32 +08:00
parent
511b357e28
commit
1eeb0fad9a
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rubick2",
|
"name": "rubick2",
|
||||||
"version": "0.0.6",
|
"version": "0.0.6-beta.1",
|
||||||
"author": "muwoo <2424880409@qq.com>",
|
"author": "muwoo <2424880409@qq.com>",
|
||||||
"description": "An electron-vue project",
|
"description": "An electron-vue project",
|
||||||
"license": null,
|
"license": null,
|
||||||
|
@ -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 {exec, spawn} from "child_process";
|
||||||
import robot from "robotjs";
|
import robot from "robotjs";
|
||||||
import Api from "./api";
|
import Api from "./api";
|
||||||
@ -54,7 +64,7 @@ class Listener {
|
|||||||
// 注册偏好快捷键
|
// 注册偏好快捷键
|
||||||
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
|
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
|
||||||
const {x, y} = screen.getCursorScreenPoint();
|
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 wx = parseInt(currentDisplay.workArea.x + currentDisplay.workArea.width / 2 - 400);
|
||||||
const wy = parseInt(currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200);
|
const wy = parseInt(currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200);
|
||||||
|
|
||||||
@ -86,7 +96,7 @@ class Listener {
|
|||||||
|
|
||||||
init(mainWindow) {
|
init(mainWindow) {
|
||||||
this.fn = throttle(({x, y}, picker) => {
|
this.fn = throttle(({x, y}, picker) => {
|
||||||
const { scaleFactor } = screen.getDisplayNearestPoint({x, y});
|
const {scaleFactor} = screen.getDisplayNearestPoint({x, y});
|
||||||
const img = robot.screen.capture(
|
const img = robot.screen.capture(
|
||||||
x - parseInt(5 / scaleFactor),
|
x - parseInt(5 / scaleFactor),
|
||||||
y - parseInt(5 / scaleFactor),
|
y - parseInt(5 / scaleFactor),
|
||||||
@ -96,7 +106,7 @@ class Listener {
|
|||||||
|
|
||||||
const colors = {}
|
const colors = {}
|
||||||
|
|
||||||
for(let i = 0; i< 9; i++) {
|
for (let i = 0; i < 9; i++) {
|
||||||
colors[i] = {};
|
colors[i] = {};
|
||||||
for (let j = 0; j < 9; j++) {
|
for (let j = 0; j < 9; j++) {
|
||||||
colors[i][j] = img.colorAt(j, i);
|
colors[i][j] = img.colorAt(j, i);
|
||||||
@ -142,7 +152,7 @@ class Listener {
|
|||||||
|
|
||||||
const colors = {}
|
const colors = {}
|
||||||
|
|
||||||
for(let i = 0; i< 9; i++) {
|
for (let i = 0; i < 9; i++) {
|
||||||
colors[i] = {};
|
colors[i] = {};
|
||||||
for (let j = 0; j < 9; j++) {
|
for (let j = 0; j < 9; j++) {
|
||||||
colors[i][j] = img.colorAt(j, i);
|
colors[i][j] = img.colorAt(j, i);
|
||||||
@ -173,7 +183,7 @@ class Listener {
|
|||||||
let y = e.y
|
let y = e.y
|
||||||
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
|
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
|
||||||
clipboard.writeText("#" + 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();
|
this.closePicker();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -195,7 +205,7 @@ class Listener {
|
|||||||
|
|
||||||
initTouchBar(mainWindow) {
|
initTouchBar(mainWindow) {
|
||||||
if (!commonConst.macOS()) return;
|
if (!commonConst.macOS()) return;
|
||||||
const { TouchBarButton, TouchBarGroup, TouchBarPopover } = TouchBar;
|
const {TouchBarButton, TouchBarGroup, TouchBarPopover} = TouchBar;
|
||||||
let items = [];
|
let items = [];
|
||||||
let system = [];
|
let system = [];
|
||||||
ipcMain.on('pluginInit', (e, args) => {
|
ipcMain.on('pluginInit', (e, args) => {
|
||||||
@ -218,7 +228,7 @@ class Listener {
|
|||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
|
|
||||||
system = args.plugins.map((item) => {
|
system = args.plugins.map((item) => {
|
||||||
if(item.type === 'system') {
|
if (item.type === 'system') {
|
||||||
return new TouchBarButton({
|
return new TouchBarButton({
|
||||||
icon: nativeImage.createFromDataURL(item.logo).resize({width: 20, height: 20}),
|
icon: nativeImage.createFromDataURL(item.logo).resize({width: 20, height: 20}),
|
||||||
click() {
|
click() {
|
||||||
@ -364,6 +374,7 @@ class Listener {
|
|||||||
windowMoveInit(win) {
|
windowMoveInit(win) {
|
||||||
let hasInit = false;
|
let hasInit = false;
|
||||||
ipcMain.on('window-move', () => {
|
ipcMain.on('window-move', () => {
|
||||||
|
let bounds = win.getBounds();
|
||||||
if (!hasInit) {
|
if (!hasInit) {
|
||||||
hasInit = true;
|
hasInit = true;
|
||||||
ioHook.start(false);
|
ioHook.start(false);
|
||||||
@ -377,8 +388,9 @@ class Listener {
|
|||||||
const cursorPosition = screen.getCursorScreenPoint();
|
const cursorPosition = screen.getCursorScreenPoint();
|
||||||
const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
|
const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
|
||||||
const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
|
const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
|
||||||
let {x, y} = {x: dx, y: dy};
|
bounds.x = parseInt(dx);
|
||||||
win.setPosition(parseInt(x), parseInt(y));
|
bounds.y = parseInt(dy);
|
||||||
|
win.setBounds(bounds);
|
||||||
});
|
});
|
||||||
|
|
||||||
ioHook.on('mouseup', e => {
|
ioHook.on('mouseup', e => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user