diff --git a/src/main/api.js b/src/main/api.js index 7cdcec7..6234c93 100644 --- a/src/main/api.js +++ b/src/main/api.js @@ -1,6 +1,8 @@ -import {app} from 'electron'; +import {app, BrowserWindow} from 'electron'; import {getlocalDataFile, saveData, getData} from './common/utils'; import path from "path"; +import marked from 'marked'; +const rendererMD = new marked.Renderer(); const appPath = path.join(getlocalDataFile()); const dbPath = path.join(appPath, './db.json'); @@ -10,7 +12,6 @@ export default { return app.getPath(arg.name); }, hideMainWindow(arg, mainWindow) { - console.log(111, mainWindow) mainWindow.hide(); }, showMainWindow(arg, mainWindow) { @@ -20,15 +21,13 @@ export default { return arg }, setExpendHeight({height}, mainWindow) { - console.log(height); - mainWindow.setSize(788, height); + mainWindow.setSize(788, height || 60); }, db: { put({data}) { data._rev = ''; let dbData = getData(dbPath) || []; let target = []; - console.log(data, dbData); dbData.some((d, i) => { if (d._id === data._id) { target = [d, i] @@ -102,5 +101,37 @@ export default { const result = dbData.filter(d => d._id === key); return result; } + }, + + ubrowser: { + goto: ({md, title}) => { + marked.setOptions({ + renderer: rendererMD, + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: true, + smartypants: false + }); + const htmlContent = marked(md); + const win = new BrowserWindow({ + height: 600, + useContentSize: true, + width: 788, + title, + webPreferences: { + webSecurity: false, + enableRemoteModule: true, + backgroundThrottling: false, + webviewTag: true, + nodeIntegration: true // 在网页中集成Node + } + }); + win.loadURL('data:text/html;charset=UTF-8,' + encodeURIComponent(htmlContent)) + win.once('ready-to-show', () => win.show()); + return win.id + } } } diff --git a/src/main/index.js b/src/main/index.js index 01fb445..9116cc4 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -39,7 +39,7 @@ function createWindow () { mainWindow.on('closed', () => { mainWindow = null }); - protocol.interceptFileProtocol('file', (req, callback) => { + protocol.interceptFileProtocol('image', (req, callback) => { const url = req.url.substr(8); callback(decodeURI(url)); }, (error) => { diff --git a/src/renderer/pages/plugins/index.vue b/src/renderer/pages/plugins/index.vue index c1d5c43..ca5b86e 100644 --- a/src/renderer/pages/plugins/index.vue +++ b/src/renderer/pages/plugins/index.vue @@ -1,6 +1,9 @@ @@ -15,6 +18,9 @@ export default { path: `File://${this.$route.query.sourceFile}`, preload: `File://${path.join(__static, './preload.js')}`, 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)}`, } }, mounted() { @@ -28,10 +34,40 @@ export default { if (event.channel === 'setSubInput') { this.setSubPlaceHolder(event.args[0].placeHolder); } + if (event.channel === 'removeSubInput') { + this.commonUpdate({ + searchValue: '', + }); + } + if (event.channel === 'setSubInputValue') { + this.commonUpdate({ + searchValue: event.args[0].text, + }); + this.webview.send('msg-back-setSubInput', this.searchValue); + } + if (event.channel === 'templateConfig') { + this.config = event.args[0].config; + } + if (event.channel === 'getFeatures') { + this.webview.send('msg-back-getFeatures', this.pluginDetail); + } + if (event.channel === 'setFeature') { + this.commonUpdate({ + devPlugins: this.devPlugins.map(plugin => { + if (plugin.name === this.query.name) { + return { + ...plugin, + features: [...plugin.features, event.args[0].feature] + } + } + return plugin; + }), + }); + } }) }, methods: { - ...mapMutations('main', ['setSubPlaceHolder']), + ...mapMutations('main', ['setSubPlaceHolder', 'commonUpdate']), }, beforeRouteUpdate() { this.path = `File://${this.$route.query.sourceFile}` @@ -41,7 +77,10 @@ export default { webview && webview.send('onPluginOut', this.$route.query) }, computed: { - ...mapState('main', ['searchValue']) + ...mapState('main', ['searchValue', 'devPlugins']), + pluginDetail() { + return (this.devPlugins.filter(plugin => plugin.name === this.query.name)[0] || {}).features + }, }, watch: { searchValue() { diff --git a/src/renderer/store/modules/main.js b/src/renderer/store/modules/main.js index 45da8e7..516d043 100644 --- a/src/renderer/store/modules/main.js +++ b/src/renderer/store/modules/main.js @@ -99,9 +99,15 @@ const actions = { const pluginConfig = { ...config, - sourceFile: path.join(fileUrl, `../${config.main}`), + sourceFile: path.join(fileUrl, `../${config.main || 'index.html'}`), name: uuidv4(), - type: 'dev' + type: 'dev', + subType: (() => { + if (config.main) { + return '' + } + return 'template'; + })() }; commit('commonUpdate', { selected: { @@ -164,7 +170,7 @@ const actions = { ...cmds.map((cmd) => ({ name: cmd, value: 'plugin', - icon: 'file://' + path.join(plugin.sourceFile, `../${plugin.logo}`), + icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`), desc: fe.explain, click: (router) => { actions.openPlugin({commit}, {cmd, plugin, feature: fe, router}); @@ -201,7 +207,7 @@ const actions = { selected: { key: 'plugin-container', name: cmd, - icon: 'file://' + path.join(plugin.sourceFile, `../${plugin.logo}`), + icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`), }, searchValue: '', showMain: true, diff --git a/static/doc-tpl.html b/static/doc-tpl.html new file mode 100644 index 0000000..12dce7a --- /dev/null +++ b/static/doc-tpl.html @@ -0,0 +1,65 @@ + + + + + Title + + + + + +
+ +
+ + + + diff --git a/static/doc.js b/static/doc.js new file mode 100644 index 0000000..4668a24 --- /dev/null +++ b/static/doc.js @@ -0,0 +1,28 @@ +export default { + template: ` +
+ +