未验证 提交 a489a8f1 编写于 作者: 木偶 提交者: GitHub

Merge pull request #34 from SOVLOOKUP/cross-platform

Cross platform Linux 跨平台适配
{
"0 debug pnpm:scope": {
"selected": 1
}
}
\ No newline at end of file
......@@ -50,6 +50,7 @@
## 使用问题
1. 依赖于 `robotjs` dev 环境运行请在 `install` 后执行 `npm run rebuild`
2. windows 版本目前有了一个最基础的可用版,代码在 [feat-win](https://github.com/clouDr-f2e/rubick/tree/feat-win) 分支。完整版正在开发中,敬请期待
3. linux 开发分支 cross-platform 的 iohook 开发模式下可能需要手动下载并放入node_modules, 将在未来修复
## 目前支持能力
......
......@@ -10,7 +10,8 @@
"build": "node .electron-vue/build.js && electron-builder",
"dev": "node .electron-vue/dev-runner.js",
"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": {
"asar": true,
......@@ -99,6 +100,7 @@
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"babel-runtime": "^6.26.0",
"cfonts": "^2.1.2",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^4.5.1",
......@@ -106,7 +108,7 @@
"css-loader": "^0.28.11",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^11.0.2",
"electron": "^12.0.15",
"electron-builder": "22.10.5",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
......@@ -137,15 +139,16 @@
"iohook": {
"targets": [
"node-83",
"electron-85"
"electron-87"
],
"platforms": [
"darwin",
"win32"
"win32",
"linux"
],
"arches": [
"x64",
"ia32"
]
}
}
}
\ No newline at end of file
此差异已折叠。
......@@ -3,4 +3,4 @@ module.exports = () => ({
separator: require("./separate")(),
superPanel: require("./superPanel")(),
main: require("./main")(),
});
})
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,
};
};
}
}
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,
};
};
}
}
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,
};
};
}
}
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))
}
}
import { app, globalShortcut } from 'electron'
import '../renderer/store'
import init from './common/common';
import {autoUpdate} from './common/autoUpdate';
import createTray from './tray';
import {commonConst} from './common/utils';
import pkg from '../../package.json';
import init from './common/common'
import { autoUpdate } from './common/autoUpdate'
import createTray from './tray'
import { commonConst } from './common/utils'
import pkg from '../../package.json'
const {main} = require("./browsers")();
const { main } = require("./browsers")()
if (commonConst.production()) {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}
// to fix https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = false;
app.allowRendererProcessReuse = false
class initApp {
launchApp() {
......@@ -28,28 +28,28 @@ class initApp {
}
createWindow() {
main.init();
init(main.getWindow());
main.init()
init(main.getWindow())
}
beforeReady() {
// 系统托盘
if (commonConst.macOS()) {
if (commonConst.production() && !app.isInApplicationsFolder()) {
app.moveToApplicationsFolder();
app.moveToApplicationsFolder()
} else {
app.dock.hide();
app.dock.hide()
}
}else {
app.disableHardwareAcceleration();
} else {
app.disableHardwareAcceleration()
}
}
onReady() {
const readyFunction = () => {
this.createWindow();
createTray(main.getWindow());
autoUpdate();
this.createWindow()
createTray(main.getWindow())
autoUpdate()
}
if (!app.isReady()) {
app.on('ready', readyFunction)
......@@ -61,25 +61,25 @@ class initApp {
onRunning() {
app.on('second-instance', (event, commandLine, workingDirectory) => {
// 当运行第二个实例时,将会聚焦到myWindow这个窗口
const win = main.getWindow();
const win = main.getWindow()
if (win) {
if (win.isMinimized()) {
win.restore();
win.restore()
}
win.focus();
win.focus()
}
});
})
app.on('activate', () => {
if (!main.getWindow()) {
this.createWindow();
this.createWindow()
}
});
})
if (commonConst.windows()) {
app.setAppUserModelId(pkg.build.appId);
app.setAppUserModelId(pkg.build.appId)
}
}
onQuit () {
onQuit() {
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
......@@ -106,4 +106,4 @@ class initApp {
}
}
(new initApp()).launchApp();
(new initApp()).launchApp()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册