mirror of
https://github.com/rubickCenter/rubick
synced 2025-07-18 05:17:27 +08:00
commit
74e4956050
@ -1,15 +1,16 @@
|
|||||||
const { BrowserWindow, protocol } = require("electron")
|
const { BrowserWindow, protocol } = require("electron");
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
let win
|
let win;
|
||||||
|
|
||||||
let init = (opts) => {
|
let init = (opts) => {
|
||||||
createWindow(opts)
|
createWindow(opts);
|
||||||
}
|
};
|
||||||
|
|
||||||
let createWindow = (opts) => {
|
let createWindow = (opts) => {
|
||||||
const winURL = process.env.NODE_ENV === 'development'
|
const winURL =
|
||||||
? `http://localhost:9080`
|
process.env.NODE_ENV === "development"
|
||||||
: `file://${__dirname}/index.html`
|
? `http://localhost:9080`
|
||||||
|
: `file://${__dirname}/index.html`;
|
||||||
|
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
height: 60,
|
height: 60,
|
||||||
@ -17,7 +18,7 @@ module.exports = () => {
|
|||||||
resizable: true,
|
resizable: true,
|
||||||
width: 800,
|
width: 800,
|
||||||
frame: false,
|
frame: false,
|
||||||
title: '拉比克',
|
title: "拉比克",
|
||||||
show: false,
|
show: false,
|
||||||
skipTaskbar: true,
|
skipTaskbar: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
@ -26,31 +27,35 @@ module.exports = () => {
|
|||||||
backgroundThrottling: false,
|
backgroundThrottling: false,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true // 在网页中集成Node
|
nodeIntegration: true, // 在网页中集成Node
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
win.loadURL(winURL);
|
||||||
|
|
||||||
|
protocol.interceptFileProtocol(
|
||||||
|
"image",
|
||||||
|
(req, callback) => {
|
||||||
|
const url = req.url.substr(8);
|
||||||
|
callback(decodeURI(url));
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
if (error) {
|
||||||
|
console.error("Failed to register protocol");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
);
|
||||||
|
|
||||||
win.loadURL(winURL)
|
win.once("ready-to-show", () => win.show());
|
||||||
|
|
||||||
protocol.interceptFileProtocol('image', (req, callback) => {
|
|
||||||
const url = req.url.substr(8)
|
|
||||||
callback(decodeURI(url))
|
|
||||||
}, (error) => {
|
|
||||||
if (error) {
|
|
||||||
console.error('Failed to register protocol')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
win.once('ready-to-show', () => win.show())
|
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
win = undefined
|
win = undefined;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
let getWindow = () => win
|
let getWindow = () => win;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init,
|
||||||
getWindow: getWindow,
|
getWindow,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
const { BrowserWindow, nativeImage } = require("electron")
|
const { BrowserWindow, nativeImage } = require("electron");
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
let win
|
let win;
|
||||||
|
|
||||||
let init = (x, y) => {
|
let init = (x, y) => {
|
||||||
if (win === null || win === undefined) {
|
if (win === null || win === undefined) {
|
||||||
createWindow()
|
createWindow();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let createWindow = () => {
|
let createWindow = () => {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
@ -25,18 +25,18 @@ module.exports = () => {
|
|||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
devTools: false,
|
devTools: false,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
win.loadURL(`file://${__static}/plugins/picker/index.html`)
|
win.loadURL(`file://${__static}/plugins/picker/index.html`);
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
win = undefined
|
win = undefined;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
let getWindow = () => win
|
let getWindow = () => win;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init,
|
||||||
getWindow: getWindow,
|
getWindow,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
const { BrowserWindow } = require("electron")
|
const { BrowserWindow } = require("electron");
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
let win
|
let win;
|
||||||
|
|
||||||
let init = (opts) => {
|
let init = (opts) => {
|
||||||
createWindow(opts)
|
createWindow(opts);
|
||||||
}
|
};
|
||||||
|
|
||||||
let createWindow = (opts) => {
|
let createWindow = (opts) => {
|
||||||
const winURL = process.env.NODE_ENV === 'development'
|
const winURL =
|
||||||
? `http://localhost:9080/#/plugin`
|
process.env.NODE_ENV === "development"
|
||||||
: `${__dirname}/index.html`
|
? `http://localhost:9080/#/plugin`
|
||||||
|
: `${__dirname}/index.html`;
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
height: 600,
|
height: 600,
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
width: 800,
|
width: 800,
|
||||||
titleBarStyle: 'hiddenInset',
|
titleBarStyle: "hiddenInset",
|
||||||
title: '拉比克',
|
title: "拉比克",
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
@ -24,26 +25,30 @@ module.exports = () => {
|
|||||||
backgroundThrottling: false,
|
backgroundThrottling: false,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true // 在网页中集成Node
|
nodeIntegration: true, // 在网页中集成Node
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, {
|
process.env.NODE_ENV === "development"
|
||||||
hash: `#/plugin`,
|
? win.loadURL(winURL)
|
||||||
})
|
: win.loadFile(winURL, {
|
||||||
|
hash: `#/plugin`,
|
||||||
|
});
|
||||||
|
|
||||||
win.webContents.executeJavaScript(`window.setPluginInfo(${opts})`).then(() => {
|
win.webContents
|
||||||
win.show()
|
.executeJavaScript(`window.setPluginInfo(${opts})`)
|
||||||
})
|
.then(() => {
|
||||||
|
win.show();
|
||||||
|
});
|
||||||
|
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
win = undefined
|
win = undefined;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
let getWindow = () => win
|
let getWindow = () => win;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init,
|
||||||
getWindow: getWindow,
|
getWindow,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
@ -6,14 +6,14 @@ module.exports = () => {
|
|||||||
let init = (mainWindow) => {
|
let init = (mainWindow) => {
|
||||||
if (win === null || win === undefined) {
|
if (win === null || win === undefined) {
|
||||||
createWindow();
|
createWindow();
|
||||||
ipcMain.on('superPanel-hidden', () => {
|
ipcMain.on("superPanel-hidden", () => {
|
||||||
win.hide();
|
win.hide();
|
||||||
});
|
});
|
||||||
ipcMain.on('superPanel-setSize', (e, height) => {
|
ipcMain.on("superPanel-setSize", (e, height) => {
|
||||||
win.setSize(250, height);
|
win.setSize(250, height);
|
||||||
});
|
});
|
||||||
ipcMain.on('superPanel-openPlugin', (e, args) => {
|
ipcMain.on("superPanel-openPlugin", (e, args) => {
|
||||||
mainWindow.webContents.send('superPanel-openPlugin', args);
|
mainWindow.webContents.send("superPanel-openPlugin", args);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -39,7 +39,7 @@ module.exports = () => {
|
|||||||
win = undefined;
|
win = undefined;
|
||||||
});
|
});
|
||||||
// 打包后,失焦隐藏
|
// 打包后,失焦隐藏
|
||||||
win.on('blur', () => {
|
win.on("blur", () => {
|
||||||
win.hide();
|
win.hide();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -47,7 +47,7 @@ module.exports = () => {
|
|||||||
let getWindow = () => win;
|
let getWindow = () => win;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init,
|
||||||
getWindow: getWindow,
|
getWindow,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {app} from 'electron';
|
import { app } from "electron";
|
||||||
import './config';
|
import "./config";
|
||||||
import Listener from './listener';
|
import Listener from "./listener";
|
||||||
|
import { remote } from "electron";
|
||||||
|
|
||||||
export default function init(mainWindow) {
|
export default function init(mainWindow) {
|
||||||
const listener = new Listener();
|
const listener = new Listener();
|
||||||
@ -16,11 +17,11 @@ export default function init(mainWindow) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 打包后,失焦隐藏
|
// 判断失焦是否隐藏
|
||||||
mainWindow.on('blur', () => {
|
mainWindow.on("blur", () => {
|
||||||
app.isPackaged && mainWindow.hide();
|
const config = { ...opConfig.get() };
|
||||||
|
if (config.perf.common.hideOnBlur) {
|
||||||
|
mainWindow.hide();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,109 +1,76 @@
|
|||||||
import path from "path"
|
import path from "path";
|
||||||
import fs from 'fs'
|
import fs from "fs";
|
||||||
import { getlocalDataFile } from "./utils"
|
import { getLocalDataFile } from "./utils";
|
||||||
import os from 'os'
|
import os from "os";
|
||||||
|
import { app } from "electron";
|
||||||
|
|
||||||
const configPath = path.join(getlocalDataFile(), './rubick-config.json')
|
const configPath = path.join(getLocalDataFile(), "./rubick-config.json");
|
||||||
|
|
||||||
|
const defaultConfigForAnyPlatform = {
|
||||||
|
version: 3,
|
||||||
|
perf: {
|
||||||
|
shortCut: {
|
||||||
|
showAndHidden: "Option+R",
|
||||||
|
separate: "Ctrl+D",
|
||||||
|
quit: "Shift+Escape",
|
||||||
|
},
|
||||||
|
common: {
|
||||||
|
start: true,
|
||||||
|
space: true,
|
||||||
|
// 是否失焦隐藏。默认在dev环境不隐藏,在打包后隐藏。
|
||||||
|
hideOnBlur: app.isPackaged,
|
||||||
|
},
|
||||||
|
local: {
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
superPanel: {
|
||||||
|
baiduAPI: {
|
||||||
|
key: "",
|
||||||
|
appid: "",
|
||||||
|
},
|
||||||
|
mouseDownTime: 500,
|
||||||
|
},
|
||||||
|
global: [],
|
||||||
|
};
|
||||||
|
|
||||||
let defaultConfig = {
|
let defaultConfig = {
|
||||||
Darwin: {
|
Darwin: {
|
||||||
version: 3,
|
...defaultConfigForAnyPlatform,
|
||||||
perf: {
|
|
||||||
shortCut: {
|
|
||||||
showAndHidden: 'Option+R',
|
|
||||||
separate: 'Ctrl+D',
|
|
||||||
quit: 'Shift+Escape'
|
|
||||||
},
|
|
||||||
common: {
|
|
||||||
start: true,
|
|
||||||
space: true,
|
|
||||||
},
|
|
||||||
local: {
|
|
||||||
search: true,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
superPanel: {
|
|
||||||
baiduAPI: {
|
|
||||||
key: '',
|
|
||||||
appid: '',
|
|
||||||
},
|
|
||||||
mouseDownTime: 500
|
|
||||||
},
|
|
||||||
global: []
|
|
||||||
},
|
},
|
||||||
Windows_NT: {
|
Windows_NT: {
|
||||||
version: 3,
|
...defaultConfigForAnyPlatform,
|
||||||
perf: {
|
|
||||||
shortCut: {
|
|
||||||
showAndHidden: 'Option+R',
|
|
||||||
separate: 'Ctrl+D',
|
|
||||||
quit: 'Shift+Escape'
|
|
||||||
},
|
|
||||||
common: {
|
|
||||||
start: true,
|
|
||||||
space: true,
|
|
||||||
},
|
|
||||||
local: {
|
|
||||||
search: true,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
superPanel: {
|
|
||||||
baiduAPI: {
|
|
||||||
key: '',
|
|
||||||
appid: '',
|
|
||||||
},
|
|
||||||
mouseDownTime: 500
|
|
||||||
},
|
|
||||||
global: []
|
|
||||||
},
|
},
|
||||||
Linux: {
|
Linux: {
|
||||||
version: 3,
|
...defaultConfigForAnyPlatform,
|
||||||
perf: {
|
},
|
||||||
shortCut: {
|
};
|
||||||
showAndHidden: 'Option+R',
|
|
||||||
separate: 'Ctrl+D',
|
|
||||||
quit: 'Shift+Escape'
|
|
||||||
},
|
|
||||||
common: {
|
|
||||||
start: true,
|
|
||||||
space: true,
|
|
||||||
},
|
|
||||||
local: {
|
|
||||||
search: true,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
superPanel: {
|
|
||||||
baiduAPI: {
|
|
||||||
key: '',
|
|
||||||
appid: '',
|
|
||||||
},
|
|
||||||
mouseDownTime: 500
|
|
||||||
},
|
|
||||||
global: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
global.opConfig = {
|
global.opConfig = {
|
||||||
config: null,
|
config: null,
|
||||||
get() {
|
get() {
|
||||||
const platform = os.type();
|
const platform = os.type();
|
||||||
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])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// 重置
|
// 重置
|
||||||
if (!opConfig.config.version || opConfig.config.version < defaultConfig[platform].version) {
|
if (
|
||||||
opConfig.config = defaultConfig[platform]
|
!opConfig.config.version ||
|
||||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
|
opConfig.config.version < defaultConfig[platform].version
|
||||||
|
) {
|
||||||
|
opConfig.config = defaultConfig[platform];
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(opConfig.config));
|
||||||
}
|
}
|
||||||
return opConfig.config
|
return opConfig.config;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
opConfig.config = defaultConfig[platform]
|
opConfig.config = defaultConfig[platform];
|
||||||
return opConfig.config
|
return opConfig.config;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(key, value) {
|
set(key, value) {
|
||||||
opConfig.config[key] = value;
|
opConfig.config[key] = value;
|
||||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
|
fs.writeFileSync(configPath, JSON.stringify(opConfig.config));
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
export const getlocalDataFile = () => {
|
export const getLocalDataFile = () => {
|
||||||
let localDataFile = process.env.HOME;
|
let localDataFile = process.env.HOME;
|
||||||
if (!localDataFile) {
|
if (!localDataFile) {
|
||||||
localDataFile = process.env.LOCALAPPDATA;
|
localDataFile = process.env.LOCALAPPDATA;
|
||||||
@ -14,13 +14,13 @@ export function saveData(path, value) {
|
|||||||
|
|
||||||
export function getData(path, defaultValue) {
|
export function getData(path, defaultValue) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(path, 'utf8'));
|
return JSON.parse(fs.readFileSync(path, "utf8"));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return defaultValue || undefined;
|
return defaultValue || undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function throttle (func, wait, options) {
|
export function throttle(func, wait, options) {
|
||||||
let context, args, result;
|
let context, args, result;
|
||||||
let timeout = null;
|
let timeout = null;
|
||||||
let previous = 0;
|
let previous = 0;
|
||||||
@ -54,21 +54,19 @@ export function throttle (func, wait, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const commonConst = {
|
export const commonConst = {
|
||||||
linux: function () {
|
linux: function() {
|
||||||
return process.platform === 'linux'
|
return process.platform === "linux";
|
||||||
},
|
},
|
||||||
macOS () {
|
macOS() {
|
||||||
return process.platform === 'darwin';
|
return process.platform === "darwin";
|
||||||
},
|
},
|
||||||
windows () {
|
windows() {
|
||||||
return process.platform === 'win32'
|
return process.platform === "win32";
|
||||||
},
|
},
|
||||||
production: function () {
|
production: function() {
|
||||||
return process.env.NODE_ENV !== 'development';
|
return process.env.NODE_ENV !== "development";
|
||||||
},
|
},
|
||||||
dev: function () {
|
dev: function() {
|
||||||
return process.env.NODE_ENV === 'development';
|
return process.env.NODE_ENV === "development";
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div @mousedown="drag">
|
<div @mousedown="drag">
|
||||||
<a-layout id="components-layout">
|
<a-layout id="components-layout">
|
||||||
<div v-if="!searchType" class="rubick-select">
|
<div v-if="!searchType" class="rubick-select">
|
||||||
<div class="tag-container" v-if="selected">
|
<div v-if="selected" class="tag-container">
|
||||||
<a-tag
|
<a-tag
|
||||||
:key="selected.key"
|
:key="selected.key"
|
||||||
@close="closeTag"
|
@close="closeTag"
|
||||||
@ -59,7 +59,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a-input>
|
</a-input>
|
||||||
<div class="options" v-show="showOptions">
|
<div v-show="showOptions" class="options">
|
||||||
<a-list item-layout="horizontal" :data-source="options">
|
<a-list item-layout="horizontal" :data-source="options">
|
||||||
<a-list-item
|
<a-list-item
|
||||||
@click="() => item.click($router)"
|
@click="() => item.click($router)"
|
||||||
@ -80,8 +80,20 @@
|
|||||||
</a-list-item>
|
</a-list-item>
|
||||||
</a-list>
|
</a-list>
|
||||||
</div>
|
</div>
|
||||||
|
<span
|
||||||
|
v-show="selected"
|
||||||
|
class="button-hide-on-blur"
|
||||||
|
@click="changeHideOnBlur"
|
||||||
|
>
|
||||||
|
<a-icon
|
||||||
|
type="pushpin"
|
||||||
|
:style="{
|
||||||
|
color: config.perf.common.hideOnBlur ? 'grey' : '#ea68a2',
|
||||||
|
}"
|
||||||
|
></a-icon>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="rubick-select-subMenu" v-else>
|
<div v-else class="rubick-select-subMenu">
|
||||||
<div>
|
<div>
|
||||||
<img
|
<img
|
||||||
class="icon-tool-sub"
|
class="icon-tool-sub"
|
||||||
@ -135,11 +147,10 @@ export default {
|
|||||||
return {
|
return {
|
||||||
query: this.$route.query,
|
query: this.$route.query,
|
||||||
searchFn: null,
|
searchFn: null,
|
||||||
config: opConfig.get(),
|
config: { ...opConfig.get() },
|
||||||
currentSelect: 0,
|
currentSelect: 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
window.setPluginInfo = (pluginInfo) => {
|
window.setPluginInfo = (pluginInfo) => {
|
||||||
this.commonUpdate({
|
this.commonUpdate({
|
||||||
@ -147,7 +158,6 @@ export default {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
ipcRenderer.on("init-rubick", this.closeTag);
|
ipcRenderer.on("init-rubick", this.closeTag);
|
||||||
ipcRenderer.on("new-window", this.newWindow);
|
ipcRenderer.on("new-window", this.newWindow);
|
||||||
@ -319,10 +329,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
changePath({ key }) {
|
changePath({ key }) {
|
||||||
this.$router.push({ path: `/home/${key}` });
|
const path = `/home/${key}`;
|
||||||
this.commonUpdate({
|
// 避免重复点击导致跳转相同路由而爆红
|
||||||
current: [key],
|
if (this.$router.history.current.fullPath != path) {
|
||||||
});
|
this.$router.push({ path });
|
||||||
|
this.commonUpdate({
|
||||||
|
current: [key],
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
closeTag(v) {
|
closeTag(v) {
|
||||||
this.commonUpdate({
|
this.commonUpdate({
|
||||||
@ -330,6 +344,7 @@ export default {
|
|||||||
showMain: false,
|
showMain: false,
|
||||||
options: [],
|
options: [],
|
||||||
});
|
});
|
||||||
|
this.setHideOnBlur(true);
|
||||||
ipcRenderer.send("changeWindowSize-rubick", {
|
ipcRenderer.send("changeWindowSize-rubick", {
|
||||||
height: getWindowHeight([]),
|
height: getWindowHeight([]),
|
||||||
});
|
});
|
||||||
@ -392,10 +407,20 @@ export default {
|
|||||||
ipcRenderer.send("window-move");
|
ipcRenderer.send("window-move");
|
||||||
},
|
},
|
||||||
dragWhenInput(e) {
|
dragWhenInput(e) {
|
||||||
if (this.searchValue == "") {
|
if (this.searchValue === "") {
|
||||||
ipcRenderer.send("window-move");
|
ipcRenderer.send("window-move");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
changeHideOnBlur(e) {
|
||||||
|
let cfg = { ...this.config };
|
||||||
|
cfg.perf.common.hideOnBlur = !cfg.perf.common.hideOnBlur;
|
||||||
|
this.config = cfg;
|
||||||
|
},
|
||||||
|
setHideOnBlur(v) {
|
||||||
|
let cfg = { ...this.config };
|
||||||
|
cfg.perf.common.hideOnBlur = v;
|
||||||
|
this.config = cfg;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState("main", [
|
...mapState("main", [
|
||||||
@ -410,7 +435,7 @@ export default {
|
|||||||
"pluginLoading",
|
"pluginLoading",
|
||||||
]),
|
]),
|
||||||
showOptions() {
|
showOptions() {
|
||||||
// 有选项值,且不在显示主页
|
// 有选项值,且不在显示主页。(即出现下方选项框)
|
||||||
if (this.options.length && !this.showMain) {
|
if (this.options.length && !this.showMain) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -419,6 +444,17 @@ export default {
|
|||||||
return this.pluginInfo.searchType ? "subWindow" : "";
|
return this.pluginInfo.searchType ? "subWindow" : "";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
config: {
|
||||||
|
deep: true,
|
||||||
|
handler() {
|
||||||
|
opConfig.set("perf", this.config.perf);
|
||||||
|
opConfig.set("superPanel", this.config.superPanel);
|
||||||
|
opConfig.set("global", this.config.global);
|
||||||
|
ipcRenderer.send("re-register");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@ -538,4 +574,9 @@ export default {
|
|||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.button-hide-on-blur {
|
||||||
|
padding: 0px 3px 0px 0px;
|
||||||
|
// 小按钮只会在碰到1/3处时被认为点击。
|
||||||
|
height: 33%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
import { WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS } from './constans';
|
import {
|
||||||
import path from 'path';
|
WINDOW_MAX_HEIGHT,
|
||||||
import fs from 'fs';
|
WINDOW_MIN_HEIGHT,
|
||||||
import Store from 'electron-store';
|
PRE_ITEM_HEIGHT,
|
||||||
import downloadFile from 'download';
|
SYSTEM_PLUGINS,
|
||||||
import { ipcRenderer } from 'electron';
|
} from "./constans";
|
||||||
import { getlocalDataFile } from '../../../main/common/utils';
|
import path from "path";
|
||||||
import shell from 'shelljs';
|
import fs from "fs";
|
||||||
|
import Store from "electron-store";
|
||||||
|
import downloadFile from "download";
|
||||||
|
import { ipcRenderer } from "electron";
|
||||||
|
import { getLocalDataFile } from "../../../main/common/utils";
|
||||||
|
import shell from "shelljs";
|
||||||
|
|
||||||
const getApp = process.platform === 'win32' ? require('./win-app').getApp : require('./darwin-app').getApp;
|
const getApp =
|
||||||
|
process.platform === "win32"
|
||||||
|
? require("./win-app").getApp
|
||||||
|
: require("./darwin-app").getApp;
|
||||||
|
|
||||||
const store = new Store();
|
const store = new Store();
|
||||||
|
|
||||||
@ -17,14 +25,16 @@ const fileLists = getApp.fileLists;
|
|||||||
function getWindowHeight(searchList) {
|
function getWindowHeight(searchList) {
|
||||||
if (!searchList) return WINDOW_MAX_HEIGHT;
|
if (!searchList) return WINDOW_MAX_HEIGHT;
|
||||||
if (!searchList.length) return WINDOW_MIN_HEIGHT;
|
if (!searchList.length) return WINDOW_MIN_HEIGHT;
|
||||||
return searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5 > WINDOW_MAX_HEIGHT
|
return searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5 >
|
||||||
|
WINDOW_MAX_HEIGHT
|
||||||
? WINDOW_MAX_HEIGHT
|
? WINDOW_MAX_HEIGHT
|
||||||
: searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5;
|
: searchList.length * PRE_ITEM_HEIGHT + WINDOW_MIN_HEIGHT + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchKeyValues(lists, value) {
|
function searchKeyValues(lists, value) {
|
||||||
return lists.filter((item) => {
|
return lists.filter((item) => {
|
||||||
if (typeof item === 'string') return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
if (typeof item === "string")
|
||||||
|
return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
||||||
return item.type.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
return item.type.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -41,7 +51,7 @@ function existOrNot(path) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const appPath = getlocalDataFile();
|
const appPath = getLocalDataFile();
|
||||||
|
|
||||||
async function downloadZip(downloadRepoUrl, name) {
|
async function downloadZip(downloadRepoUrl, name) {
|
||||||
try {
|
try {
|
||||||
@ -50,7 +60,7 @@ async function downloadZip(downloadRepoUrl, name) {
|
|||||||
const temp_dest = `${plugin_path}/${name}`;
|
const temp_dest = `${plugin_path}/${name}`;
|
||||||
// 下载模板
|
// 下载模板
|
||||||
if (await existOrNot(temp_dest)) {
|
if (await existOrNot(temp_dest)) {
|
||||||
shell.rm('-rf', temp_dest);
|
shell.rm("-rf", temp_dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
await downloadFile(downloadRepoUrl, plugin_path, { extract: true });
|
await downloadFile(downloadRepoUrl, plugin_path, { extract: true });
|
||||||
@ -63,7 +73,7 @@ async function downloadZip(downloadRepoUrl, name) {
|
|||||||
|
|
||||||
const sysFile = {
|
const sysFile = {
|
||||||
savePlugins(plugins) {
|
savePlugins(plugins) {
|
||||||
ipcRenderer.send('optionPlugin', {
|
ipcRenderer.send("optionPlugin", {
|
||||||
plugins: plugins.filter((plugin) => {
|
plugins: plugins.filter((plugin) => {
|
||||||
let hasOption = false;
|
let hasOption = false;
|
||||||
plugin.features.forEach((fe) => {
|
plugin.features.forEach((fe) => {
|
||||||
@ -74,20 +84,20 @@ const sysFile = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
return hasOption;
|
return hasOption;
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
store.set('user-plugins', plugins);
|
store.set("user-plugins", plugins);
|
||||||
},
|
},
|
||||||
getUserPlugins() {
|
getUserPlugins() {
|
||||||
try {
|
try {
|
||||||
return store.get('user-plugins');
|
return store.get("user-plugins");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeAllPlugins() {
|
removeAllPlugins() {
|
||||||
store.delete('user-plugins');
|
store.delete("user-plugins");
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function mergePlugins(plugins) {
|
function mergePlugins(plugins) {
|
||||||
@ -97,10 +107,10 @@ function mergePlugins(plugins) {
|
|||||||
return {
|
return {
|
||||||
...plugin,
|
...plugin,
|
||||||
status: true,
|
status: true,
|
||||||
sourceFile: '',
|
sourceFile: "",
|
||||||
type: 'system'
|
type: "system",
|
||||||
};
|
};
|
||||||
})
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
const target = [];
|
const target = [];
|
||||||
@ -108,7 +118,7 @@ function mergePlugins(plugins) {
|
|||||||
result.forEach((item, i) => {
|
result.forEach((item, i) => {
|
||||||
let targetIndex = -1;
|
let targetIndex = -1;
|
||||||
target.forEach((tg, j) => {
|
target.forEach((tg, j) => {
|
||||||
if (tg.tag === item.tag && tg.type === 'system') {
|
if (tg.tag === item.tag && tg.type === "system") {
|
||||||
targetIndex = j;
|
targetIndex = j;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -117,7 +127,7 @@ function mergePlugins(plugins) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcRenderer &&
|
ipcRenderer &&
|
||||||
ipcRenderer.send('optionPlugin', {
|
ipcRenderer.send("optionPlugin", {
|
||||||
plugins: target.filter((plugin) => {
|
plugins: target.filter((plugin) => {
|
||||||
let hasOption = false;
|
let hasOption = false;
|
||||||
plugin.features.forEach((fe) => {
|
plugin.features.forEach((fe) => {
|
||||||
@ -128,25 +138,25 @@ function mergePlugins(plugins) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
return hasOption;
|
return hasOption;
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
ipcRenderer &&
|
ipcRenderer &&
|
||||||
ipcRenderer.send('pluginInit', {
|
ipcRenderer.send("pluginInit", {
|
||||||
plugins: target
|
plugins: target,
|
||||||
});
|
});
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
function find(p, target = 'plugin.json') {
|
function find(p, target = "plugin.json") {
|
||||||
try {
|
try {
|
||||||
let result;
|
let result;
|
||||||
const fileList = fs.readdirSync(p);
|
const fileList = fs.readdirSync(p);
|
||||||
for (let i = 0; i < fileList.length; i++) {
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
let thisPath = p + '/' + fileList[i];
|
let thisPath = p + "/" + fileList[i];
|
||||||
const data = fs.statSync(thisPath);
|
const data = fs.statSync(thisPath);
|
||||||
|
|
||||||
if (data.isFile() && fileList[i] === target) {
|
if (data.isFile() && fileList[i] === target) {
|
||||||
result = path.join(thisPath, '../');
|
result = path.join(thisPath, "../");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (data.isDirectory()) {
|
if (data.isDirectory()) {
|
||||||
@ -172,4 +182,13 @@ function debounce(fn, delay) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getWindowHeight, searchKeyValues, sysFile, mergePlugins, find, downloadZip, fileLists, debounce };
|
export {
|
||||||
|
getWindowHeight,
|
||||||
|
searchKeyValues,
|
||||||
|
sysFile,
|
||||||
|
mergePlugins,
|
||||||
|
find,
|
||||||
|
downloadZip,
|
||||||
|
fileLists,
|
||||||
|
debounce,
|
||||||
|
};
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
import Vue from 'vue'
|
import Vue from "vue";
|
||||||
import axios from 'axios'
|
import axios from "axios";
|
||||||
import ioHook from 'iohook';
|
import ioHook from "iohook";
|
||||||
import {ipcRenderer, remote} from 'electron';
|
import { ipcRenderer, remote } from "electron";
|
||||||
import App from './App'
|
import App from "./App";
|
||||||
import router from './router'
|
import router from "./router";
|
||||||
import store from './store'
|
import store from "./store";
|
||||||
import Antd from 'ant-design-vue';
|
import Antd from "ant-design-vue";
|
||||||
|
|
||||||
import './assets/ant-reset.less';
|
import "./assets/ant-reset.less";
|
||||||
|
|
||||||
const opConfig = remote.getGlobal('opConfig');
|
const opConfig = remote.getGlobal("opConfig");
|
||||||
|
|
||||||
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
|
if (!process.env.IS_WEB) Vue.use(require("vue-electron"));
|
||||||
Vue.http = Vue.prototype.$http = axios
|
Vue.http = Vue.prototype.$http = axios;
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
Vue.use(Antd);
|
Vue.use(Antd);
|
||||||
@ -22,25 +22,25 @@ new Vue({
|
|||||||
components: { App },
|
components: { App },
|
||||||
router,
|
router,
|
||||||
store,
|
store,
|
||||||
template: '<App/>'
|
template: "<App/>",
|
||||||
}).$mount('#app');
|
}).$mount("#app");
|
||||||
|
|
||||||
ioHook.start(false);
|
ioHook.start(false);
|
||||||
|
|
||||||
let down_time = 0;
|
let down_time = 0;
|
||||||
let isPress = false;
|
let isPress = false;
|
||||||
ioHook.on('mousedown', (e) => {
|
ioHook.on("mousedown", (e) => {
|
||||||
if (e.button === 1) return;
|
if (e.button === 1) return;
|
||||||
isPress = true;
|
isPress = true;
|
||||||
down_time = Date.now();
|
down_time = Date.now();
|
||||||
const config = opConfig.get();
|
const config = opConfig.get();
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
if (isPress) {
|
if (isPress) {
|
||||||
ipcRenderer.send('right-down');
|
ipcRenderer.send("right-down");
|
||||||
}
|
}
|
||||||
}, config.superPanel.mouseDownTime);
|
}, config.superPanel.mouseDownTime);
|
||||||
})
|
});
|
||||||
ioHook.on('mouseup', (e) => {
|
ioHook.on("mouseup", (e) => {
|
||||||
if(e.button === 1) return;
|
if (e.button === 1) return;
|
||||||
isPress = false;
|
isPress = false;
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="pg-settings">
|
<div class="pg-settings">
|
||||||
<div class="dev-detail">
|
<div class="dev-detail">
|
||||||
<a-menu v-model="currentSelect" style="width: 256px; height: 100%" mode="vertical">
|
<a-menu
|
||||||
|
v-model="currentSelect"
|
||||||
|
style="width: 256px; height: 100%"
|
||||||
|
mode="vertical"
|
||||||
|
>
|
||||||
<a-menu-item :key="0">
|
<a-menu-item :key="0">
|
||||||
偏好设置
|
偏好设置
|
||||||
</a-menu-item>
|
</a-menu-item>
|
||||||
@ -15,40 +19,72 @@
|
|||||||
<div class="settings-detail">
|
<div class="settings-detail">
|
||||||
<div v-if="currentSelect[0] === 0">
|
<div v-if="currentSelect[0] === 0">
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="title">快捷键(需要使用 option/ctrl/shift/command 键修饰)</div>
|
<div class="title">
|
||||||
|
快捷键(需要使用 option/ctrl/shift/command 键修饰)
|
||||||
|
</div>
|
||||||
<div class="settings-item-li">
|
<div class="settings-item-li">
|
||||||
<div class="label">显示/隐藏快捷键</div>
|
<div class="label">显示/隐藏快捷键</div>
|
||||||
<div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'showAndHidden')">{{ config.perf.shortCut.showAndHidden }}</div>
|
<div
|
||||||
|
class="value"
|
||||||
|
tabIndex="-1"
|
||||||
|
@keyup="(e) => changeShortCut(e, 'showAndHidden')"
|
||||||
|
>
|
||||||
|
{{ config.perf.shortCut.showAndHidden }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-item-li">
|
<div class="settings-item-li">
|
||||||
<div class="label">插件分离快捷键</div>
|
<div class="label">插件分离快捷键</div>
|
||||||
<div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'separate')">{{ config.perf.shortCut.separate }}</div>
|
<div
|
||||||
|
class="value"
|
||||||
|
tabIndex="-1"
|
||||||
|
@keyup="(e) => changeShortCut(e, 'separate')"
|
||||||
|
>
|
||||||
|
{{ config.perf.shortCut.separate }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-item-li">
|
<div class="settings-item-li">
|
||||||
<div class="label">返回主界面</div>
|
<div class="label">返回主界面</div>
|
||||||
<div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'quit')">{{ config.perf.shortCut.quit }}</div>
|
<div
|
||||||
|
class="value"
|
||||||
|
tabIndex="-1"
|
||||||
|
@keyup="(e) => changeShortCut(e, 'quit')"
|
||||||
|
>
|
||||||
|
{{ config.perf.shortCut.quit }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="title">通用</div>
|
<div class="title">通用</div>
|
||||||
<div class="settings-item-li">
|
<div class="settings-item-li">
|
||||||
<div class="label">开机启动</div>
|
<div class="label">开机启动</div>
|
||||||
<a-switch v-model:checked="config.perf.common.start" checked-children="开" un-checked-children="关"></a-switch>
|
<a-switch
|
||||||
|
v-model:checked="config.perf.common.start"
|
||||||
|
checked-children="开"
|
||||||
|
un-checked-children="关"
|
||||||
|
></a-switch>
|
||||||
</div>
|
</div>
|
||||||
<div class="settings-item-li">
|
<div class="settings-item-li">
|
||||||
<div class="label">空格执行</div>
|
<div class="label">空格执行</div>
|
||||||
<a-switch v-model:checked="config.perf.common.space" checked-children="开" un-checked-children="关"></a-switch>
|
<a-switch
|
||||||
|
v-model:checked="config.perf.common.space"
|
||||||
|
checked-children="开"
|
||||||
|
un-checked-children="关"
|
||||||
|
></a-switch>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="title">本地搜索启动</div>
|
<div class="title">本地搜索启动</div>
|
||||||
<div class="settings-item-li">
|
<div class="settings-item-li">
|
||||||
<div class="label">搜索启动应用&文件</div>
|
<div class="label">搜索启动应用&文件</div>
|
||||||
<a-switch v-model:checked="config.perf.local.search" checked-children="开" un-checked-children="关"></a-switch>
|
<a-switch
|
||||||
|
v-model:checked="config.perf.local.search"
|
||||||
|
checked-children="开"
|
||||||
|
un-checked-children="关"
|
||||||
|
></a-switch>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="currentSelect[0] === 1">
|
<div v-if="currentSelect[0] === 1">
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="title">弹出面板</div>
|
<div class="title">弹出面板</div>
|
||||||
<a-select value="mouseRight" style="width: 200px" disabled>
|
<a-select value="mouseRight" style="width: 200px" disabled>
|
||||||
@ -57,20 +93,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="setting-item">
|
<div class="setting-item">
|
||||||
<div class="title">长按以下设置的毫秒响应</div>
|
<div class="title">长按以下设置的毫秒响应</div>
|
||||||
<a-slider :step="100" v-model:value="config.superPanel.mouseDownTime" :min="200" :max="1000" />
|
<a-slider
|
||||||
|
:step="100"
|
||||||
|
v-model:value="config.superPanel.mouseDownTime"
|
||||||
|
:min="200"
|
||||||
|
:max="1000"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="currentSelect[0] === 2">
|
<div v-if="currentSelect[0] === 2">
|
||||||
<a-collapse>
|
<a-collapse>
|
||||||
<a-collapse-panel key="1" header="说明及示例">
|
<a-collapse-panel key="1" header="说明及示例">
|
||||||
<div>按下快捷键,自动搜索对应关键字,当关键字结果完全匹配,且结果唯一时,会直接指向该功能。</div>
|
<div>
|
||||||
|
按下快捷键,自动搜索对应关键字,当关键字结果完全匹配,且结果唯一时,会直接指向该功能。
|
||||||
|
</div>
|
||||||
<h3 style="margin-top: 10px;">示例</h3>
|
<h3 style="margin-top: 10px;">示例</h3>
|
||||||
<a-divider style="margin: 5px 0;" />
|
<a-divider style="margin: 5px 0;" />
|
||||||
<a-list item-layout="horizontal" :data-source="examples">
|
<a-list item-layout="horizontal" :data-source="examples">
|
||||||
<a-list-item slot="renderItem" slot-scope="item, index">
|
<a-list-item slot="renderItem" slot-scope="item, index">
|
||||||
<a-list-item-meta
|
<a-list-item-meta :description="item.desc">
|
||||||
:description="item.desc"
|
|
||||||
>
|
|
||||||
<div slot="title">{{ item.title }}</div>
|
<div slot="title">{{ item.title }}</div>
|
||||||
</a-list-item-meta>
|
</a-list-item-meta>
|
||||||
</a-list-item>
|
</a-list-item>
|
||||||
@ -82,80 +123,81 @@
|
|||||||
<div>快捷键</div>
|
<div>快捷键</div>
|
||||||
<a-tooltip placement="top" trigger="click">
|
<a-tooltip placement="top" trigger="click">
|
||||||
<template slot="title">
|
<template slot="title">
|
||||||
<span>先按功能键(Ctrl、Shift、Alt、Option、Command),再按其他普通键。或按 F1-F12 单键</span>
|
<span
|
||||||
|
>先按功能键(Ctrl、Shift、Alt、Option、Command),再按其他普通键。或按
|
||||||
|
F1-F12 单键</span
|
||||||
|
>
|
||||||
</template>
|
</template>
|
||||||
<div
|
<div
|
||||||
v-for="(item, index) in config.global"
|
v-for="(item, index) in config.global"
|
||||||
class="value"
|
class="value"
|
||||||
tabIndex=-1
|
tabIndex="-1"
|
||||||
@keyup="(e) => changeGlobalKey(e, index)"
|
@keyup="(e) => changeGlobalKey(e, index)"
|
||||||
>
|
>
|
||||||
{{ item.key }}
|
{{ item.key }}
|
||||||
</div>
|
</div>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="short-cut item">
|
<div class="short-cut item">
|
||||||
<div>功能关键字</div>
|
<div>功能关键字</div>
|
||||||
<a-input
|
<a-input
|
||||||
:value="item.value"
|
:value="item.value"
|
||||||
v-for="(item, index) in config.global"
|
v-for="(item, index) in config.global"
|
||||||
class="value"
|
class="value"
|
||||||
:disabled="!item.key"
|
:disabled="!item.key"
|
||||||
@change="(e) => changeGlobalValue(index, e.target.value)"
|
@change="(e) => changeGlobalValue(index, e.target.value)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div @click="addConfig" class="add-global"> + 新增全局快捷功能</div>
|
<div @click="addConfig" class="add-global">+ 新增全局快捷功能</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import keycodes from '../../../assets/keycode';
|
import keycodes from "../../../assets/keycode";
|
||||||
import {ipcRenderer, remote} from 'electron';
|
import { ipcRenderer, remote } from "electron";
|
||||||
|
|
||||||
const opConfig = remote.getGlobal('opConfig');
|
const opConfig = remote.getGlobal("opConfig");
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currentSelect: [0],
|
currentSelect: [0],
|
||||||
config: JSON.parse(JSON.stringify(opConfig.get())),
|
config: { ...opConfig.get() },
|
||||||
examples: [
|
examples: [
|
||||||
{
|
{
|
||||||
title: '快捷键 「 Alt + W」 关键字 「 微信」',
|
title: "快捷键 「 Alt + W」 关键字 「 微信」",
|
||||||
desc: '按下Alt + W 直接打开本地微信应用'
|
desc: "按下Alt + W 直接打开本地微信应用",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '快捷键 「 Alt + Q」 关键字 「 取色」',
|
title: "快捷键 「 Alt + Q」 关键字 「 取色」",
|
||||||
desc: '按下Alt + Q 直接打开屏幕取色功能'
|
desc: "按下Alt + Q 直接打开屏幕取色功能",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
changeShortCut(e, key) {
|
changeShortCut(e, key) {
|
||||||
let change = false;
|
let change = false;
|
||||||
if(e.altKey && e.keyCode !== 18){
|
if (e.altKey && e.keyCode !== 18) {
|
||||||
const compose = `Option+${keycodes[e.keyCode].toUpperCase()}`;
|
const compose = `Option+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
this.config.perf.shortCut[key] = compose;
|
this.config.perf.shortCut[key] = compose;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
if(e.ctrlKey && e.keyCode !== 17){
|
if (e.ctrlKey && e.keyCode !== 17) {
|
||||||
const compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
|
const compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
this.config.perf.shortCut[key] = compose;
|
this.config.perf.shortCut[key] = compose;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
if(e.shiftKey && e.keyCode !== 16){
|
if (e.shiftKey && e.keyCode !== 16) {
|
||||||
const compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
|
const compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
this.config.perf.shortCut[key] = compose;
|
this.config.perf.shortCut[key] = compose;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
if(e.metaKey && e.keyCode !== 93){
|
if (e.metaKey && e.keyCode !== 93) {
|
||||||
const compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
|
const compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
this.config.perf.shortCut[key] = compose;
|
this.config.perf.shortCut[key] = compose;
|
||||||
change = true;
|
change = true;
|
||||||
@ -163,131 +205,129 @@ export default {
|
|||||||
},
|
},
|
||||||
addConfig() {
|
addConfig() {
|
||||||
this.config.global.push({
|
this.config.global.push({
|
||||||
key: '',
|
key: "",
|
||||||
value: ''
|
value: "",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
changeGlobalKey(e, index) {
|
changeGlobalKey(e, index) {
|
||||||
let compose;
|
let compose;
|
||||||
if(e.altKey && e.keyCode !== 18){
|
if (e.altKey && e.keyCode !== 18) {
|
||||||
compose = `Alt+${keycodes[e.keyCode].toUpperCase()}`;
|
compose = `Alt+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
}
|
}
|
||||||
if(e.ctrlKey && e.keyCode !== 17){
|
if (e.ctrlKey && e.keyCode !== 17) {
|
||||||
compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
|
compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
}
|
}
|
||||||
if(e.shiftKey && e.keyCode !== 16){
|
if (e.shiftKey && e.keyCode !== 16) {
|
||||||
compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
|
compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
}
|
}
|
||||||
if(e.metaKey && e.keyCode !== 93){
|
if (e.metaKey && e.keyCode !== 93) {
|
||||||
compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
|
compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
|
||||||
}
|
}
|
||||||
if (compose) {
|
if (compose) {
|
||||||
this.$set(this.config.global[index], 'key', compose);
|
this.$set(this.config.global[index], "key", compose);
|
||||||
}
|
}
|
||||||
// f1 - f12
|
// f1 - f12
|
||||||
if (e.keyCode >= 112 && e.keyCode <= 123) {
|
if (e.keyCode >= 112 && e.keyCode <= 123) {
|
||||||
compose = keycodes[e.keyCode].toUpperCase();
|
compose = keycodes[e.keyCode].toUpperCase();
|
||||||
}
|
}
|
||||||
if (compose) {
|
if (compose) {
|
||||||
this.$set(this.config.global[index], 'key', compose);
|
this.$set(this.config.global[index], "key", compose);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeGlobalValue(index, value) {
|
changeGlobalValue(index, value) {
|
||||||
this.$set(this.config.global[index], 'value', value);
|
this.$set(this.config.global[index], "value", value);
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
config: {
|
config: {
|
||||||
deep: true,
|
deep: true,
|
||||||
handler() {
|
handler() {
|
||||||
opConfig.set('perf', this.config.perf);
|
opConfig.set("perf", this.config.perf);
|
||||||
opConfig.set('superPanel', this.config.superPanel);
|
opConfig.set("superPanel", this.config.superPanel);
|
||||||
opConfig.set('global', this.config.global);
|
opConfig.set("global", this.config.global);
|
||||||
ipcRenderer.send('re-register');
|
ipcRenderer.send("re-register");
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
.pg-settings {
|
.pg-settings {
|
||||||
height: calc(~'100vh - 110px');
|
height: calc(~"100vh - 110px");
|
||||||
|
overflow: auto;
|
||||||
|
.dev-detail {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.settings-detail {
|
||||||
|
padding: 20px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
flex: 1;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
.dev-detail {
|
height: 100%;
|
||||||
height: 100%;
|
.setting-item {
|
||||||
display: flex;
|
margin-bottom: 20px;
|
||||||
align-items: flex-start;
|
.ant-form-item {
|
||||||
background: #fff;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
.settings-detail {
|
.title {
|
||||||
padding: 20px;
|
color: #6c9fe2;
|
||||||
box-sizing: border-box;
|
font-size: 15px;
|
||||||
flex: 1;
|
margin-bottom: 10px;
|
||||||
overflow: auto;
|
}
|
||||||
height: 100%;
|
.settings-item-li {
|
||||||
.setting-item {
|
padding-left: 20px;
|
||||||
margin-bottom: 20px;
|
display: flex;
|
||||||
.ant-form-item {
|
width: 100%;
|
||||||
margin-bottom: 0;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
.label {
|
||||||
|
color: #646464;
|
||||||
}
|
}
|
||||||
.title {
|
.value {
|
||||||
color: #6C9FE2;
|
width: 300px;
|
||||||
font-size: 15px;
|
text-align: center;
|
||||||
margin-bottom: 10px;
|
border: 1px solid #ddd;
|
||||||
}
|
color: #6c9fe2;
|
||||||
.settings-item-li {
|
font-size: 14px;
|
||||||
padding-left: 20px;
|
height: 24px;
|
||||||
display: flex;
|
font-weight: lighter;
|
||||||
width: 100%;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
.label {
|
|
||||||
color: #646464;
|
|
||||||
}
|
|
||||||
.value {
|
|
||||||
width: 300px;
|
|
||||||
text-align: center;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
color: #6C9FE2;
|
|
||||||
font-size: 14px;
|
|
||||||
height: 24px;
|
|
||||||
font-weight: lighter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.feature-container {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-top: 10px;
|
|
||||||
font-size: 14px;
|
|
||||||
.item {
|
|
||||||
flex: 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
.short-cut {
|
|
||||||
margin-left: 20px;
|
|
||||||
}
|
|
||||||
.value {
|
|
||||||
text-align: center;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
color: #6C9FE2;
|
|
||||||
font-size: 14px;
|
|
||||||
height: 24px;
|
|
||||||
font-weight: lighter;
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.add-global {
|
|
||||||
color: #6C9FE2;
|
|
||||||
margin-top: 20px;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
.feature-container {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
.item {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.short-cut {
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
||||||
|
.value {
|
||||||
|
text-align: center;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
color: #6c9fe2;
|
||||||
|
font-size: 14px;
|
||||||
|
height: 24px;
|
||||||
|
font-weight: lighter;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.add-global {
|
||||||
|
color: #6c9fe2;
|
||||||
|
margin-top: 20px;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -67,7 +67,7 @@ const mutations = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
showMainUI({ commit, state }, paylpad) {
|
showMainUI({ commit, state }, payload) {
|
||||||
ipcRenderer.send("changeWindowSize-rubick", {
|
ipcRenderer.send("changeWindowSize-rubick", {
|
||||||
height: getWindowHeight(),
|
height: getWindowHeight(),
|
||||||
});
|
});
|
||||||
|
@ -1,45 +1,56 @@
|
|||||||
const {getData, getlocalDataFile, saveData} = require("./utils");
|
const { getData, getLocalDataFile, saveData } = require("./utils");
|
||||||
const axios = require('axios');
|
const axios = require("axios");
|
||||||
const marked = require("marked");
|
const marked = require("marked");
|
||||||
const rendererMD = new marked.Renderer();
|
const rendererMD = new marked.Renderer();
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
const os = require('os');
|
const os = require("os");
|
||||||
|
|
||||||
const appPath = path.join(getlocalDataFile());
|
const appPath = path.join(getLocalDataFile());
|
||||||
const dbPath = path.join(appPath, './db.json');
|
const dbPath = path.join(appPath, "./db.json");
|
||||||
|
|
||||||
let filePath = '';
|
let filePath = "";
|
||||||
function getQueryVariable(variable) {
|
function getQueryVariable(variable) {
|
||||||
var query = window.location.search.substring(1);
|
var query = window.location.search.substring(1);
|
||||||
var vars = query.split("&");
|
var vars = query.split("&");
|
||||||
for (var i=0;i<vars.length;i++) {
|
for (var i = 0; i < vars.length; i++) {
|
||||||
var pair = vars[i].split("=");
|
var pair = vars[i].split("=");
|
||||||
if(pair[0] == variable){return pair[1];}
|
if (pair[0] == variable) {
|
||||||
|
return pair[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(false);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.href.indexOf('targetFile') > -1) {
|
if (location.href.indexOf("targetFile") > -1) {
|
||||||
filePath = decodeURIComponent(getQueryVariable('targetFile'));
|
filePath = decodeURIComponent(getQueryVariable("targetFile"));
|
||||||
} else {
|
} else {
|
||||||
filePath = process.platform === 'win32' ? location.pathname.replace('/', '') : location.pathname.replace('file://', '');
|
filePath =
|
||||||
|
process.platform === "win32"
|
||||||
|
? location.pathname.replace("/", "")
|
||||||
|
: location.pathname.replace("file://", "");
|
||||||
}
|
}
|
||||||
const {ipcRenderer, nativeImage, clipboard, remote, shell} = require('electron');
|
const {
|
||||||
|
ipcRenderer,
|
||||||
|
nativeImage,
|
||||||
|
clipboard,
|
||||||
|
remote,
|
||||||
|
shell,
|
||||||
|
} = require("electron");
|
||||||
|
|
||||||
const currentWindow = remote.getCurrentWindow();
|
const currentWindow = remote.getCurrentWindow();
|
||||||
const winId = currentWindow.id;
|
const winId = currentWindow.id;
|
||||||
const BrowserWindow = remote.BrowserWindow;
|
const BrowserWindow = remote.BrowserWindow;
|
||||||
|
|
||||||
function convertImgToBase64(url, callback, outputFormat){
|
function convertImgToBase64(url, callback, outputFormat) {
|
||||||
var canvas = document.createElement('CANVAS'),
|
var canvas = document.createElement("CANVAS"),
|
||||||
ctx = canvas.getContext('2d'),
|
ctx = canvas.getContext("2d"),
|
||||||
img = new Image;
|
img = new Image();
|
||||||
img.crossOrigin = 'Anonymous';
|
img.crossOrigin = "Anonymous";
|
||||||
img.onload = function(){
|
img.onload = function() {
|
||||||
canvas.height = img.height;
|
canvas.height = img.height;
|
||||||
canvas.width = img.width;
|
canvas.width = img.width;
|
||||||
ctx.drawImage(img,0,0);
|
ctx.drawImage(img, 0, 0);
|
||||||
var dataURL = canvas.toDataURL(outputFormat || 'image/png');
|
var dataURL = canvas.toDataURL(outputFormat || "image/png");
|
||||||
callback.call(this, dataURL);
|
callback.call(this, dataURL);
|
||||||
canvas = null;
|
canvas = null;
|
||||||
};
|
};
|
||||||
@ -49,58 +60,67 @@ function convertImgToBase64(url, callback, outputFormat){
|
|||||||
window.rubick = {
|
window.rubick = {
|
||||||
// 事件
|
// 事件
|
||||||
onPluginEnter(cb) {
|
onPluginEnter(cb) {
|
||||||
ipcRenderer.on('onPluginEnter', (e, message) => {
|
ipcRenderer.on("onPluginEnter", (e, message) => {
|
||||||
const feature = message.detail;
|
const feature = message.detail;
|
||||||
cb({...feature, type: message.cmd.type ? message.cmd.type : 'text', payload: message.payload})
|
cb({
|
||||||
})
|
...feature,
|
||||||
|
type: message.cmd.type ? message.cmd.type : "text",
|
||||||
|
payload: message.payload,
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onPluginReady(cb) {
|
onPluginReady(cb) {
|
||||||
ipcRenderer.once('onPluginReady', (e, message) => {
|
ipcRenderer.once("onPluginReady", (e, message) => {
|
||||||
const feature = message.detail
|
const feature = message.detail;
|
||||||
cb({...feature, type: message.cmd.type ? message.cmd.type : 'text', payload: message.payload})
|
cb({
|
||||||
})
|
...feature,
|
||||||
|
type: message.cmd.type ? message.cmd.type : "text",
|
||||||
|
payload: message.payload,
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onPluginOut(cb) {
|
onPluginOut(cb) {
|
||||||
ipcRenderer.once('onPluginOut', (e, message) => {
|
ipcRenderer.once("onPluginOut", (e, message) => {
|
||||||
const feature = JSON.parse(message.detail)
|
const feature = JSON.parse(message.detail);
|
||||||
cb({...feature, type: 'text'})
|
cb({ ...feature, type: "text" });
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 窗口交互
|
// 窗口交互
|
||||||
hideMainWindow() {
|
hideMainWindow() {
|
||||||
ipcRenderer.send('msg-trigger', {
|
ipcRenderer.send("msg-trigger", {
|
||||||
type: 'hideMainWindow',
|
type: "hideMainWindow",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
showMainWindow() {
|
showMainWindow() {
|
||||||
ipcRenderer.send('msg-trigger', {
|
ipcRenderer.send("msg-trigger", {
|
||||||
type: 'showMainWindow',
|
type: "showMainWindow",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setExpendHeight(height) {
|
setExpendHeight(height) {
|
||||||
ipcRenderer.send('msg-trigger', {
|
ipcRenderer.send("msg-trigger", {
|
||||||
type: 'setExpendHeight',
|
type: "setExpendHeight",
|
||||||
height,
|
height,
|
||||||
winId
|
winId,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setSubInput(onChange, placeHolder, isFocus) {
|
setSubInput(onChange, placeHolder, isFocus) {
|
||||||
ipcRenderer.sendToHost('setSubInput', {
|
ipcRenderer.sendToHost("setSubInput", {
|
||||||
placeHolder, isFocus
|
placeHolder,
|
||||||
|
isFocus,
|
||||||
});
|
});
|
||||||
ipcRenderer.on(`msg-back-setSubInput`, (e, result) => {
|
ipcRenderer.on(`msg-back-setSubInput`, (e, result) => {
|
||||||
onChange({text: result});
|
onChange({ text: result });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
removeSubInput() {
|
removeSubInput() {
|
||||||
ipcRenderer.sendToHost('removeSubInput');
|
ipcRenderer.sendToHost("removeSubInput");
|
||||||
},
|
},
|
||||||
|
|
||||||
setSubInputValue(text) {
|
setSubInputValue(text) {
|
||||||
ipcRenderer.sendToHost('setSubInputValue', {
|
ipcRenderer.sendToHost("setSubInputValue", {
|
||||||
text
|
text,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -109,41 +129,41 @@ window.rubick = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
showNotification(body, clickFeatureCode) {
|
showNotification(body, clickFeatureCode) {
|
||||||
const myNotification = new Notification('Rubick 通知', {
|
const myNotification = new Notification("Rubick 通知", {
|
||||||
body
|
body,
|
||||||
});
|
});
|
||||||
return myNotification;
|
return myNotification;
|
||||||
// todo 实现 clickFeatureCode
|
// todo 实现 clickFeatureCode
|
||||||
},
|
},
|
||||||
showOpenDialog(options) {
|
showOpenDialog(options) {
|
||||||
ipcRenderer.send('msg-trigger', {
|
ipcRenderer.send("msg-trigger", {
|
||||||
type: 'showOpenDialog',
|
type: "showOpenDialog",
|
||||||
options: {...options},
|
options: { ...options },
|
||||||
});
|
});
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ipcRenderer.once(`msg-back-showOpenDialog`, (e, result) => {
|
ipcRenderer.once(`msg-back-showOpenDialog`, (e, result) => {
|
||||||
result ? resolve(result) : reject();
|
result ? resolve(result) : reject();
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
copyImage(img) {
|
copyImage(img) {
|
||||||
convertImgToBase64(img,function(base64Image) {
|
convertImgToBase64(img, function(base64Image) {
|
||||||
const image = nativeImage.createFromDataURL(base64Image)
|
const image = nativeImage.createFromDataURL(base64Image);
|
||||||
clipboard.writeImage(image)
|
clipboard.writeImage(image);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
copyText(text) {
|
copyText(text) {
|
||||||
clipboard.writeText(text);
|
clipboard.writeText(text);
|
||||||
},
|
},
|
||||||
db: {
|
db: {
|
||||||
put(data) {
|
put(data) {
|
||||||
data._rev = '';
|
data._rev = "";
|
||||||
let dbData = getData(dbPath) || [];
|
let dbData = getData(dbPath) || [];
|
||||||
let target = [];
|
let target = [];
|
||||||
dbData.some((d, i) => {
|
dbData.some((d, i) => {
|
||||||
if (d._id === data._id) {
|
if (d._id === data._id) {
|
||||||
target = [d, i]
|
target = [d, i];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -159,15 +179,15 @@ window.rubick = {
|
|||||||
return {
|
return {
|
||||||
id: data._id,
|
id: data._id,
|
||||||
ok: true,
|
ok: true,
|
||||||
rev: '',
|
rev: "",
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
get(key) {
|
get(key) {
|
||||||
const dbData = getData(dbPath) || [];
|
const dbData = getData(dbPath) || [];
|
||||||
return dbData.find(d => d._id === key) || '';
|
return dbData.find((d) => d._id === key) || "";
|
||||||
},
|
},
|
||||||
remove(key) {
|
remove(key) {
|
||||||
key = typeof key === 'object' ? key._id : key;
|
key = typeof key === "object" ? key._id : key;
|
||||||
let dbData = getData(dbPath);
|
let dbData = getData(dbPath);
|
||||||
let find = false;
|
let find = false;
|
||||||
dbData.some((d, i) => {
|
dbData.some((d, i) => {
|
||||||
@ -183,52 +203,52 @@ window.rubick = {
|
|||||||
return {
|
return {
|
||||||
id: key,
|
id: key,
|
||||||
ok: true,
|
ok: true,
|
||||||
rev: '',
|
rev: "",
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
id: key,
|
id: key,
|
||||||
ok: false,
|
ok: false,
|
||||||
rev: '',
|
rev: "",
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bulkDocs(docs) {
|
bulkDocs(docs) {
|
||||||
const dbData = getData(dbPath);
|
const dbData = getData(dbPath);
|
||||||
dbData.forEach((d, i) => {
|
dbData.forEach((d, i) => {
|
||||||
const result = docs.find(data => data._id === d._id);
|
const result = docs.find((data) => data._id === d._id);
|
||||||
if (result) {
|
if (result) {
|
||||||
dbData[i] = result;
|
dbData[i] = result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
saveData(dbPath, dbData);
|
saveData(dbPath, dbData);
|
||||||
return docs.map(d => ({
|
return docs.map((d) => ({
|
||||||
id: d._id,
|
id: d._id,
|
||||||
success: true,
|
success: true,
|
||||||
rev: '',
|
rev: "",
|
||||||
}))
|
}));
|
||||||
},
|
},
|
||||||
allDocs(key) {
|
allDocs(key) {
|
||||||
const dbData = getData(dbPath);
|
const dbData = getData(dbPath);
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return dbData;
|
return dbData;
|
||||||
}
|
}
|
||||||
if (typeof key === 'string') {
|
if (typeof key === "string") {
|
||||||
return dbData.filter(d => d._id.indexOf(key) >= 0);
|
return dbData.filter((d) => d._id.indexOf(key) >= 0);
|
||||||
}
|
}
|
||||||
if (Array.isArray(key)) {
|
if (Array.isArray(key)) {
|
||||||
return dbData.filter(d => key.indexOf(d._id) >= 0);
|
return dbData.filter((d) => key.indexOf(d._id) >= 0);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
isDarkColors() {
|
isDarkColors() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
features: [],
|
features: [],
|
||||||
getFeatures() {
|
getFeatures() {
|
||||||
ipcRenderer.sendToHost('getFeatures');
|
ipcRenderer.sendToHost("getFeatures");
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve) => {
|
||||||
ipcRenderer.on(`msg-back-getFeatures`, (e, result) => {
|
ipcRenderer.on(`msg-back-getFeatures`, (e, result) => {
|
||||||
rubick.features = result;
|
rubick.features = result;
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@ -236,12 +256,12 @@ window.rubick = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
setFeature(feature) {
|
setFeature(feature) {
|
||||||
ipcRenderer.sendToHost('setFeature', {feature});
|
ipcRenderer.sendToHost("setFeature", { feature });
|
||||||
},
|
},
|
||||||
|
|
||||||
removeFeature(code) {
|
removeFeature(code) {
|
||||||
ipcRenderer.sendToHost('removeFeature', {code});
|
ipcRenderer.sendToHost("removeFeature", { code });
|
||||||
return !!rubick.features.filter(fe => fe.code === code).length;
|
return !!rubick.features.filter((fe) => fe.code === code).length;
|
||||||
},
|
},
|
||||||
// 系统
|
// 系统
|
||||||
shellOpenExternal(url) {
|
shellOpenExternal(url) {
|
||||||
@ -249,19 +269,19 @@ window.rubick = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
isMacOs() {
|
isMacOs() {
|
||||||
return os.type() === 'Darwin';
|
return os.type() === "Darwin";
|
||||||
},
|
},
|
||||||
|
|
||||||
isWindows() {
|
isWindows() {
|
||||||
return os.type() === 'Windows_NT';
|
return os.type() === "Windows_NT";
|
||||||
},
|
},
|
||||||
|
|
||||||
isLinux() {
|
isLinux() {
|
||||||
return os.type() === 'Linux';
|
return os.type() === "Linux";
|
||||||
},
|
},
|
||||||
|
|
||||||
shellOpenPath(path) {
|
shellOpenPath(path) {
|
||||||
shell.openPath(path)
|
shell.openPath(path);
|
||||||
},
|
},
|
||||||
|
|
||||||
request(config = {}) {
|
request(config = {}) {
|
||||||
@ -270,10 +290,13 @@ window.rubick = {
|
|||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
...config,
|
...config,
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
const preloadPath = getQueryVariable('preloadPath') || './preload.js';
|
const preloadPath = getQueryVariable("preloadPath") || "./preload.js";
|
||||||
|
|
||||||
require(path.join(filePath, '../', preloadPath));
|
require(path.join(filePath, "../", preloadPath));
|
||||||
window.exports && ipcRenderer.sendToHost('templateConfig', {config: JSON.parse(JSON.stringify(window.exports))});
|
window.exports &&
|
||||||
|
ipcRenderer.sendToHost("templateConfig", {
|
||||||
|
config: JSON.parse(JSON.stringify(window.exports)),
|
||||||
|
});
|
||||||
window.ipcRenderer = ipcRenderer;
|
window.ipcRenderer = ipcRenderer;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const getlocalDataFile = () => {
|
const getLocalDataFile = () => {
|
||||||
let localDataFile = process.env.HOME;
|
let localDataFile = process.env.HOME;
|
||||||
if (!localDataFile) {
|
if (!localDataFile) {
|
||||||
localDataFile = process.env.LOCALAPPDATA;
|
localDataFile = process.env.LOCALAPPDATA;
|
||||||
@ -14,37 +14,39 @@ function saveData(path, value) {
|
|||||||
|
|
||||||
function getData(path, defaultValue) {
|
function getData(path, defaultValue) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(path, 'utf8'));
|
return JSON.parse(fs.readFileSync(path, "utf8"));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return defaultValue || undefined;
|
return defaultValue || undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isArray = Array.isArray ||
|
const isArray =
|
||||||
function(object){ return object instanceof Array }
|
Array.isArray ||
|
||||||
|
function(object) {
|
||||||
|
return object instanceof Array;
|
||||||
|
};
|
||||||
|
|
||||||
function isPlainObject(obj) {
|
function isPlainObject(obj) {
|
||||||
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype
|
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isObject(obj) { return typeof obj == "object" }
|
function isObject(obj) {
|
||||||
|
return typeof obj == "object";
|
||||||
|
}
|
||||||
|
|
||||||
function extend(target, source, deep) {
|
function extend(target, source, deep) {
|
||||||
for (let key in source)
|
for (let key in source)
|
||||||
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
|
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
|
||||||
if (isPlainObject(source[key]) && !isPlainObject(target[key]))
|
if (isPlainObject(source[key]) && !isPlainObject(target[key]))
|
||||||
target[key] = {}
|
target[key] = {};
|
||||||
if (isArray(source[key]) && !isArray(target[key]))
|
if (isArray(source[key]) && !isArray(target[key])) target[key] = [];
|
||||||
target[key] = []
|
extend(target[key], source[key], deep);
|
||||||
extend(target[key], source[key], deep)
|
} else if (source[key] !== undefined) target[key] = source[key];
|
||||||
}
|
|
||||||
else if (source[key] !== undefined) target[key] = source[key]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getlocalDataFile,
|
getLocalDataFile,
|
||||||
saveData,
|
saveData,
|
||||||
getData,
|
getData,
|
||||||
extend
|
extend,
|
||||||
}
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user