mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-13 23:06:57 +08:00
ref: db api 修改为同步
This commit is contained in:
parent
70bbe8ab49
commit
e4e7dbbe9a
@ -66,7 +66,7 @@ export default {
|
|||||||
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) => {
|
||||||
|
@ -99,6 +99,9 @@ export default {
|
|||||||
ipcRenderer.on('new-window', this.newWindow);
|
ipcRenderer.on('new-window', this.newWindow);
|
||||||
// 超级面板打开插件
|
// 超级面板打开插件
|
||||||
ipcRenderer.on('superPanel-openPlugin', (e, args) => {
|
ipcRenderer.on('superPanel-openPlugin', (e, args) => {
|
||||||
|
ipcRenderer.send('msg-trigger', {
|
||||||
|
type: 'showMainWindow',
|
||||||
|
});
|
||||||
this.openPlugin({
|
this.openPlugin({
|
||||||
cmd: args.cmd,
|
cmd: args.cmd,
|
||||||
plugin: args.plugin,
|
plugin: args.plugin,
|
||||||
|
@ -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: {
|
methods: {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="dev-container">
|
<div class="dev-container">
|
||||||
<div class="dev-detail" v-if="devPlugin.length">
|
<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">
|
<a-menu-item @click="currentSelect = [index]" v-for="(plugin, index) in devPlugin" :key="index">
|
||||||
<div class="menu-item">
|
<div class="menu-item">
|
||||||
<img width="40" height="40" :src="plugin.icon" />
|
<img width="40" height="40" :src="plugin.icon" />
|
||||||
@ -160,6 +160,10 @@ export default {
|
|||||||
}
|
}
|
||||||
.desc {
|
.desc {
|
||||||
color: #999;
|
color: #999;
|
||||||
|
width: 180px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow:ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,11 +174,12 @@ export default {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.plugin-detail {
|
.plugin-detail {
|
||||||
padding: 20px;
|
padding: 20px 20px 0 20px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
width: 500px;
|
||||||
.detail-container {
|
.detail-container {
|
||||||
height: 340px;
|
height: 320px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
max-height: 320px;
|
max-height: 320px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -202,6 +207,8 @@ export default {
|
|||||||
.desc-item {
|
.desc-item {
|
||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
|
width: 100%;
|
||||||
|
overflow: auto;
|
||||||
.desc-title {
|
.desc-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -111,9 +111,10 @@ export default {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
.plugin-detail {
|
.plugin-detail {
|
||||||
padding: 20px;
|
padding: 20px 20px 0 20px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
.plugin-top {
|
.plugin-top {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
|
const {getData, getlocalDataFile, saveData} = require("./utils");
|
||||||
|
|
||||||
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 appPath = path.join(getlocalDataFile());
|
||||||
|
const dbPath = path.join(appPath, './db.json');
|
||||||
|
|
||||||
let filePath = '';
|
let filePath = '';
|
||||||
function getQueryVariable(variable) {
|
function getQueryVariable(variable) {
|
||||||
@ -141,60 +147,89 @@ window.utools = window.rubick = {
|
|||||||
},
|
},
|
||||||
db: {
|
db: {
|
||||||
put(data) {
|
put(data) {
|
||||||
ipcRenderer.send('msg-trigger', {
|
data._rev = '';
|
||||||
type: 'db.put',
|
let dbData = getData(dbPath) || [];
|
||||||
data,
|
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) {
|
get(key) {
|
||||||
ipcRenderer.send('msg-trigger', {
|
const dbData = getData(dbPath) || [];
|
||||||
type: 'db.get',
|
|
||||||
key,
|
return dbData.find(d => d._id === key);
|
||||||
});
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
ipcRenderer.once(`msg-back-db.get`, (e, result) => {
|
|
||||||
result ? resolve(result) : reject();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
remove(key) {
|
remove(key) {
|
||||||
ipcRenderer.send('msg-trigger', {
|
key = typeof key === 'object' ? key._id : key;
|
||||||
type: 'db.remove',
|
let dbData = getData(dbPath);
|
||||||
key,
|
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) => {
|
if (find) {
|
||||||
ipcRenderer.once(`msg-back-db.remove`, (e, result) => {
|
saveData(dbPath, dbData);
|
||||||
result ? resolve(result) : reject();
|
return {
|
||||||
});
|
id: key,
|
||||||
})
|
ok: true,
|
||||||
},
|
rev: '',
|
||||||
allDocs(key) {
|
}
|
||||||
ipcRenderer.send('msg-trigger', {
|
} else {
|
||||||
type: 'db.allDocs',
|
return {
|
||||||
key,
|
id: key,
|
||||||
});
|
ok: false,
|
||||||
return new Promise((resolve, reject) => {
|
rev: '',
|
||||||
ipcRenderer.once(`msg-back-db.allDocs`, (e, result) => {
|
}
|
||||||
console.log(result);
|
}
|
||||||
result ? resolve(result) : reject();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
bulkDocs(docs) {
|
bulkDocs(docs) {
|
||||||
ipcRenderer.send('msg-trigger', {
|
const dbData = getData(dbPath);
|
||||||
type: 'db.bulkDocs',
|
dbData.forEach((d, i) => {
|
||||||
key,
|
const result = docs.find(data => data._id === d._id);
|
||||||
|
if (result) {
|
||||||
|
dbData[i] = result;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return new Promise((resolve, reject) => {
|
saveData(dbPath, dbData);
|
||||||
ipcRenderer.once(`msg-back-db.bulkDocs`, (e, result) => {
|
return docs.map(d => ({
|
||||||
result ? resolve(result) : reject();
|
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() {
|
isDarkColors() {
|
||||||
@ -211,6 +246,10 @@ window.utools = window.rubick = {
|
|||||||
setFeature(feature) {
|
setFeature(feature) {
|
||||||
ipcRenderer.sendToHost('setFeature', {feature});
|
ipcRenderer.sendToHost('setFeature', {feature});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeFeature(code) {
|
||||||
|
ipcRenderer.sendToHost('removeFeature', {code});
|
||||||
|
},
|
||||||
ubrowser: {
|
ubrowser: {
|
||||||
winId: '',
|
winId: '',
|
||||||
async goto(md, opts) {
|
async goto(md, opts) {
|
||||||
@ -282,9 +321,19 @@ window.utools = window.rubick = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 系统
|
||||||
shellOpenExternal(url) {
|
shellOpenExternal(url) {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
isMacOs() {
|
||||||
|
return os.type() === 'Darwin';
|
||||||
|
},
|
||||||
|
|
||||||
|
isWindows() {
|
||||||
|
return os.type() === 'Windows_NT';
|
||||||
|
},
|
||||||
}
|
}
|
||||||
const preloadPath = getQueryVariable('preloadPath') || './preload.js';
|
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