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

maotama

parent f343473e
...@@ -34,4 +34,10 @@ progress { ...@@ -34,4 +34,10 @@ progress {
#news a { #news a {
display: block; display: block;
margin-bottom: 1rem; margin-bottom: 1rem;
}
#network {
display: inline-block;
vertical-align: middle;
width: 240px;
} }
\ No newline at end of file
...@@ -20,7 +20,25 @@ ...@@ -20,7 +20,25 @@
<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" (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> </div>
<ygopro *ngIf="isInstalled && (appsService.currentApp.id == 'ygopro')"></ygopro> <ygopro *ngIf="isInstalled && (appsService.currentApp.id == 'ygopro')"></ygopro>
......
...@@ -3,9 +3,30 @@ import {AppsService} from "./apps.service"; ...@@ -3,9 +3,30 @@ import {AppsService} from "./apps.service";
import {InstallConfig} from "./install-config"; import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
declare var System;
declare var process; declare var process;
declare var $; 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({ @Component({
selector: 'app-detail', selector: 'app-detail',
templateUrl: 'app/app-detail.component.html', templateUrl: 'app/app-detail.component.html',
...@@ -162,5 +183,4 @@ export class AppDetailComponent implements OnInit { ...@@ -162,5 +183,4 @@ export class AppDetailComponent implements OnInit {
} }
} }
...@@ -35,6 +35,7 @@ export class App { ...@@ -35,6 +35,7 @@ export class App {
locales: string[]; locales: string[];
download: {[platform: string]: string}; // meta4 url download: {[platform: string]: string}; // meta4 url
news: {title: string, url: string, image: string}[]; news: {title: string, url: string, image: string}[];
network: any;
tags: string[]; tags: string[];
version: {[platform: string]: string}; version: {[platform: string]: string};
local: AppLocal; local: AppLocal;
...@@ -53,6 +54,7 @@ export class App { ...@@ -53,6 +54,7 @@ export class App {
this.locales = app.locales; this.locales = app.locales;
this.download = app.download; this.download = app.download;
this.news = app.news; this.news = app.news;
this.network = app.network;
this.tags = app.tags; this.tags = app.tags;
this.version = app.version; this.version = app.version;
this.local = app.local; this.local = app.local;
......
import {Injectable} from "@angular/core"; import {Injectable, ApplicationRef} from "@angular/core";
import {Http} from "@angular/http"; import {Http} from "@angular/http";
import {App} from "./app"; import {App} from "./app";
import {InstallConfig} from "./install-config"; import {InstallConfig} from "./install-config";
...@@ -46,7 +46,7 @@ export class AppsService { ...@@ -46,7 +46,7 @@ export class AppsService {
this._currentApp = app; this._currentApp = app;
} }
constructor(private http: Http, private settingsService: SettingsService) { constructor(private http: Http, private settingsService: SettingsService, private ref: ApplicationRef) {
this.loadApps(()=> { this.loadApps(()=> {
if (this.data.size > 0) { if (this.data.size > 0) {
this.currentApp = this.data.get('ygopro'); this.currentApp = this.data.get('ygopro');
...@@ -509,22 +509,39 @@ export class AppsService { ...@@ -509,22 +509,39 @@ export class AppsService {
electron.remote.shell.showItemInFolder(app.local.path); electron.remote.shell.showItemInFolder(app.local.path);
} }
/*child.on('exit', reject); connections = new Map<App, string>();
let rl = readline.createInterface({ maotama;
input: child.stdout,
output: child.stdin network(app: App, server) {
}); if(!this.maotama){
rl.on('line', (input) => { this.maotama = sudo.fork('maotama')
resolve(); }
console.log(`Received: ${input}`);
});*/ this.maotama.then((child)=> {
network(app: App) { let connection = new WebSocket(server.url);
sudo.fork('maotama').then((child)=> { let id;
//new WebSocket() connection.onmessage = (event)=> {
setInterval(()=> { let message = <{action: string;arguments: any[]}>JSON.parse(event.data);
child.send({action: 'connect', arguments: [10800, 10900, '112.124.105.11']}) console.log(message);
}, 200); 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 @@ ...@@ -51,6 +51,16 @@
} }
} }
}, },
"network": {
"protocol": "maotama",
"port": 10800,
"servers": [
{
"id": "tiramisu",
"url": "wss://tiramisu.mycard.moe:10800"
}
]
},
"version": { "version": {
"darwin": "1.06" "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