mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-29 22:39:45 +08:00
feat: 支持文本模板,系统命令
This commit is contained in:
4
src/main/browsers/index.js
Normal file
4
src/main/browsers/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = () => ({
|
||||
picker: require("./picker")(),
|
||||
separator: require("./separate")(),
|
||||
});
|
||||
42
src/main/browsers/picker.js
Normal file
42
src/main/browsers/picker.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const { BrowserWindow, nativeImage } = require("electron");
|
||||
|
||||
module.exports = () => {
|
||||
let win;
|
||||
|
||||
let init = () => {
|
||||
if (win === null || win === undefined) {
|
||||
createWindow();
|
||||
}
|
||||
};
|
||||
|
||||
let createWindow = () => {
|
||||
win = new BrowserWindow({
|
||||
frame: false,
|
||||
autoHideMenuBar: true,
|
||||
width: 100,
|
||||
height: 100,
|
||||
transparent: true,
|
||||
alwaysOnTop: true,
|
||||
resizable: false,
|
||||
focusable: true,
|
||||
hasShadow: false,
|
||||
// icon: nativeImage.createFromPath(`${dirname}/build/icon.png`),
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
devTools: false,
|
||||
},
|
||||
});
|
||||
|
||||
win.loadURL(`file://${__static}/plugins/picker/index.html`);
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
};
|
||||
|
||||
let getWindow = () => win;
|
||||
|
||||
return {
|
||||
init: init,
|
||||
getWindow: getWindow,
|
||||
};
|
||||
};
|
||||
46
src/main/browsers/separate.js
Normal file
46
src/main/browsers/separate.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const {stringify} = require('query-string');
|
||||
const { BrowserWindow, nativeImage } = require("electron");
|
||||
|
||||
module.exports = () => {
|
||||
let win;
|
||||
|
||||
let init = (opts) => {
|
||||
createWindow(opts);
|
||||
};
|
||||
|
||||
let createWindow = (opts) => {
|
||||
const winURL = process.env.NODE_ENV === 'development'
|
||||
? `http://localhost:9080/#/plugin?${stringify(opts)}`
|
||||
: `${__dirname}/index.html`
|
||||
win = new BrowserWindow({
|
||||
height: 600,
|
||||
useContentSize: true,
|
||||
width: 800,
|
||||
titleBarStyle: 'hiddenInset',
|
||||
title: '拉比克',
|
||||
show: false,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
webviewTag: true,
|
||||
nodeIntegration: true // 在网页中集成Node
|
||||
}
|
||||
});
|
||||
|
||||
process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, {
|
||||
hash: `#/plugin?${stringify(opts)}`,
|
||||
});
|
||||
win.once('ready-to-show', () => win.show());
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
};
|
||||
|
||||
let getWindow = () => win;
|
||||
|
||||
return {
|
||||
init: init,
|
||||
getWindow: getWindow,
|
||||
};
|
||||
};
|
||||
@@ -1,71 +0,0 @@
|
||||
import {globalShortcut, ipcMain, BrowserWindow} from 'electron';
|
||||
import {stringify} from 'query-string';
|
||||
import Api from './api';
|
||||
import path from 'path';
|
||||
|
||||
export default function init(mainWindow) {
|
||||
ipcMain.on('changeWindowSize', (event, arg) => {
|
||||
mainWindow.setSize(arg.width || 788, arg.height);
|
||||
});
|
||||
|
||||
mainWindow.on('blur', () => {
|
||||
// mainWindow.hide();
|
||||
});
|
||||
|
||||
globalShortcut.register('Alt+R', () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
ipcMain.on('init-shortcut', (event) => {
|
||||
globalShortcut.register('Esc', () => {
|
||||
mainWindow.show();
|
||||
event.sender.send('init-rubick');
|
||||
});
|
||||
globalShortcut.register('ctrl+d', () => {
|
||||
event.sender.send('new-window');
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
ipcMain.on('msg-trigger', async (event, arg) => {
|
||||
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow
|
||||
const operators = arg.type.split('.');
|
||||
let fn = Api;
|
||||
operators.forEach((op) => {
|
||||
fn = fn[op];
|
||||
});
|
||||
const data = await fn(arg, window);
|
||||
event.sender.send(`msg-back-${arg.type}`, data);
|
||||
});
|
||||
|
||||
ipcMain.on('new-window', (event, arg) => {
|
||||
const opts = {
|
||||
...arg,
|
||||
searchType: 'subWindow',
|
||||
}
|
||||
const winURL = process.env.NODE_ENV === 'development'
|
||||
? `http://localhost:9080/#/plugin?${stringify(opts)}`
|
||||
: `${__dirname}/index.html`
|
||||
const win = new BrowserWindow({
|
||||
height: 600,
|
||||
useContentSize: true,
|
||||
width: 788,
|
||||
titleBarStyle: 'hiddenInset',
|
||||
title: '拉比克',
|
||||
show: false,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
webviewTag: true,
|
||||
nodeIntegration: true // 在网页中集成Node
|
||||
}
|
||||
});
|
||||
process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, {
|
||||
hash: `#/plugin?${stringify(opts)}`,
|
||||
});
|
||||
win.once('ready-to-show', () => win.show());
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {app, BrowserWindow} from 'electron';
|
||||
import {getlocalDataFile, saveData, getData} from './common/utils';
|
||||
import {getlocalDataFile, saveData, getData} from './utils';
|
||||
import path from "path";
|
||||
|
||||
const puppeteer = require("puppeteer-core");
|
||||
112
src/main/common/common.js
Normal file
112
src/main/common/common.js
Normal file
@@ -0,0 +1,112 @@
|
||||
import {
|
||||
globalShortcut,
|
||||
ipcMain,
|
||||
BrowserWindow,
|
||||
clipboard,
|
||||
Notification,
|
||||
} from 'electron';
|
||||
import Api from './api';
|
||||
import robot from 'robotjs';
|
||||
|
||||
const browsers = require("../browsers")();
|
||||
const mouseEvents = require("osx-mouse");
|
||||
const {picker, separator} = browsers;
|
||||
|
||||
let closePicker = (newColor) => {
|
||||
if (picker.getWindow()) {
|
||||
ipcMain.removeListener("closePicker", closePicker);
|
||||
ipcMain.removeListener("pickerRequested", (event) => {});
|
||||
picker.getWindow().close();
|
||||
}
|
||||
};
|
||||
|
||||
export default function init(mainWindow) {
|
||||
const mouseTrack = mouseEvents();
|
||||
let down_time = 0;
|
||||
mouseTrack.on('right-down', () => {
|
||||
down_time = Date.now();
|
||||
})
|
||||
mouseTrack.on('right-up', () => {
|
||||
if ((Date.now() - down_time) > 1000) {
|
||||
new Notification({ title: 'Rubick 通知', body: '长按了' }).show();
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('changeWindowSize-rubick', (event, arg) => {
|
||||
mainWindow.setSize(arg.width || 788, arg.height);
|
||||
});
|
||||
|
||||
mainWindow.on('blur', () => {
|
||||
// mainWindow.hide();
|
||||
});
|
||||
|
||||
globalShortcut.register('Alt+R', () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
ipcMain.on('init-shortcut', (event) => {
|
||||
globalShortcut.register('Esc', () => {
|
||||
mainWindow.show();
|
||||
event.sender.send('init-rubick');
|
||||
});
|
||||
globalShortcut.register('ctrl+d', () => {
|
||||
event.sender.send('new-window');
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
ipcMain.on('msg-trigger', async (event, arg) => {
|
||||
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow
|
||||
const operators = arg.type.split('.');
|
||||
let fn = Api;
|
||||
operators.forEach((op) => {
|
||||
fn = fn[op];
|
||||
});
|
||||
const data = await fn(arg, window);
|
||||
window.webContents.send(`msg-back-${arg.type}`, data);
|
||||
});
|
||||
|
||||
ipcMain.on('new-window', (event, arg) => {
|
||||
const opts = {
|
||||
...arg,
|
||||
searchType: 'subWindow',
|
||||
}
|
||||
separator.init(opts);
|
||||
});
|
||||
|
||||
ipcMain.on('start-picker', () => {
|
||||
const mouseTrack = mouseEvents();
|
||||
picker.init();
|
||||
picker.getWindow().on("close", () => {
|
||||
mouseTrack.destroy();
|
||||
});
|
||||
mouseTrack.on('move', (x, y) => {
|
||||
if (!picker.getWindow()) return;
|
||||
let color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
|
||||
picker.getWindow().setPosition(parseInt(x) - 50, parseInt(y) - 50);
|
||||
picker.getWindow().webContents.send("updatePicker", color);
|
||||
})
|
||||
mouseTrack.on("left-up", (x, y) => {
|
||||
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
|
||||
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y)));
|
||||
new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show();
|
||||
closePicker();
|
||||
});
|
||||
let pos = robot.getMousePos();
|
||||
picker
|
||||
.getWindow()
|
||||
.setPosition(parseInt(pos.x) - 50, parseInt(pos.y) - 50);
|
||||
|
||||
picker
|
||||
.getWindow()
|
||||
.webContents.send(
|
||||
"updatePicker",
|
||||
robot.getPixelColor(pos.x, pos.y)
|
||||
);
|
||||
|
||||
ipcMain.on("closePicker", closePicker);
|
||||
mouseTrack.on("right-up", closePicker);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { app, BrowserWindow, protocol } from 'electron'
|
||||
import '../renderer/store'
|
||||
import init from './common';
|
||||
import init from './common/common';
|
||||
import createTray from './tray';
|
||||
/**
|
||||
* Set `__static` path to static files in production
|
||||
|
||||
Reference in New Issue
Block a user