Commit 708bd61c authored by 神楽坂玲奈's avatar 神楽坂玲奈

electron-sudo

parent a5d7d2ee
'use strict'; 'use strict';
// 处理提权 if (require('electron-sudo/main').handleElevate()) return;
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') {
require('electron').app.dock.hide();
}
let elevate = JSON.parse(Buffer.from(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, Menu, Tray, Notification } = require('electron'); const { ipcMain, app, shell, BrowserWindow, Menu, Tray, Notification } = require('electron');
const { autoUpdater } = require('electron-updater'); const { autoUpdater } = require('electron-updater');
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
"electron": "^14.0.0", "electron": "^14.0.0",
"electron-builder": "^22.11.7", "electron-builder": "^22.11.7",
"electron-builder-notarize": "^1.2.0", "electron-builder-notarize": "^1.2.0",
"electron-sudo": "github:mycard/electron-sudo#mycard",
"exports-loader": "^3.0.0", "exports-loader": "^3.0.0",
"imports-loader": "^3.0.0", "imports-loader": "^3.0.0",
"ini": "^2.0.0", "ini": "^2.0.0",
...@@ -7484,6 +7485,16 @@ ...@@ -7484,6 +7485,16 @@
"node": ">= 10.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/electron-sudo": {
"version": "4.0.12",
"resolved": "git+ssh://git@github.com/mycard/electron-sudo.git#2ef775ba6e16eefe492cb3fdccdae3be0a034d9a",
"dev": true,
"license": "MIT",
"peerDependencies": {
"@electron/remote": "latest",
"electron": "latest"
}
},
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.3.833", "version": "1.3.833",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.833.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.833.tgz",
...@@ -25254,6 +25265,12 @@ ...@@ -25254,6 +25265,12 @@
} }
} }
}, },
"electron-sudo": {
"version": "git+ssh://git@github.com/mycard/electron-sudo.git#2ef775ba6e16eefe492cb3fdccdae3be0a034d9a",
"dev": true,
"from": "electron-sudo@mycard/electron-sudo#mycard",
"requires": {}
},
"electron-to-chromium": { "electron-to-chromium": {
"version": "1.3.833", "version": "1.3.833",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.833.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.833.tgz",
...@@ -3,7 +3,7 @@ import child_process from 'child_process'; ...@@ -3,7 +3,7 @@ import child_process from 'child_process';
import { ChildProcess } from 'child_process'; import { ChildProcess } from 'child_process';
import crypto from 'crypto'; import crypto from 'crypto';
import * as remote from '@electron/remote'; import * as remote from '@electron/remote';
import * as sudo from 'child_process'; import * as sudo from 'electron-sudo';
import fs from 'fs'; import fs from 'fs';
import glob from 'glob'; import glob from 'glob';
import path from 'path'; import path from 'path';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment