Skip to content

Commit

Permalink
修复提权
Browse files Browse the repository at this point in the history
  • Loading branch information
wudizhanche1000 committed Dec 5, 2016
1 parent bcc1450 commit 78adf92
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
'use strict';

// 处理提权
function handleElevate() {
// for debug
if (process.argv[1] == '.') {
process.argv[1] = process.argv[2];
process.argv[2] = process.argv[3];
}

if (process.argv[1] == '-e') {
if (process.platform == 'darwin') {
app.dock.hide();
}
let elevate = JSON.parse(new Buffer(process.argv[2], 'base64').toString());
require('net').connect(elevate['ipc'], function () {
process.send = (message, sendHandle, options, callback) => this.write(JSON.stringify(message) + require('os').EOL, callback);
this.on('end', () => process.emit('disconnect'));
require('readline').createInterface({input: this}).on('line', (line) => process.emit('message', JSON.parse(line)));
process.argv = elevate['arguments'][1];
require("./" + elevate['arguments'][0]);
});
return true;
}
}
if (handleElevate()) {
return;
}

const {ipcMain, app, shell, BrowserWindow} = require('electron');
const {autoUpdater} = require("electron-auto-updater");
const isDev = require('electron-is-dev');
Expand All @@ -19,7 +46,7 @@ const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
}
mainWindow.focus()
}
})
});
if (shouldQuit) {
app.quit()
}
Expand Down Expand Up @@ -70,37 +97,6 @@ autoUpdater.on('update-downloaded', (event) => {
})
});

// 处理提权
function handleElevate() {

// for debug
if (process.argv[1] == '.') {
process.argv[1] = process.argv[2];
process.argv[2] = process.argv[3];
}

if (process.argv[1] == '-e') {
if (process.platform == 'darwin') {
app.dock.hide();
}
let elevate = JSON.parse(new Buffer(process.argv[2], 'base64'));
let socket = require('net').connect(elevate['ipc'], function () {
process.send = (message, sendHandle, options, callback) => this.write(JSON.stringify(message) + require('os').EOL, callback);
this.on('end', () => process.emit('disconnect'));
require('readline').createInterface({input: this}).on('line', (line) => process.emit('message', JSON.parse(line)));
process.argv = elevate['arguments'][1];
require("./" + elevate['arguments'][0]);
});
// socket.on("error", (error)=> {
// console.log(error);
// });
return true;
}
}
if (handleElevate()) {
return;
}

// Aria2c
function createAria2c() {
let aria2c_path;
Expand Down

0 comments on commit 78adf92

Please sign in to comment.