mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-21 03:32:44 +08:00
Merge pull request #34 from SOVLOOKUP/cross-platform
Cross platform Linux 跨平台适配
This commit is contained in:
commit
a489a8f130
5
.pnpm-debug.log
Normal file
5
.pnpm-debug.log
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"0 debug pnpm:scope": {
|
||||||
|
"selected": 1
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,7 @@
|
|||||||
## 使用问题
|
## 使用问题
|
||||||
1. 依赖于 `robotjs` dev 环境运行请在 `install` 后执行 `npm run rebuild`
|
1. 依赖于 `robotjs` dev 环境运行请在 `install` 后执行 `npm run rebuild`
|
||||||
2. windows 版本目前有了一个最基础的可用版,代码在 [feat-win](https://github.com/clouDr-f2e/rubick/tree/feat-win) 分支。完整版正在开发中,敬请期待
|
2. windows 版本目前有了一个最基础的可用版,代码在 [feat-win](https://github.com/clouDr-f2e/rubick/tree/feat-win) 分支。完整版正在开发中,敬请期待
|
||||||
|
3. linux 开发分支 cross-platform 的 iohook 开发模式下可能需要手动下载并放入node_modules, 将在未来修复
|
||||||
|
|
||||||
## 目前支持能力
|
## 目前支持能力
|
||||||
|
|
||||||
|
13
package.json
13
package.json
@ -10,7 +10,8 @@
|
|||||||
"build": "node .electron-vue/build.js && electron-builder",
|
"build": "node .electron-vue/build.js && electron-builder",
|
||||||
"dev": "node .electron-vue/dev-runner.js",
|
"dev": "node .electron-vue/dev-runner.js",
|
||||||
"rebuild": " ./node_modules/.bin/electron-rebuild",
|
"rebuild": " ./node_modules/.bin/electron-rebuild",
|
||||||
"rebuild_win": "npm rebuild --runtime=electron --target=11.4.10 --disturl=https://atom.io/download/atom-shell --abi=85"
|
"rebuild_win": "npm rebuild --runtime=electron --target=11.4.10 --disturl=https://atom.io/download/atom-shell --abi=85",
|
||||||
|
"rebuild_linux": "npm rebuild --runtime=electron --target=12.0.15 --disturl=https://atom.io/download/atom-shell --abi=87"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"asar": true,
|
"asar": true,
|
||||||
@ -99,6 +100,7 @@
|
|||||||
"babel-preset-env": "^1.7.0",
|
"babel-preset-env": "^1.7.0",
|
||||||
"babel-preset-stage-0": "^6.24.1",
|
"babel-preset-stage-0": "^6.24.1",
|
||||||
"babel-register": "^6.26.0",
|
"babel-register": "^6.26.0",
|
||||||
|
"babel-runtime": "^6.26.0",
|
||||||
"cfonts": "^2.1.2",
|
"cfonts": "^2.1.2",
|
||||||
"chalk": "^2.4.1",
|
"chalk": "^2.4.1",
|
||||||
"copy-webpack-plugin": "^4.5.1",
|
"copy-webpack-plugin": "^4.5.1",
|
||||||
@ -106,7 +108,7 @@
|
|||||||
"css-loader": "^0.28.11",
|
"css-loader": "^0.28.11",
|
||||||
"del": "^3.0.0",
|
"del": "^3.0.0",
|
||||||
"devtron": "^1.4.0",
|
"devtron": "^1.4.0",
|
||||||
"electron": "^11.0.2",
|
"electron": "^12.0.15",
|
||||||
"electron-builder": "22.10.5",
|
"electron-builder": "22.10.5",
|
||||||
"electron-debug": "^1.5.0",
|
"electron-debug": "^1.5.0",
|
||||||
"electron-devtools-installer": "^2.2.4",
|
"electron-devtools-installer": "^2.2.4",
|
||||||
@ -137,15 +139,16 @@
|
|||||||
"iohook": {
|
"iohook": {
|
||||||
"targets": [
|
"targets": [
|
||||||
"node-83",
|
"node-83",
|
||||||
"electron-85"
|
"electron-87"
|
||||||
],
|
],
|
||||||
"platforms": [
|
"platforms": [
|
||||||
"darwin",
|
"darwin",
|
||||||
"win32"
|
"win32",
|
||||||
|
"linux"
|
||||||
],
|
],
|
||||||
"arches": [
|
"arches": [
|
||||||
"x64",
|
"x64",
|
||||||
"ia32"
|
"ia32"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
11829
pnpm-lock.yaml
generated
Normal file
11829
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,4 +3,4 @@ module.exports = () => ({
|
|||||||
separator: require("./separate")(),
|
separator: require("./separate")(),
|
||||||
superPanel: require("./superPanel")(),
|
superPanel: require("./superPanel")(),
|
||||||
main: require("./main")(),
|
main: require("./main")(),
|
||||||
});
|
})
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
const { BrowserWindow, protocol } = require("electron");
|
const { BrowserWindow, protocol } = require("electron")
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
let win;
|
let win
|
||||||
|
|
||||||
let init = (opts) => {
|
let init = (opts) => {
|
||||||
createWindow(opts);
|
createWindow(opts)
|
||||||
};
|
}
|
||||||
|
|
||||||
let createWindow = (opts) => {
|
let createWindow = (opts) => {
|
||||||
const winURL = process.env.NODE_ENV === 'development'
|
const winURL = process.env.NODE_ENV === 'development'
|
||||||
@ -23,6 +23,7 @@ module.exports = () => {
|
|||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
enableRemoteModule: true,
|
enableRemoteModule: true,
|
||||||
backgroundThrottling: false,
|
backgroundThrottling: false,
|
||||||
|
contextIsolation: false,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true // 在网页中集成Node
|
nodeIntegration: true // 在网页中集成Node
|
||||||
}
|
}
|
||||||
@ -31,24 +32,24 @@ module.exports = () => {
|
|||||||
win.loadURL(winURL)
|
win.loadURL(winURL)
|
||||||
|
|
||||||
protocol.interceptFileProtocol('image', (req, callback) => {
|
protocol.interceptFileProtocol('image', (req, callback) => {
|
||||||
const url = req.url.substr(8);
|
const url = req.url.substr(8)
|
||||||
callback(decodeURI(url));
|
callback(decodeURI(url))
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
if (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.on("closed", () => {
|
||||||
win = undefined;
|
win = undefined
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
let getWindow = () => win;
|
let getWindow = () => win
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
getWindow: getWindow,
|
getWindow: getWindow,
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
const { BrowserWindow, nativeImage } = require("electron");
|
const { BrowserWindow, nativeImage } = require("electron")
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
let win;
|
let win
|
||||||
|
|
||||||
let init = (x, y) => {
|
let init = (x, y) => {
|
||||||
if (win === null || win === undefined) {
|
if (win === null || win === undefined) {
|
||||||
createWindow();
|
createWindow()
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
let createWindow = () => {
|
let createWindow = () => {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
@ -22,20 +22,21 @@ module.exports = () => {
|
|||||||
hasShadow: false,
|
hasShadow: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
|
contextIsolation: false,
|
||||||
devTools: false,
|
devTools: false,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|
||||||
win.loadURL(`file://${__static}/plugins/picker/index.html`);
|
win.loadURL(`file://${__static}/plugins/picker/index.html`)
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
win = undefined;
|
win = undefined
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
let getWindow = () => win;
|
let getWindow = () => win
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
getWindow: getWindow,
|
getWindow: getWindow,
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
const { BrowserWindow } = require("electron");
|
const { BrowserWindow } = require("electron")
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
let win;
|
let win
|
||||||
|
|
||||||
let init = (opts) => {
|
let init = (opts) => {
|
||||||
createWindow(opts);
|
createWindow(opts)
|
||||||
};
|
}
|
||||||
|
|
||||||
let createWindow = (opts) => {
|
let createWindow = (opts) => {
|
||||||
const winURL = process.env.NODE_ENV === 'development'
|
const winURL = process.env.NODE_ENV === 'development'
|
||||||
@ -22,27 +22,28 @@ module.exports = () => {
|
|||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
enableRemoteModule: true,
|
enableRemoteModule: true,
|
||||||
backgroundThrottling: false,
|
backgroundThrottling: false,
|
||||||
|
contextIsolation: false,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
nodeIntegration: true // 在网页中集成Node
|
nodeIntegration: true // 在网页中集成Node
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, {
|
process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, {
|
||||||
hash: `#/plugin`,
|
hash: `#/plugin`,
|
||||||
});
|
})
|
||||||
|
|
||||||
win.webContents.executeJavaScript(`window.setPluginInfo(${opts})`).then(() => {
|
win.webContents.executeJavaScript(`window.setPluginInfo(${opts})`).then(() => {
|
||||||
win.show()
|
win.show()
|
||||||
});
|
})
|
||||||
|
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
win = undefined;
|
win = undefined
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
let getWindow = () => win;
|
let getWindow = () => win
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
getWindow: getWindow,
|
getWindow: getWindow,
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import path from "path";
|
import path from "path"
|
||||||
import fs from 'fs';
|
import fs from 'fs'
|
||||||
import {getlocalDataFile} from "./utils";
|
import { getlocalDataFile } from "./utils"
|
||||||
import os from 'os';
|
import os from 'os'
|
||||||
|
|
||||||
const configPath = path.join(getlocalDataFile(), './rubick-config.json');
|
const configPath = path.join(getlocalDataFile(), './rubick-config.json')
|
||||||
|
|
||||||
let defaultConfig = {
|
let defaultConfig = {
|
||||||
Darwin: {
|
Darwin: {
|
||||||
@ -55,30 +55,55 @@ let defaultConfig = {
|
|||||||
mouseDownTime: 500
|
mouseDownTime: 500
|
||||||
},
|
},
|
||||||
global: []
|
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 = {
|
global.opConfig = {
|
||||||
config: null,
|
config: null,
|
||||||
get() {
|
get() {
|
||||||
const platform = os.type();
|
const platform = os.type()
|
||||||
try {
|
try {
|
||||||
if (!opConfig.config) {
|
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) {
|
if (!opConfig.version || opConfig.version < defaultConfig[platform].version) {
|
||||||
opConfig.config = defaultConfig[platform];
|
opConfig.config = defaultConfig[platform]
|
||||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config));
|
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
|
||||||
}
|
}
|
||||||
return opConfig.config;
|
return opConfig.config
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
opConfig.config = defaultConfig[platform]
|
opConfig.config = defaultConfig[platform]
|
||||||
return opConfig.config;
|
return opConfig.config
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set(key, value) {
|
set(key, value) {
|
||||||
opConfig.config[key] = value;
|
opConfig.config[key] = value
|
||||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config));
|
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
import { app, globalShortcut } from 'electron'
|
import { app, globalShortcut } from 'electron'
|
||||||
import '../renderer/store'
|
import '../renderer/store'
|
||||||
import init from './common/common';
|
import init from './common/common'
|
||||||
import {autoUpdate} from './common/autoUpdate';
|
import { autoUpdate } from './common/autoUpdate'
|
||||||
import createTray from './tray';
|
import createTray from './tray'
|
||||||
import {commonConst} from './common/utils';
|
import { commonConst } from './common/utils'
|
||||||
import pkg from '../../package.json';
|
import pkg from '../../package.json'
|
||||||
|
|
||||||
const {main} = require("./browsers")();
|
const { main } = require("./browsers")()
|
||||||
|
|
||||||
if (commonConst.production()) {
|
if (commonConst.production()) {
|
||||||
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
|
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
|
||||||
}
|
}
|
||||||
// to fix https://github.com/electron/electron/issues/18397
|
// to fix https://github.com/electron/electron/issues/18397
|
||||||
app.allowRendererProcessReuse = false;
|
app.allowRendererProcessReuse = false
|
||||||
|
|
||||||
class initApp {
|
class initApp {
|
||||||
launchApp() {
|
launchApp() {
|
||||||
@ -28,28 +28,28 @@ class initApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createWindow() {
|
createWindow() {
|
||||||
main.init();
|
main.init()
|
||||||
init(main.getWindow());
|
init(main.getWindow())
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeReady() {
|
beforeReady() {
|
||||||
// 系统托盘
|
// 系统托盘
|
||||||
if (commonConst.macOS()) {
|
if (commonConst.macOS()) {
|
||||||
if (commonConst.production() && !app.isInApplicationsFolder()) {
|
if (commonConst.production() && !app.isInApplicationsFolder()) {
|
||||||
app.moveToApplicationsFolder();
|
app.moveToApplicationsFolder()
|
||||||
} else {
|
} else {
|
||||||
app.dock.hide();
|
app.dock.hide()
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
app.disableHardwareAcceleration();
|
app.disableHardwareAcceleration()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onReady() {
|
onReady() {
|
||||||
const readyFunction = () => {
|
const readyFunction = () => {
|
||||||
this.createWindow();
|
this.createWindow()
|
||||||
createTray(main.getWindow());
|
createTray(main.getWindow())
|
||||||
autoUpdate();
|
autoUpdate()
|
||||||
}
|
}
|
||||||
if (!app.isReady()) {
|
if (!app.isReady()) {
|
||||||
app.on('ready', readyFunction)
|
app.on('ready', readyFunction)
|
||||||
@ -61,25 +61,25 @@ class initApp {
|
|||||||
onRunning() {
|
onRunning() {
|
||||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||||
// 当运行第二个实例时,将会聚焦到myWindow这个窗口
|
// 当运行第二个实例时,将会聚焦到myWindow这个窗口
|
||||||
const win = main.getWindow();
|
const win = main.getWindow()
|
||||||
if (win) {
|
if (win) {
|
||||||
if (win.isMinimized()) {
|
if (win.isMinimized()) {
|
||||||
win.restore();
|
win.restore()
|
||||||
}
|
}
|
||||||
win.focus();
|
win.focus()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (!main.getWindow()) {
|
if (!main.getWindow()) {
|
||||||
this.createWindow();
|
this.createWindow()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
if (commonConst.windows()) {
|
if (commonConst.windows()) {
|
||||||
app.setAppUserModelId(pkg.build.appId);
|
app.setAppUserModelId(pkg.build.appId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onQuit () {
|
onQuit() {
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
@ -106,4 +106,4 @@ class initApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(new initApp()).launchApp();
|
(new initApp()).launchApp()
|
Loading…
x
Reference in New Issue
Block a user