mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-19 18:42:43 +08:00
Merge branch 'master' of https://github.com/clouDr-f2e/rubick into master
This commit is contained in:
commit
261a6db49e
@ -18,7 +18,7 @@
|
||||
之所以做这个工具箱一方面是 utools 本身并未开源,但是公司内部的工具库又无法发布到 utools 插件中,所以为了既要享受 utools 生态又要有定制化需求,我们自己参考 utools 设计,做了 Rubick
|
||||
|
||||
## 安装包
|
||||
* [Rubick Mac OS V0.0.1](https://github.com/clouDr-f2e/rubick/releases/tag/v0.0.1-beta.2)
|
||||
* [Rubick Mac OS V0.0.1](https://github.com/clouDr-f2e/rubick/releases/download/v0.0.1-beta.3/rubick2-0.0.1.pkg)
|
||||
|
||||
## 支持能力
|
||||
|
||||
|
16892
package-lock.json
generated
Normal file
16892
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -66,7 +66,7 @@ export default {
|
||||
return dbData.find(d => d._id === key) || {};
|
||||
},
|
||||
remove({key}) {
|
||||
key = typeof key === 'object' ? key.id : key;
|
||||
key = typeof key === 'object' ? key._id : key;
|
||||
let dbData = getData(dbPath);
|
||||
let find = false;
|
||||
dbData.some((d, i) => {
|
||||
|
@ -99,6 +99,9 @@ export default {
|
||||
ipcRenderer.on('new-window', this.newWindow);
|
||||
// 超级面板打开插件
|
||||
ipcRenderer.on('superPanel-openPlugin', (e, args) => {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'showMainWindow',
|
||||
});
|
||||
this.openPlugin({
|
||||
cmd: args.cmd,
|
||||
plugin: args.plugin,
|
||||
|
@ -110,6 +110,20 @@ function mergePlugins(plugins) {
|
||||
target.push(item)
|
||||
}
|
||||
});
|
||||
ipcRenderer && ipcRenderer.send('optionPlugin', {
|
||||
plugins: target.filter((plugin) => {
|
||||
let hasOption = false;
|
||||
plugin.features.forEach(fe => {
|
||||
fe.cmds.forEach(cmd => {
|
||||
if (cmd.type) {
|
||||
hasOption = true;
|
||||
}
|
||||
})
|
||||
});
|
||||
return hasOption;
|
||||
})
|
||||
});
|
||||
|
||||
return target
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,19 @@ export default {
|
||||
}),
|
||||
});
|
||||
}
|
||||
if (event.channel === 'removeFeature') {
|
||||
this.commonUpdate({
|
||||
devPlugins: this.devPlugins.map(plugin => {
|
||||
if (plugin.name === this.query.name) {
|
||||
return {
|
||||
...plugin,
|
||||
features: plugin.features.filter(fe => fe.code !== event.args[0].code)
|
||||
}
|
||||
}
|
||||
return plugin;
|
||||
}),
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="dev-container">
|
||||
<div class="dev-detail" v-if="devPlugin.length">
|
||||
<a-menu v-model="currentSelect" style="width: 200px; height: 100%" mode="vertical">
|
||||
<a-menu v-model="currentSelect" style="width: 256px; height: 100%" mode="vertical">
|
||||
<a-menu-item @click="currentSelect = [index]" v-for="(plugin, index) in devPlugin" :key="index">
|
||||
<div class="menu-item">
|
||||
<img width="40" height="40" :src="plugin.icon" />
|
||||
@ -160,6 +160,10 @@ export default {
|
||||
}
|
||||
.desc {
|
||||
color: #999;
|
||||
width: 180px;
|
||||
overflow: hidden;
|
||||
text-overflow:ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,11 +174,12 @@ export default {
|
||||
width: 100%;
|
||||
}
|
||||
.plugin-detail {
|
||||
padding: 20px;
|
||||
padding: 20px 20px 0 20px;
|
||||
box-sizing: border-box;
|
||||
flex: 1;
|
||||
width: 500px;
|
||||
.detail-container {
|
||||
height: 340px;
|
||||
height: 320px;
|
||||
overflow: auto;
|
||||
max-height: 320px;
|
||||
width: 100%;
|
||||
@ -202,6 +207,8 @@ export default {
|
||||
.desc-item {
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: 10px 0;
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
.desc-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
@ -111,9 +111,10 @@ export default {
|
||||
overflow: auto;
|
||||
}
|
||||
.plugin-detail {
|
||||
padding: 20px;
|
||||
padding: 20px 20px 0 20px;
|
||||
box-sizing: border-box;
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
.plugin-top {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
|
@ -77,7 +77,43 @@ new Vue({
|
||||
const word = this.selectData.text;
|
||||
const isCh = isChinese(word);
|
||||
this.translate(word, isCh ? 'en' : 'zh');
|
||||
this.targetOptions = this.options.translate;
|
||||
this.targetOptions = JSON.parse(JSON.stringify(this.options.translate));
|
||||
(this.selectData.optionPlugin || []).forEach(plugin => {
|
||||
plugin.features.forEach(fe => {
|
||||
fe.cmds.forEach(cmd => {
|
||||
if (cmd.type === 'regex' && eval(cmd.match).test(word)) {
|
||||
this.targetOptions.push({
|
||||
type: 'ext',
|
||||
name: cmd.label,
|
||||
icon: plugin.icon,
|
||||
click: () => {
|
||||
ipcRenderer.send('superPanel-openPlugin', {
|
||||
cmd: cmd,
|
||||
plugin: plugin,
|
||||
feature: fe,
|
||||
data: word
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
if (cmd.type === 'over') {
|
||||
this.targetOptions.push({
|
||||
type: 'ext',
|
||||
name: cmd.label,
|
||||
icon: plugin.icon,
|
||||
click: () => {
|
||||
ipcRenderer.send('superPanel-openPlugin', {
|
||||
cmd: cmd,
|
||||
plugin: plugin,
|
||||
feature: fe,
|
||||
data: word
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
} else if (!ext || path.parse(this.selectData.fileUrl).base === 'Desktop') {
|
||||
// 如果在桌面上或者没有选择任何文件,则展示通用选项
|
||||
this.targetOptions = this.options.common;
|
||||
@ -91,7 +127,6 @@ new Vue({
|
||||
// 如果是图片,则唤起图片选项
|
||||
const regImg = /\.(png|jpg|gif|jpeg|webp)$/;
|
||||
if (cmd.type === 'img' && regImg.test(ext)) {
|
||||
console.log(plugin);
|
||||
this.targetOptions.push({
|
||||
type: 'ext',
|
||||
name: cmd.label,
|
||||
|
@ -1,6 +1,12 @@
|
||||
const {getData, getlocalDataFile, saveData} = require("./utils");
|
||||
|
||||
const marked = require("marked");
|
||||
const rendererMD = new marked.Renderer();
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const appPath = path.join(getlocalDataFile());
|
||||
const dbPath = path.join(appPath, './db.json');
|
||||
|
||||
let filePath = '';
|
||||
function getQueryVariable(variable) {
|
||||
@ -141,60 +147,88 @@ window.utools = window.rubick = {
|
||||
},
|
||||
db: {
|
||||
put(data) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'db.put',
|
||||
data,
|
||||
data._rev = '';
|
||||
let dbData = getData(dbPath) || [];
|
||||
let target = [];
|
||||
dbData.some((d, i) => {
|
||||
if (d._id === data._id) {
|
||||
target = [d, i]
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once(`msg-back-db.put`, (e, result) => {
|
||||
result ? resolve(result) : reject();
|
||||
});
|
||||
})
|
||||
|
||||
// 更新
|
||||
if (target[0]) {
|
||||
dbData[target[1]] = data;
|
||||
} else {
|
||||
dbData.push(data);
|
||||
}
|
||||
saveData(dbPath, dbData);
|
||||
return {
|
||||
id: data._id,
|
||||
ok: true,
|
||||
rev: '',
|
||||
}
|
||||
},
|
||||
get(key) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'db.get',
|
||||
key,
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once(`msg-back-db.get`, (e, result) => {
|
||||
result ? resolve(result) : reject();
|
||||
});
|
||||
})
|
||||
const dbData = getData(dbPath) || [];
|
||||
return dbData.find(d => d._id === key) || '';
|
||||
},
|
||||
remove(key) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'db.remove',
|
||||
key,
|
||||
key = typeof key === 'object' ? key._id : key;
|
||||
let dbData = getData(dbPath);
|
||||
let find = false;
|
||||
dbData.some((d, i) => {
|
||||
if (d._id === key) {
|
||||
dbData.splice(i, 1);
|
||||
find = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once(`msg-back-db.remove`, (e, result) => {
|
||||
result ? resolve(result) : reject();
|
||||
});
|
||||
})
|
||||
},
|
||||
allDocs(key) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'db.allDocs',
|
||||
key,
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once(`msg-back-db.allDocs`, (e, result) => {
|
||||
console.log(result);
|
||||
result ? resolve(result) : reject();
|
||||
});
|
||||
})
|
||||
if (find) {
|
||||
saveData(dbPath, dbData);
|
||||
return {
|
||||
id: key,
|
||||
ok: true,
|
||||
rev: '',
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
id: key,
|
||||
ok: false,
|
||||
rev: '',
|
||||
}
|
||||
}
|
||||
},
|
||||
bulkDocs(docs) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'db.bulkDocs',
|
||||
key,
|
||||
const dbData = getData(dbPath);
|
||||
dbData.forEach((d, i) => {
|
||||
const result = docs.find(data => data._id === d._id);
|
||||
if (result) {
|
||||
dbData[i] = result;
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once(`msg-back-db.bulkDocs`, (e, result) => {
|
||||
result ? resolve(result) : reject();
|
||||
});
|
||||
})
|
||||
saveData(dbPath, dbData);
|
||||
return docs.map(d => ({
|
||||
id: d._id,
|
||||
success: true,
|
||||
rev: '',
|
||||
}))
|
||||
},
|
||||
allDocs(key) {
|
||||
const dbData = getData(dbPath);
|
||||
if (!key) {
|
||||
return dbData;
|
||||
}
|
||||
if (typeof key === 'string') {
|
||||
return dbData.filter(d => d._id.indexOf(key) >= 0);
|
||||
}
|
||||
if (Array.isArray(key)) {
|
||||
return dbData.filter(d => key.indexOf(d._id) >= 0);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
},
|
||||
isDarkColors() {
|
||||
@ -211,6 +245,10 @@ window.utools = window.rubick = {
|
||||
setFeature(feature) {
|
||||
ipcRenderer.sendToHost('setFeature', {feature});
|
||||
},
|
||||
|
||||
removeFeature(code) {
|
||||
ipcRenderer.sendToHost('removeFeature', {code});
|
||||
},
|
||||
ubrowser: {
|
||||
winId: '',
|
||||
async goto(md, opts) {
|
||||
@ -282,9 +320,19 @@ window.utools = window.rubick = {
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
// 系统
|
||||
shellOpenExternal(url) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
},
|
||||
|
||||
isMacOs() {
|
||||
return os.type() === 'Darwin';
|
||||
},
|
||||
|
||||
isWindows() {
|
||||
return os.type() === 'Windows_NT';
|
||||
},
|
||||
}
|
||||
const preloadPath = getQueryVariable('preloadPath') || './preload.js';
|
||||
|
||||
|
27
static/utils.js
Normal file
27
static/utils.js
Normal file
@ -0,0 +1,27 @@
|
||||
const fs = require("fs");
|
||||
|
||||
const getlocalDataFile = () => {
|
||||
let localDataFile = process.env.HOME;
|
||||
if (!localDataFile) {
|
||||
localDataFile = process.env.LOCALAPPDATA;
|
||||
}
|
||||
return localDataFile;
|
||||
};
|
||||
|
||||
function saveData(path, value) {
|
||||
fs.writeFileSync(path, JSON.stringify(value));
|
||||
}
|
||||
|
||||
function getData(path, defaultValue) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(path, 'utf8'));
|
||||
} catch (e) {
|
||||
return defaultValue || undefined;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getlocalDataFile,
|
||||
saveData,
|
||||
getData
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user