Skip to content

feat: 升级 electron,支持 苹果芯片 #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ossutil*
ossutil_output
app.asar
pvl
out

#tool
.vscode/
2 changes: 1 addition & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ angular
label: v.label
});
});
var lang = localStorage.getItem('lang') || langList[0].lang;
var lang = localStorage.getItem('lang') || (langList[0] && langList[0].lang);

$rootScope.langSettings = {
langList: langList,
Expand Down
24 changes: 11 additions & 13 deletions app/components/services/cipher.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
angular.module('web').factory('Cipher', function() {
var crypto = require('crypto');
var ALGORITHM = 'aes192';
var KEY = 'x82m#*lx8vv';
var ALGORITHM = 'aes-256-cbc';
// var KEY = 'x82m#*lx8vv';
var KEY = Buffer.from('x82m#*lx8vvy93n#*my9wwz04o#*nz0x');
var IV = Buffer.from('*my9wwz04o#*nz0x');

return {
cipher: cipher,
decipher: decipher
};

function cipher(buf, key, algorithm) {
if (!(buf instanceof Buffer)) {
buf = new Buffer(buf);
}

function cipher(buf, key, algorithm, iv) {
var encrypted = '';
var cip = crypto.createCipher(algorithm || ALGORITHM, key || KEY);
var cip = crypto.createCipheriv(algorithm || ALGORITHM, key || KEY, iv || IV);

encrypted += cip.update(buf, 'utf8', 'hex');
encrypted += cip['final']('hex');
encrypted += cip.final('hex');

return encrypted;
}

function decipher(encrypted, key, algorithm) {
function decipher(encrypted, key, algorithm, iv) {
var decrypted = '';
var decipher = crypto.createDecipher(algorithm || ALGORITHM, key || KEY);
var decipher = crypto.createDecipheriv(algorithm || ALGORITHM, key || KEY, iv || IV);

decrypted += decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher['final']('utf8');
decrypted += decipher.update(Buffer.from(encrypted, 'hex'), null, 'utf8');
decrypted += decipher.final('utf8');

return decrypted;
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/services/dialog.s.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular
.factory('Dialog', [
'$uibModal',
function($modal) {
var dialog = require('electron').remote.dialog;
var dialog = require('electron').dialog;

return {
alert: alert,
Expand Down
44 changes: 44 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');

module.exports = {
packagerConfig: {
asar: true,
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {},
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {},
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};
54 changes: 28 additions & 26 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var electron = require("electron");
const server = require('./server.js');
// Module to control application life.

// use self signed certificate for Apsara Stack
Expand All @@ -23,18 +24,19 @@ log.transports.console.level = false;
///*****************************************
//静态服务
var PORTS = [7123, 7124, 7125, 7126];

for (var port of PORTS) {
try {
//var subp = require('child_process').fork('./server.js',[port]);
require("./server.js").listen(port);
console.log("listening on port " + port);
break;
} catch (e) {
console.log(e);
}
try {
// var subp = require('child_process').fork('./server.js',[port]);
server.listen(PORTS[0]);
console.log("listening on port " + PORTS[0]);
// break;
} catch (e) {
console.log(e);
}

// for (var port of PORTS) {

// }

app.commandLine.appendSwitch("ignore-certificate-errors");
///*****************************************

Expand All @@ -57,7 +59,7 @@ if (process.platform == "darwin") {
);
}

function createWindow() {
function createWindow () {
var opt = {
width: 1221,
height: 700,
Expand All @@ -67,6 +69,9 @@ function createWindow() {
icon: custom.logo_ico || path.join(__dirname, "icons", "icon.ico"),

webPreferences: {
nodeIntegration: true, // 允许在渲染器进程中使用 Node.js API
contextIsolation: false, // 需要配合 nodeIntegration 使用
enableRemoteModule: true, // 允许使用 remote 模块
plugins: true,
},
};
Expand Down Expand Up @@ -112,7 +117,7 @@ ipcMain.on("asynchronous", (event, data) => {
switch (data.key) {
case "getStaticServerPort":
//在main process里向web page发出message
event.sender.send("asynchronous-reply", { key: data.key, port: port });
event.sender.send("asynchronous-reply", { key: data.key, port: 7123 });
break;
case "openDevTools":
process.env["DEBUG"] = 'ali-oss';
Expand Down Expand Up @@ -145,7 +150,7 @@ ipcMain.on("asynchronous", (event, data) => {
}
});

function moveFile(from, to, fn) {
function moveFile (from, to, fn) {
if (process.platform != "win32") {
fs.rename(from, to, fn);
return;
Expand Down Expand Up @@ -179,23 +184,20 @@ function moveFile(from, to, fn) {
}

//singleton
var shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
});
app.requestSingleInstanceLock({});
// console.log('shouldQuit', shouldQuit);
// var shouldQuit = false;

if (shouldQuit) {
app.quit();
process.exit(0);
}
// if (shouldQuit) {
// app.quit();
// process.exit(0);
// }

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", createWindow);
// app.on("ready", createWindow);
app.whenReady().then(() => createWindow());

// Quit when all windows are closed.
app.on("window-all-closed", () => {
Expand Down Expand Up @@ -228,7 +230,7 @@ app.on(
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

function getMenuTemplate() {
function getMenuTemplate () {
var name = app.getName();
return [
{
Expand Down
28 changes: 20 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@
"watch": "./node_modules/.bin/gulp watch --custom=$custom",
"build": "./node_modules/.bin/gulp build --custom=$custom",
"rcedit": "cp tools/rcedit-x64.exe node_modules/rcedit/bin/rcedit.exe",
"lint": "eslint --fix app"
"lint": "eslint --fix app",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"engines": {
"node": "8.2.1"
"node": ">=8.2.1"
},
"devDependencies": {
"@alicloud/eslint-config": "^1.2.23",
"@electron-forge/cli": "^7.4.0",
"@electron-forge/maker-deb": "^7.4.0",
"@electron-forge/maker-rpm": "^7.4.0",
"@electron-forge/maker-squirrel": "^7.4.0",
"@electron-forge/maker-zip": "^7.4.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
"@electron-forge/plugin-fuses": "^7.4.0",
"@electron/fuses": "^1.8.0",
"angular": "1.5.8",
"angular-bootstrap-contextmenu": "^1.1.0",
"angular-sanitize": "1.5.8",
Expand All @@ -36,8 +47,8 @@
"commander": "~2.9.0",
"cross-env": "^3.1.4",
"del": "^4.1.1",
"electron": "1.8.4",
"electron-packager": "7.1.0",
"electron": "latest",
"electron-packager": "latest",
"eslint": "^7.1.0",
"font-awesome": "^4.7.0",
"gulp": "~3.5.5",
Expand Down Expand Up @@ -67,11 +78,12 @@
"ali-oss": "^6.13.2",
"aliyun-sdk": "^1.12.3",
"clipboard": "^1.7.1",
"electron-log": "1.3.0",
"electron-log": "latest",
"electron-squirrel-startup": "^1.0.1",
"emoji-regex": "^9.0.0",
"koa": "^2.3.0",
"koa-convert": "^1.2.0",
"koa-static-server": "^1.2.1",
"koa": "latest",
"koa-convert": "latest",
"koa-static-server": "latest",
"mime": "^1.3.6",
"nodemailer": "4.0.1",
"nodemailer-smtp-transport": "2.7.4",
Expand Down