From 0abdb3cf00ab346534dbd12d21f2ccd7d89d30dc Mon Sep 17 00:00:00 2001
From: Molunerfinn <marksz@teamsz.xyz>
Date: Tue, 15 Jan 2019 17:28:50 +0800
Subject: [PATCH] Fixed: #166 & add showNotification for guiApi

---
 src/main/utils/guiApi.js       | 18 ++++++++++++++++++
 src/main/utils/picgoCoreIPC.js | 10 ++++++++--
 src/renderer/pages/Plugin.vue  | 12 +++++++++---
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/main/utils/guiApi.js b/src/main/utils/guiApi.js
index 8a8a3c3..cc0066b 100644
--- a/src/main/utils/guiApi.js
+++ b/src/main/utils/guiApi.js
@@ -82,6 +82,24 @@ class GuiApi {
     }
     return []
   }
+
+  /**
+   * For notification
+   * @param {Object} options
+   */
+  showNotification (options) {
+    if (options === undefined) {
+      options = {
+        title: '',
+        body: ''
+      }
+    }
+    const notification = new Notification({
+      title: options.title,
+      body: options.body
+    })
+    notification.show()
+  }
 }
 
 export default GuiApi
diff --git a/src/main/utils/picgoCoreIPC.js b/src/main/utils/picgoCoreIPC.js
index 55475fc..a0d16c9 100644
--- a/src/main/utils/picgoCoreIPC.js
+++ b/src/main/utils/picgoCoreIPC.js
@@ -49,13 +49,19 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
       if (plugin.guiMenu) {
         menu = plugin.guiMenu(picgo)
       }
+      let gui = false
+      if (pluginPKG.keywords && pluginPKG.keywords.length > 0) {
+        if (pluginPKG.keywords.includes('picgo-gui-plugin')) {
+          gui = true
+        }
+      }
       const obj = {
         name: pluginList[i].replace(/picgo-plugin-/, ''),
         author: pluginPKG.author.name || pluginPKG.author,
         description: pluginPKG.description,
         logo: 'file://' + path.join(pluginPath, 'logo.png').split(path.sep).join('/'),
         version: pluginPKG.version,
-        gui: pluginPKG.gui || false,
+        gui,
         config: {
           plugin: {
             name: pluginList[i].replace(/picgo-plugin-/, ''),
@@ -70,7 +76,7 @@ const handleGetPluginList = (ipcMain, STORE_PATH, CONFIG_PATH) => {
             config: handleConfigWithFunction(getConfig(uploaderName, 'transformer', picgo))
           }
         },
-        enabled: picgo.getConfig(`plugins.${pluginList[i]}`),
+        enabled: picgo.getConfig(`picgoPlugins.${pluginList[i]}`),
         homepage: pluginPKG.homepage ? pluginPKG.homepage : '',
         guiMenu: menu,
         ing: false
diff --git a/src/renderer/pages/Plugin.vue b/src/renderer/pages/Plugin.vue
index c381cc5..be385f0 100644
--- a/src/renderer/pages/Plugin.vue
+++ b/src/renderer/pages/Plugin.vue
@@ -219,7 +219,7 @@ export default {
         label: '启用插件',
         enabled: !plugin.enabled,
         click () {
-          _this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, true).write()
+          _this.$db.read().set(`picgoPlugins.picgo-plugin-${plugin.name}`, true).write()
           plugin.enabled = true
           _this.getPicBeds()
         }
@@ -227,7 +227,7 @@ export default {
         label: '禁用插件',
         enabled: plugin.enabled,
         click () {
-          _this.$db.read().set(`plugins.picgo-plugin-${plugin.name}`, false).write()
+          _this.$db.read().set(`picgoPlugins.picgo-plugin-${plugin.name}`, false).write()
           plugin.enabled = false
           _this.getPicBeds()
           if (plugin.config.transformer.name) {
@@ -398,6 +398,12 @@ export default {
     },
     handleSearchResult (item) {
       const name = item.package.name.replace(/picgo-plugin-/, '')
+      let gui = false
+      if (item.package.keywords && item.package.keywords.length > 0) {
+        if (item.package.keywords.includes('picgo-gui-plugin')) {
+          gui = true
+        }
+      }
       return {
         name: name,
         author: item.package.author.name,
@@ -407,7 +413,7 @@ export default {
         homepage: item.package.links ? item.package.links.homepage : '',
         hasInstall: this.pluginNameList.some(plugin => plugin === item.package.name.replace(/picgo-plugin-/, '')),
         version: item.package.version,
-        gui: item.package.gui || false,
+        gui,
         ing: false // installing or uninstalling
       }
     },