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

maotama

parent f343473e
......@@ -34,4 +34,10 @@ progress {
#news a {
display: block;
margin-bottom: 1rem;
}
#network {
display: inline-block;
vertical-align: middle;
width: 240px;
}
\ No newline at end of file
......@@ -20,7 +20,25 @@
<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 (click)="appsService.browse(appsService.currentApp)" type="button" class="btn btn-secondary">游览本地文件</button>-->
<button type="button" class="btn btn-secondary" (click)="appsService.network(appsService.currentApp)">联机</button>
<div id="network" *ngIf="appsService.currentApp.network && appsService.currentApp.network.protocol == 'maotama'">
<div class="input-group">
<input *ngIf="appsService.connections.get(appsService.currentApp)" [value]="appsService.connections.get(appsService.currentApp)" readonly type="text" class="form-control" aria-label="Text input with dropdown button">
<div class="input-group-btn btn-group">
<button *ngIf="!appsService.connections.get(appsService.currentApp)" (click)="appsService.network(appsService.currentApp, appsService.currentApp.network.servers[0])" type="button" class="btn btn-secondary" aria-haspopup="true" aria-expanded="false">
联机
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="height: 38px;">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-right">
<a *ngFor="let server of appsService.currentApp.network.servers"
(click)="appsService.network(appsService.currentApp, server)" class="dropdown-item" href="#">{{server.id}}</a>
</div>
</div>
</div>
</div>
</div>
<ygopro *ngIf="isInstalled && (appsService.currentApp.id == 'ygopro')"></ygopro>
......
......@@ -3,9 +3,30 @@ import {AppsService} from "./apps.service";
import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices";
declare var System;
declare var process;
declare var $;
const readline = System._nodeRequire('readline');
const os = System._nodeRequire('os');
const electron = System._nodeRequire('electron');
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
})
};
@Component({
selector: 'app-detail',
templateUrl: 'app/app-detail.component.html',
......@@ -162,5 +183,4 @@ export class AppDetailComponent implements OnInit {
}
}
......@@ -35,6 +35,7 @@ export class App {
locales: string[];
download: {[platform: string]: string}; // meta4 url
news: {title: string, url: string, image: string}[];
network: any;
tags: string[];
version: {[platform: string]: string};
local: AppLocal;
......@@ -53,6 +54,7 @@ export class App {
this.locales = app.locales;
this.download = app.download;
this.news = app.news;
this.network = app.network;
this.tags = app.tags;
this.version = app.version;
this.local = app.local;
......
import {Injectable} from "@angular/core";
import {Injectable, ApplicationRef} from "@angular/core";
import {Http} from "@angular/http";
import {App} from "./app";
import {InstallConfig} from "./install-config";
......@@ -46,7 +46,7 @@ export class AppsService {
this._currentApp = app;
}
constructor(private http: Http, private settingsService: SettingsService) {
constructor(private http: Http, private settingsService: SettingsService, private ref: ApplicationRef) {
this.loadApps(()=> {
if (this.data.size > 0) {
this.currentApp = this.data.get('ygopro');
......@@ -509,22 +509,39 @@ export class AppsService {
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);
});
connections = new Map<App, string>();
maotama;
network(app: App, server) {
if(!this.maotama){
this.maotama = sudo.fork('maotama')
}
this.maotama.then((child)=> {
let connection = new WebSocket(server.url);
let id;
connection.onmessage = (event)=> {
let message = <{action: string;arguments: any[]}>JSON.parse(event.data);
console.log(message);
switch (message.action) {
case 'listen':
this.connections.set(app, `${message.arguments[0]}:${message.arguments[1]}`);
this.ref.tick();
break;
case 'connect':
id = setInterval(()=> {
child.send({
action: 'connect',
arguments: [app.network.port, message.arguments[1], message.arguments[0]]
})
}, 200);
break;
case 'connected':
clearInterval(id);
break;
}
}
})
}
}
\ No newline at end of file
......@@ -51,6 +51,16 @@
}
}
},
"network": {
"protocol": "maotama",
"port": 10800,
"servers": [
{
"id": "tiramisu",
"url": "wss://tiramisu.mycard.moe:10800"
}
]
},
"version": {
"darwin": "1.06"
},
......
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