From bda7f0c091abbe13704d1e914b40db42798c5b40 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Tue, 6 Jul 2021 12:13:35 +0800 Subject: [PATCH] =?UTF-8?q?ref:=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=20&?= =?UTF-8?q?=20bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/browsers/index.js | 1 + src/main/browsers/main.js | 53 +++++++++++++++++++++ src/main/index.js | 74 ++++------------------------- src/renderer/assets/common/utils.js | 15 ++++-- 4 files changed, 74 insertions(+), 69 deletions(-) create mode 100644 src/main/browsers/main.js diff --git a/src/main/browsers/index.js b/src/main/browsers/index.js index 1c095bb..3cbc090 100644 --- a/src/main/browsers/index.js +++ b/src/main/browsers/index.js @@ -3,4 +3,5 @@ module.exports = () => ({ separator: require("./separate")(), capture: require("./capture")(), superPanel: require("./superPanel")(), + main: require("./main")(), }); diff --git a/src/main/browsers/main.js b/src/main/browsers/main.js new file mode 100644 index 0000000..71d928d --- /dev/null +++ b/src/main/browsers/main.js @@ -0,0 +1,53 @@ +const { BrowserWindow, protocol } = require("electron"); +module.exports = () => { + let win; + + let init = (opts) => { + createWindow(opts); + }; + + let createWindow = (opts) => { + const winURL = process.env.NODE_ENV === 'development' + ? `http://localhost:9080` + : `file://${__dirname}/index.html` + + win = new BrowserWindow({ + height: 60, + useContentSize: true, + width: 800, + frame: false, + title: '拉比克', + show: false, + webPreferences: { + webSecurity: false, + enableRemoteModule: true, + backgroundThrottling: false, + webviewTag: true, + nodeIntegration: true // 在网页中集成Node + } + }) + + win.loadURL(winURL) + + protocol.interceptFileProtocol('image', (req, callback) => { + const url = req.url.substr(8); + callback(decodeURI(url)); + }, (error) => { + if (error) { + console.error('Failed to register protocol'); + } + }); + + win.once('ready-to-show', () => win.show()); + win.on("closed", () => { + win = undefined; + }); + }; + + let getWindow = () => win; + + return { + init: init, + getWindow: getWindow, + }; +}; diff --git a/src/main/index.js b/src/main/index.js index 8ed5722..12d7799 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,9 +1,9 @@ -import { app, BrowserWindow, protocol } from 'electron' +import { app } from 'electron' import '../renderer/store' import init from './common/common'; import {autoUpdate} from './common/autoUpdate'; import createTray from './tray'; -const {capture} = require("./browsers")(); +const {capture, main} = require("./browsers")(); /** * Set `__static` path to static files in production * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html @@ -13,50 +13,17 @@ if (process.env.NODE_ENV !== 'development') { } // to fix https://github.com/electron/electron/issues/18397 app.allowRendererProcessReuse = false; -let mainWindow -const winURL = process.env.NODE_ENV === 'development' - ? `http://localhost:9080` - : `file://${__dirname}/index.html` +app.dock.hide(); -function createWindow () { - /** - * Initial window options - */ - capture.useCapture() - mainWindow = new BrowserWindow({ - height: 60, - useContentSize: true, - width: 800, - frame: false, - title: '拉比克', - webPreferences: { - webSecurity: false, - enableRemoteModule: true, - backgroundThrottling: false, - webviewTag: true, - nodeIntegration: true // 在网页中集成Node - } - }) - - mainWindow.loadURL(winURL) - - mainWindow.on('closed', () => { - mainWindow = null - }); - protocol.interceptFileProtocol('image', (req, callback) => { - const url = req.url.substr(8); - callback(decodeURI(url)); - }, (error) => { - if (error) { - console.error('Failed to register protocol'); - } - }); - init(mainWindow); +function createWindow() { + capture.useCapture(); + main.init(); + init(main.getWindow()); } app.on('ready', () => { createWindow() - createTray(mainWindow); + createTray(main.getWindow()); autoUpdate(); }) @@ -67,27 +34,6 @@ app.on('window-all-closed', () => { }) app.on('activate', () => { - if (mainWindow === null) { - createWindow() - } -}) + createWindow() +}); -/** - * Auto Updater - * - * Uncomment the following code below and install `electron-updater` to - * support auto updating. Code Signing with a valid certificate is required. - * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating - */ - -/* -import { autoUpdater } from 'electron-updater' - -autoUpdater.on('update-downloaded', () => { - autoUpdater.quitAndInstall() -}) - -app.on('ready', () => { - if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates() -}) - */ diff --git a/src/renderer/assets/common/utils.js b/src/renderer/assets/common/utils.js index 1668661..341fcea 100644 --- a/src/renderer/assets/common/utils.js +++ b/src/renderer/assets/common/utils.js @@ -74,7 +74,7 @@ const sysFile = { }, getUserPlugins() { try { - return store.get('user-plugins').devPlugins; + return store.get('user-plugins'); } catch (e) { return [] } @@ -97,15 +97,20 @@ function mergePlugins(plugins) { }) ] - return result.filter((item, i) => { - let targetIndex; - result.forEach((tg, j) => { + const target = []; + + result.forEach((item, i) => { + let targetIndex = -1; + target.forEach((tg, j) => { if (tg.tag === item.tag && tg.type === 'system') { targetIndex = j } }); - return i === targetIndex; + if (targetIndex === -1) { + target.push(item) + } }); + return target } function find(p, target = 'plugin.json') {