feat: 支持文本模板,系统命令

This commit is contained in:
muwoo
2021-06-10 20:54:28 +08:00
parent 31e7e17cc9
commit 31d57fc404
29 changed files with 377 additions and 205 deletions

View File

@@ -16,7 +16,7 @@
id="search"
:placeholder="subPlaceHolder && selected && selected.key === 'plugin-container' ? subPlaceHolder : 'Hi, Rubick'"
class="main-input"
@change="onSearch"
@change="e => onSearch({value: e.target.value})"
:value="searchValue"
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
>
@@ -49,7 +49,7 @@
<a-input
:placeholder="subPlaceHolder"
class="sub-input"
@change="onSearch"
@change="(e) => onSearch({value: e.target.value, searchType: $route.query.searchType})"
:value="searchValue"
></a-input>
</div>
@@ -84,8 +84,6 @@ export default {
const searchNd = document.getElementById('search');
searchNd && searchNd.addEventListener('keydown', this.checkNeedInit)
},
beforeDestroy() {
},
methods: {
...mapActions('main', ['onSearch', 'showMainUI']),
...mapMutations('main', ['commonUpdate']),
@@ -104,8 +102,9 @@ export default {
this.commonUpdate({
selected: null,
showMain: false,
options: [],
});
ipcRenderer.send('changeWindowSize', {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([]),
});
this.$router.push({
@@ -167,7 +166,7 @@ export default {
}
};
</script>
<style lang="scss">
<style lang="less">
* {
margin: 0;
padding: 0;

View File

@@ -2,8 +2,36 @@ const WINDOW_MAX_HEIGHT = 600;
const WINDOW_MIN_HEIGHT = 60;
const PRE_ITEM_HEIGHT = 60;
const SYSTEM_PLUGINS = [
{
"pluginName": "rubick 帮助文档",
"logo": "logo.png",
"features": [
{
"code": "help",
"explain": "rubick 帮助文档",
"cmds": [ "Help", "帮助" ]
},
],
"tag": 'rubick-help',
},
{
"pluginName": "屏幕颜色拾取",
"logo": "logo.png",
"features": [
{
"code": "pick",
"explain": "rubick 帮助文档",
"cmds": [ "取色", "拾色", 'Pick color' ]
},
],
"tag": 'rubick-color',
}
]
export {
WINDOW_MAX_HEIGHT,
WINDOW_MIN_HEIGHT,
PRE_ITEM_HEIGHT,
SYSTEM_PLUGINS,
}

View File

@@ -0,0 +1,13 @@
import {shell, ipcRenderer} from 'electron';
export default {
'rubick-help': {
help() {
shell.openExternal('https://u.tools/docs/guide/about-uTools.html')
}
},
'rubick-color': {
pick() {
ipcRenderer.send('start-picker')
}
}
}

View File

@@ -1,4 +1,4 @@
import {WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT} from './constans';
import {WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS} from './constans';
import download from 'download-git-repo';
import path from 'path';
import fs from 'fs';
@@ -14,7 +14,6 @@ function getWindowHeight(searchList) {
}
function searchKeyValues(lists, value){
console.log(lists);
return lists.filter(item => item.indexOf(value) >= 0)
}
@@ -90,9 +89,24 @@ const sysFile = {
}
}
function mergePlugins(plugins) {
return [
...plugins,
...SYSTEM_PLUGINS.map(plugin => {
return {
...plugin,
status: true,
sourceFile: '',
type: 'system',
}
}),
]
}
export {
getWindowHeight,
searchKeyValues,
downloadFunc,
sysFile,
mergePlugins,
}

View File

@@ -46,7 +46,7 @@ export default {
},
}
</script>
<style lang="scss">
<style lang="less">
.fava-btn {
cursor: pointer;
&:hover {

View File

@@ -10,6 +10,10 @@
<script>
import path from 'path';
import {mapMutations, mapState} from 'vuex';
import {remote} from "electron";
const currentWindow = remote.getCurrentWindow();
const winId = currentWindow.id;
export default {
name: "index.vue",
@@ -20,7 +24,7 @@ export default {
webview: null,
query: this.$route.query,
config: {},
templatePath: `File://${path.join(__static, './doc-tpl.html')}?code=${JSON.parse(this.$route.query.detail).code}&targetFile=${encodeURIComponent(this.$route.query.sourceFile)}`,
templatePath: `File://${path.join(__static, './plugins/doc/doc-tpl.html')}?code=${JSON.parse(this.$route.query.detail).code}&targetFile=${encodeURIComponent(this.$route.query.sourceFile)}`,
}
},
mounted() {
@@ -90,9 +94,9 @@ export default {
}
</script>
<style lang="scss">
<style lang="less">
#webview {
width: 100%;
height: calc(100vh - 60px);
height: calc(~'100vh - 60px');
}
</style>

View File

@@ -45,7 +45,7 @@ export default {
}
</script>
<style lang="scss">
<style lang="less">
.main-input {
-webkit-app-region: drag;
height: 60px !important;

View File

@@ -110,9 +110,9 @@ export default {
}
</script>
<style lang="scss">
<style lang="less">
.dev-container {
height: calc(100vh - 110px);
height: calc(~'100vh - 110px');
.dev-detail {
display: flex;
align-items: flex-start;

View File

@@ -74,9 +74,9 @@ export default {
}
</script>
<style lang="scss">
<style lang="less">
.market {
height: calc(100vh - 110px);
height: calc(~'100vh - 110px');
background: #fff;
padding: 20px;
box-sizing: border-box;

View File

@@ -95,9 +95,9 @@ export default {
}
</script>
<style lang="scss">
<style lang="less">
.dev-container {
height: calc(100vh - 110px);
height: calc(~'100vh - 110px');
overflow: auto;
.dev-detail {
display: flex;

View File

@@ -1,6 +1,13 @@
import {clipboard, ipcRenderer, remote} from "electron";
import { v4 as uuidv4 } from 'uuid';
import {getWindowHeight, searchKeyValues, downloadFunc, sysFile} from '../../assets/common/utils';
import {
getWindowHeight,
searchKeyValues,
downloadFunc,
sysFile,
mergePlugins,
} from '../../assets/common/utils';
import systemMethod from '../../assets/common/system';
import fs from "fs";
import path from 'path';
@@ -10,7 +17,7 @@ const state = {
showMain: false,
current: ['market'],
searchValue: '',
devPlugins: sysFile.getUserPlugins() || [],
devPlugins: mergePlugins(sysFile.getUserPlugins() || []),
subPlaceHolder: '',
}
@@ -48,7 +55,7 @@ const mutations = {
const actions = {
showMainUI ({ commit, state }, paylpad) {
ipcRenderer.send('changeWindowSize', {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),
});
setTimeout(() => {
@@ -85,9 +92,9 @@ const actions = {
commit('commonUpdate', {searchValue: ''});
return;
}
const value = paylpad.target.value;
const value = paylpad.value;
// 在插件界面
if(state.selected && state.selected.key === 'plugin-container') {
if((state.selected && state.selected.key === 'plugin-container') || paylpad.searchType === 'subWindow') {
commit('commonUpdate', {searchValue: value})
return;
}
@@ -131,7 +138,7 @@ const actions = {
},
current: ['dev'],
});
ipcRenderer.send('changeWindowSize', {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),
});
router.push('/home/dev')
@@ -149,7 +156,7 @@ const actions = {
]
});
// 调整窗口大小
ipcRenderer.send('changeWindowSize', {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(state.options),
});
return
@@ -184,7 +191,7 @@ const actions = {
commit('commonUpdate', {
options
});
ipcRenderer.send('changeWindowSize', {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(state.options),
});
},
@@ -212,9 +219,24 @@ const actions = {
searchValue: '',
showMain: true,
});
ipcRenderer.send('changeWindowSize', {
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),
});
if (plugin.type === 'system') {
systemMethod[plugin.tag][feature.code]()
commit('commonUpdate', {
selected: null,
showMain: false,
options: [],
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight([]),
});
router.push({
path: '/home',
});
return;
}
router.push({
path: '/plugin',
query: {