From d38dcab9ccaf4b1e660ab921290f955172b1181d Mon Sep 17 00:00:00 2001 From: sovlookup Date: Thu, 26 Aug 2021 12:57:04 +0800 Subject: [PATCH] feat: linux version --- src/main/browsers/index.js | 2 +- src/main/browsers/main.js | 31 ++++++++++----------- src/main/browsers/picker.js | 25 ++++++++--------- src/main/browsers/separate.js | 27 ++++++++++--------- src/main/common/config.js | 51 ++++++++++++++++++++++++++--------- 5 files changed, 82 insertions(+), 54 deletions(-) diff --git a/src/main/browsers/index.js b/src/main/browsers/index.js index c2e3cf1..928e4d0 100644 --- a/src/main/browsers/index.js +++ b/src/main/browsers/index.js @@ -3,4 +3,4 @@ module.exports = () => ({ separator: require("./separate")(), superPanel: require("./superPanel")(), main: require("./main")(), -}); +}) diff --git a/src/main/browsers/main.js b/src/main/browsers/main.js index 752cf38..79d2fab 100644 --- a/src/main/browsers/main.js +++ b/src/main/browsers/main.js @@ -1,10 +1,10 @@ -const { BrowserWindow, protocol } = require("electron"); +const { BrowserWindow, protocol } = require("electron") module.exports = () => { - let win; + let win let init = (opts) => { - createWindow(opts); - }; + createWindow(opts) + } let createWindow = (opts) => { const winURL = process.env.NODE_ENV === 'development' @@ -23,6 +23,7 @@ module.exports = () => { webSecurity: false, enableRemoteModule: true, backgroundThrottling: false, + contextIsolation: false, webviewTag: true, nodeIntegration: true // 在网页中集成Node } @@ -31,24 +32,24 @@ module.exports = () => { win.loadURL(winURL) protocol.interceptFileProtocol('image', (req, callback) => { - const url = req.url.substr(8); - callback(decodeURI(url)); + const url = req.url.substr(8) + callback(decodeURI(url)) }, (error) => { if (error) { - console.error('Failed to register protocol'); + console.error('Failed to register protocol') } - }); + }) - win.once('ready-to-show', () => win.show()); + win.once('ready-to-show', () => win.show()) win.on("closed", () => { - win = undefined; - }); - }; + win = undefined + }) + } - let getWindow = () => win; + let getWindow = () => win return { init: init, getWindow: getWindow, - }; -}; + } +} diff --git a/src/main/browsers/picker.js b/src/main/browsers/picker.js index 4c350e4..0950c4a 100644 --- a/src/main/browsers/picker.js +++ b/src/main/browsers/picker.js @@ -1,13 +1,13 @@ -const { BrowserWindow, nativeImage } = require("electron"); +const { BrowserWindow, nativeImage } = require("electron") module.exports = () => { - let win; + let win let init = (x, y) => { if (win === null || win === undefined) { - createWindow(); + createWindow() } - }; + } let createWindow = () => { win = new BrowserWindow({ @@ -22,20 +22,21 @@ module.exports = () => { hasShadow: false, webPreferences: { nodeIntegration: true, + contextIsolation: false, devTools: false, }, - }); + }) - win.loadURL(`file://${__static}/plugins/picker/index.html`); + win.loadURL(`file://${__static}/plugins/picker/index.html`) win.on("closed", () => { - win = undefined; - }); - }; + win = undefined + }) + } - let getWindow = () => win; + let getWindow = () => win return { init: init, getWindow: getWindow, - }; -}; + } +} diff --git a/src/main/browsers/separate.js b/src/main/browsers/separate.js index 1b39ab1..87ff803 100644 --- a/src/main/browsers/separate.js +++ b/src/main/browsers/separate.js @@ -1,11 +1,11 @@ -const { BrowserWindow } = require("electron"); +const { BrowserWindow } = require("electron") module.exports = () => { - let win; + let win let init = (opts) => { - createWindow(opts); - }; + createWindow(opts) + } let createWindow = (opts) => { const winURL = process.env.NODE_ENV === 'development' @@ -22,27 +22,28 @@ module.exports = () => { webSecurity: false, enableRemoteModule: true, backgroundThrottling: false, + contextIsolation: false, webviewTag: true, nodeIntegration: true // 在网页中集成Node } - }); + }) process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, { hash: `#/plugin`, - }); + }) win.webContents.executeJavaScript(`window.setPluginInfo(${opts})`).then(() => { win.show() - }); + }) win.on("closed", () => { - win = undefined; - }); - }; + win = undefined + }) + } - let getWindow = () => win; + let getWindow = () => win return { init: init, getWindow: getWindow, - }; -}; + } +} diff --git a/src/main/common/config.js b/src/main/common/config.js index 73d48bb..a844b8c 100644 --- a/src/main/common/config.js +++ b/src/main/common/config.js @@ -1,9 +1,9 @@ -import path from "path"; -import fs from 'fs'; -import {getlocalDataFile} from "./utils"; -import os from 'os'; +import path from "path" +import fs from 'fs' +import { getlocalDataFile } from "./utils" +import os from 'os' -const configPath = path.join(getlocalDataFile(), './rubick-config.json'); +const configPath = path.join(getlocalDataFile(), './rubick-config.json') let defaultConfig = { Darwin: { @@ -55,30 +55,55 @@ let defaultConfig = { mouseDownTime: 500 }, global: [] + }, + Linux: { + version: 1, + perf: { + shortCut: { + showAndHidden: 'Option+R', + separate: 'Ctrl+D', + quit: 'Shift+Escape' + }, + common: { + start: true, + space: true, + }, + local: { + search: true, + } + }, + superPanel: { + baiduAPI: { + key: '', + appid: '', + }, + mouseDownTime: 500 + }, + global: [] } } global.opConfig = { config: null, get() { - const platform = os.type(); + const platform = os.type() try { if (!opConfig.config) { - opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform])); + opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform])) } // 重置 if (!opConfig.version || opConfig.version < defaultConfig[platform].version) { - opConfig.config = defaultConfig[platform]; - fs.writeFileSync(configPath, JSON.stringify(opConfig.config)); + opConfig.config = defaultConfig[platform] + fs.writeFileSync(configPath, JSON.stringify(opConfig.config)) } - return opConfig.config; + return opConfig.config } catch (e) { opConfig.config = defaultConfig[platform] - return opConfig.config; + return opConfig.config } }, set(key, value) { - opConfig.config[key] = value; - fs.writeFileSync(configPath, JSON.stringify(opConfig.config)); + opConfig.config[key] = value + fs.writeFileSync(configPath, JSON.stringify(opConfig.config)) } }