mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-13 06:54:05 +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) || {};
|
||||
},
|
||||
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,
|
||||
|
@ -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;
|
||||
|
@ -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,89 @@ 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 +246,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 +321,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