Commit e770e834 authored by 神楽坂玲奈's avatar 神楽坂玲奈

network

parent c1251714
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<button (click)="startApp(appsService.currentApp)" type="button" class="btn btn-primary">运行</button> <button (click)="startApp(appsService.currentApp)" type="button" class="btn btn-primary">运行</button>
<button type="button" data-toggle="modal" data-target="#settings-modal" class="btn btn-secondary">设置</button> <button type="button" data-toggle="modal" data-target="#settings-modal" class="btn btn-secondary">设置</button>
<!--<button (click)="appsService.browse(appsService.currentApp)" type="button" class="btn btn-secondary">游览本地文件</button>--> <!--<button (click)="appsService.browse(appsService.currentApp)" type="button" class="btn btn-secondary">游览本地文件</button>-->
<button type="button" class="btn btn-secondary">联机</button> <button type="button" class="btn btn-secondary" (click)="appsService.network(appsService.currentApp)">联机</button>
</div> </div>
<ygopro *ngIf="isInstalled && (appsService.currentApp.id == 'ygopro')"></ygopro> <ygopro *ngIf="isInstalled && (appsService.currentApp.id == 'ygopro')"></ygopro>
......
...@@ -7,13 +7,32 @@ import {InstallConfig} from "./install-config"; ...@@ -7,13 +7,32 @@ import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
declare var process; declare var process;
const os = window['System']._nodeRequire('os'); declare var System;
const fs = window['System']._nodeRequire('fs'); const os = System._nodeRequire('os');
const path = window['System']._nodeRequire('path'); const fs = System._nodeRequire('fs');
const mkdirp = window['System']._nodeRequire('mkdirp'); const path = System._nodeRequire('path');
const electron = window['System']._nodeRequire('electron'); const readline = System._nodeRequire('readline');
const Aria2 = window['System']._nodeRequire('aria2'); const mkdirp = System._nodeRequire('mkdirp');
const execFile = window['System']._nodeRequire('child_process').execFile; const electron = System._nodeRequire('electron');
const Aria2 = System._nodeRequire('aria2');
const execFile = System._nodeRequire('child_process').execFile;
const sudo = new (System._nodeRequire('electron-sudo').default)({name: 'MyCard'});
sudo.fork = function (modulePath, args, options) {
return sudo.spawn(electron.remote.app.getPath('exe'), ['-e', modulePath]).then((child)=> {
readline.createInterface({input: child.stdout}).on('line', (line) => {
child.emit('message', JSON.parse(line));
});
child.send = (message, sendHandle, options, callback)=> {
child.stdin.write(JSON.stringify(message) + os.EOL);
if (callback) {
callback()
}
};
return child
})
};
//const sudo = System._nodeRequire('sudo-prompt');
@Injectable() @Injectable()
export class AppsService { export class AppsService {
...@@ -476,4 +495,23 @@ export class AppsService { ...@@ -476,4 +495,23 @@ export class AppsService {
browse(app: App) { browse(app: App) {
electron.remote.shell.showItemInFolder(app.local.path); electron.remote.shell.showItemInFolder(app.local.path);
} }
}
/*child.on('exit', reject);
let rl = readline.createInterface({
input: child.stdout,
output: child.stdin
});
rl.on('line', (input) => {
resolve();
console.log(`Received: ${input}`);
});*/
network(app: App) {
sudo.fork('maotama').then((child)=> {
//new WebSocket()
setInterval(()=> {
child.send({action: 'connect', arguments: [10800, 10900, '112.124.105.11']})
}, 200);
});
}
}
\ No newline at end of file
...@@ -1377,7 +1377,17 @@ ...@@ -1377,7 +1377,17 @@
"win32": "http://thief.mycard.moe/metalinks/th123.meta4", "win32": "http://thief.mycard.moe/metalinks/th123.meta4",
"darwin": "http://thief.mycard.moe/metalinks/th123.meta4" "darwin": "http://thief.mycard.moe/metalinks/th123.meta4"
}, },
"news": [] "news": [],
"network": {
"protocol": "maotama",
"port": 10800,
"servers": [
{
"id": "tiramisu",
"url": "wss://tiramisu.mycard.moe:10800"
}
]
}
}, },
{ {
"id": "th123-lang-zh-CN", "id": "th123-lang-zh-CN",
......
...@@ -10,7 +10,7 @@ const child_process = require('child_process'); ...@@ -10,7 +10,7 @@ const child_process = require('child_process');
const path = require('path'); const path = require('path');
// this should be placed at top of main.js to handle setup events quickly // this should be placed at top of main.js to handle setup events quickly
if (handleSquirrelEvent()) { if (handleSquirrelEvent() || handleElevate()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else // squirrel event handled and app will exit in 1000ms, so don't do anything else
return; return;
} }
...@@ -78,6 +78,14 @@ function handleSquirrelEvent() { ...@@ -78,6 +78,14 @@ function handleSquirrelEvent() {
} }
}; };
function handleElevate() {
if (process.argv[1] == '-e') {
app.dock.hide();
require("./" + process.argv[2]);
return true;
}
}
function createAria2c() { function createAria2c() {
let aria2c_path; let aria2c_path;
switch (process.platform) { switch (process.platform) {
......
const os = require('os');
const readline = require('readline');
process.send = (message, sendHandle, options, callback)=> {
process.stdout.write(JSON.stringify(message) + os.EOL);
if (callback) {
callback()
}
};
process.stdin.on('end', ()=> {
process.emit('disconnect')
});
readline.createInterface({input: process.stdin}).on('line', (line) => {
process.emit('message', JSON.parse(line))
});
const raw = require("raw-socket");
let socket = raw.createSocket({protocol: raw.Protocol.UDP});
let connect = (local_port, remote_port, remote_address)=> {
let buffer = new Buffer(9);
buffer.writeUInt16BE(local_port, 0);
buffer.writeUInt16BE(remote_port, 2);
buffer.writeUInt16BE(buffer.length, 4);
socket.send(buffer, 0, buffer.length, remote_address, (error, bytes) => {
if (error) {
throw(error);
}
})
};
let handler = {connect: connect};
process.on('message', (message)=> {
handler[message.action](...message.arguments);
});
process.on('disconnect', process.exit);
\ No newline at end of file
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