suport win

This commit is contained in:
muwoo 2021-07-30 18:01:54 +08:00
parent f0b9cb2f5d
commit dade771985
5 changed files with 20 additions and 11 deletions

View File

@ -88,6 +88,9 @@
"vuex": "^3.0.1", "vuex": "^3.0.1",
"vuex-electron": "^1.0.0" "vuex-electron": "^1.0.0"
}, },
"optionalDependencies": {
"win-mouse": "git+https://github.com/Toinane/win-mouse"
},
"devDependencies": { "devDependencies": {
"ajv": "^6.5.0", "ajv": "^6.5.0",
"babel-core": "^6.26.3", "babel-core": "^6.26.3",

View File

@ -57,7 +57,6 @@ global.opConfig = {
config: null, config: null,
get() { get() {
const platform = os.type(); const platform = os.type();
console.log(platform);
try { try {
if (!opConfig.config) { if (!opConfig.config) {
opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform])); opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform]));

View File

@ -11,6 +11,7 @@ const {picker, separator, superPanel} = browsers;
class Listener { class Listener {
constructor() { constructor() {
this.optionPlugin = {}; this.optionPlugin = {};
this.isWin = process.platform === 'win32';
} }
getSelectedContent() { getSelectedContent() {
@ -31,7 +32,6 @@ class Listener {
// 延时一定时间才能从剪切板内读取到内容 // 延时一定时间才能从剪切板内读取到内容
const text = clipboard.readText('clipboard') || '' const text = clipboard.readText('clipboard') || ''
const fileUrl = clipboard.read('public.file-url'); const fileUrl = clipboard.read('public.file-url');
// 如果之前是文案,则回填 // 如果之前是文案,则回填
clipboard.writeText(lastText); clipboard.writeText(lastText);
@ -103,15 +103,15 @@ class Listener {
ipcMain.on('start-picker', () => { ipcMain.on('start-picker', () => {
// 开启输入侦测 // 开启输入侦测
ioHook.start(false); ioHook.start(false);
ioHook.load(); !this.isWin && ioHook.load();
picker.init(); picker.init();
picker.getWindow().on('close', () => { picker.getWindow().on('close', () => {
ioHook.stop(); ioHook.stop();
ioHook.unload(); !this.isWin && ioHook.unload();
}); });
let pos = robot.getMousePos(); let pos = this.getPos(robot.getMousePos());
picker picker
.getWindow() .getWindow()
.setPosition(parseInt(pos.x) + 10, parseInt(pos.y) + 10); .setPosition(parseInt(pos.x) + 10, parseInt(pos.y) + 10);
@ -139,8 +139,7 @@ class Listener {
}); });
}); });
ioHook.on('mousemove', e => { ioHook.on('mousemove', e => {
let x = e.x let {x, y} = this.getPos(e);
let y = e.y
if (!picker.getWindow()) return; if (!picker.getWindow()) return;
picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10); picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10);
this.fn(e, picker); this.fn(e, picker);
@ -192,6 +191,7 @@ class Listener {
superPanel(mainWindow) { superPanel(mainWindow) {
// 长按右击呼起超级面板 // 长按右击呼起超级面板
ipcMain.on('right-down', async () => { ipcMain.on('right-down', async () => {
const copyResult = await this.getSelectedContent(); const copyResult = await this.getSelectedContent();
let win = superPanel.getWindow(); let win = superPanel.getWindow();
@ -211,12 +211,16 @@ class Listener {
}); });
}); });
} }
const pos = robot.getMousePos(); const pos = this.getPos(robot.getMousePos());
win.setPosition(parseInt(pos.x), parseInt(pos.y)); win.setPosition(parseInt(pos.x), parseInt(pos.y));
win.show(); win.show();
}); });
} }
getPos(point) {
return this.isWin ? screen.screenToDipPoint({x: point.x, y: point.y}) : point;
}
reRegisterShortCut(mainWindow) { reRegisterShortCut(mainWindow) {
ipcMain.on('re-register', (event, arg) => { ipcMain.on('re-register', (event, arg) => {
this.registerShortCut(mainWindow); this.registerShortCut(mainWindow);
@ -257,7 +261,10 @@ class Listener {
initCapture() { initCapture() {
ipcMain.on('capture-screen', () => { ipcMain.on('capture-screen', () => {
spawn('/usr/sbin/screencapture', ["-c", "-i", "-r"], {detached: !0}); if (process.platform === 'darwin') {
spawn('/usr/sbin/screencapture', ["-c", "-i", "-r"], {detached: !0});
}
// todo win
}); });
} }
} }

View File

@ -1,6 +1,6 @@
<template> <template>
<a-layout id="components-layout"> <a-layout id="components-layout">
<div v-if="!searchType" class="rubick-select" @click="alert(123123)"> <div v-if="!searchType" class="rubick-select">
<div class="tag-container" v-if="selected"> <div class="tag-container" v-if="selected">
<a-tag <a-tag
:key="selected.key" :key="selected.key"

View File

@ -22,7 +22,7 @@ function getQueryVariable(variable) {
if (location.href.indexOf('targetFile') > -1) { if (location.href.indexOf('targetFile') > -1) {
filePath = decodeURIComponent(getQueryVariable('targetFile')); filePath = decodeURIComponent(getQueryVariable('targetFile'));
} else { } else {
filePath = location.pathname.replace('file://', ''); filePath = process.platform === 'win32' ? location.pathname.split(':')[1] : location.pathname.replace('file://', '');
} }
const {ipcRenderer, nativeImage, clipboard, remote, shell} = require('electron'); const {ipcRenderer, nativeImage, clipboard, remote, shell} = require('electron');