Commit 0a5ddc82 authored by 神楽坂玲奈's avatar 神楽坂玲奈

optimize import

parent ee74a9a4
<h1>{{appsService.currentApp.name}}</h1> <h1>{{appsService.currentApp.name}}</h1>
<div *ngIf="!isInstalled"> <div *ngIf="!isInstalled">
<div *ngIf="!appsService.getDownloadInfo(appsService.currentApp)"> <div *ngIf="!appsService.getDownloadInfo(appsService.currentApp)">
<button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal" <button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal" data-target="#install-modal">安装
data-target="#install-modal">安装
</button> </button>
<button type="button" class="btn btn-secondary">导入</button> <button type="button" class="btn btn-secondary">导入</button>
<!--<button type="button" class="btn btn-secondary">正版代购</button>--> <!--<button type="button" class="btn btn-secondary">正版代购</button>-->
...@@ -10,10 +9,7 @@ ...@@ -10,10 +9,7 @@
<div *ngIf="appsService.getDownloadInfo(appsService.currentApp)"> <div *ngIf="appsService.getDownloadInfo(appsService.currentApp)">
<div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'install'">正在安装...</div> <div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'install'">正在安装...</div>
<div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'wait'">等待安装...</div> <div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'wait'">等待安装...</div>
<progress *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'active'" <progress *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(appsService.currentApp).progress}}" max="100"></progress>
class="progress progress-striped progress-animated"
value="{{appsService.getDownloadInfo(appsService.currentApp).progress}}" max="100">
</progress>
</div> </div>
</div> </div>
<div *ngIf="isInstalled && (appsService.currentApp.id != 'ygopro')"> <div *ngIf="isInstalled && (appsService.currentApp.id != 'ygopro')">
...@@ -23,7 +19,7 @@ ...@@ -23,7 +19,7 @@
<div id="network" *ngIf="appsService.currentApp.network && appsService.currentApp.network.protocol == 'maotama'"> <div id="network" *ngIf="appsService.currentApp.network && appsService.currentApp.network.protocol == 'maotama'">
<div class="input-group"> <div class="input-group">
<input *ngIf="appsService.connections.get(appsService.currentApp)" [value]="appsService.connections.get(appsService.currentApp).address || 'Loading...'" readonly type="text" class="form-control" aria-label="Text input with dropdown button"> <input *ngIf="appsService.connections.get(appsService.currentApp)" [value]="appsService.connections.get(appsService.currentApp).address || 'Loading...'" readonly type="text" class="form-control" aria-label="Text input with dropdown button" title="address">
<div class="input-group-btn"> <div class="input-group-btn">
<button *ngIf="!appsService.connections.get(appsService.currentApp)" (click)="appsService.network(appsService.currentApp, appsService.currentApp.network.servers[0])" type="button" class="btn btn-secondary"> <button *ngIf="!appsService.connections.get(appsService.currentApp)" (click)="appsService.network(appsService.currentApp, appsService.currentApp.network.servers[0])" type="button" class="btn btn-secondary">
联机 联机
...@@ -31,14 +27,12 @@ ...@@ -31,14 +27,12 @@
<button *ngIf="appsService.connections.get(appsService.currentApp)" (click)="copy(appsService.connections.get(appsService.currentApp).address)" [disabled]="!appsService.connections.get(appsService.currentApp).address" type="button" class="btn btn-secondary"> <button *ngIf="appsService.connections.get(appsService.currentApp)" (click)="copy(appsService.connections.get(appsService.currentApp).address)" [disabled]="!appsService.connections.get(appsService.currentApp).address" type="button" class="btn btn-secondary">
复制 复制
</button> </button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="height: 38px;">
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="height: 38px;">
<span class="sr-only">Toggle Dropdown</span> <span class="sr-only">Toggle Dropdown</span>
</button> </button>
<div class="dropdown-menu" [class.dropdown-menu-right]="appsService.connections.get(appsService.currentApp)"> <div class="dropdown-menu" [class.dropdown-menu-right]="appsService.connections.get(appsService.currentApp)">
<h6 class="dropdown-header">选择服务器</h6> <h6 class="dropdown-header">选择服务器</h6>
<a *ngFor="let server of appsService.currentApp.network.servers" <a *ngFor="let server of appsService.currentApp.network.servers" (click)="appsService.network(appsService.currentApp, server)" class="dropdown-item" href="#">{{server.id}}</a>
(click)="appsService.network(appsService.currentApp, server)" class="dropdown-item" href="#">{{server.id}}</a>
</div> </div>
</div> </div>
</div> </div>
...@@ -88,13 +82,9 @@ ...@@ -88,13 +82,9 @@
<button type="button" class="btn btn-danger btn-sm">卸载</button> <button type="button" class="btn btn-danger btn-sm">卸载</button>
</td> </td>
<td *ngIf="!checkInstall(mod.id)"> <td *ngIf="!checkInstall(mod.id)">
<button *ngIf="!appsService.getDownloadInfo(mod.id)" (click)="install(mod.id)" type="button" <button *ngIf="!appsService.getDownloadInfo(mod.id)" (click)="install(mod.id)" type="button" class="btn btn-primary btn-sm">安装
class="btn btn-primary btn-sm">安装
</button> </button>
<progress <progress *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress>
*ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'"
class="progress progress-striped progress-animated"
value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress>
<div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'wait'"> <div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'wait'">
等待安装... 等待安装...
</div> </div>
...@@ -117,26 +107,19 @@ ...@@ -117,26 +107,19 @@
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" <button type="button" class="close" data-dismiss="modal" aria-label="Close">
aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<h4 class="modal-title">{{'settings'|translate}}</h4> <h4 class="modal-title">{{'settings'|translate}}</h4>
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#general"> <a class="nav-link active" data-toggle="tab" href="#general"> {{'general'|translate}} </a>
{{'general'|translate}}
</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#updates"> <a class="nav-link" data-toggle="tab" href="#updates"> {{'updates'|translate}} </a>
{{'updates'|translate}}
</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#local-files"> <a class="nav-link" data-toggle="tab" href="#local-files"> {{'local files'|translate}} </a>
{{'local files'|translate}}
</a>
</li> </li>
</ul> </ul>
</div> </div>
...@@ -164,10 +147,8 @@ ...@@ -164,10 +147,8 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div><!-- Modal -->
<!-- Modal --> <div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" *ngIf="installConfig">
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true" *ngIf="installConfig">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<form id="install-form" class="modal-content" (ngSubmit)="install()" #theForm="ngForm"> <form id="install-form" class="modal-content" (ngSubmit)="install()" #theForm="ngForm">
<div class="modal-header"> <div class="modal-header">
...@@ -181,7 +162,7 @@ ...@@ -181,7 +162,7 @@
<!-- 安装位置选择只在 windows 下存在, 为了方便调试暂时不加ngif --> <!-- 安装位置选择只在 windows 下存在, 为了方便调试暂时不加ngif -->
<h4>{{'install_path'|translate}}</h4> <h4>{{'install_path'|translate}}</h4>
<div class="form-group"> <div class="form-group">
<select class="form-control" name="installPath" [(ngModel)]="installConfig.installPath"> <select class="form-control" name="installPath" [(ngModel)]="installConfig.installPath" title="path">
<option *ngFor="let library of settingsService.getLibraries()" value="{{library['path']}}"> <option *ngFor="let library of settingsService.getLibraries()" value="{{library['path']}}">
{{ library['path']}} {{ library['path']}}
</option> </option>
...@@ -190,22 +171,18 @@ ...@@ -190,22 +171,18 @@
<h4>{{'shortcut'|translate}}</h4> <h4>{{'shortcut'|translate}}</h4>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="application" [(ngModel)]="installConfig.createShortcut"> <input type="checkbox" name="application" [(ngModel)]="installConfig.createShortcut"> {{'create_shortcut'|translate}}
{{'create_shortcut'|translate}}
</label> </label>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="desktop" [(ngModel)]="installConfig.createDesktopShortcut"> <input type="checkbox" name="desktop" [(ngModel)]="installConfig.createDesktopShortcut"> {{'create_desktop_shortcut'|translate}}
{{'create_desktop_shortcut'|translate}}
</label> </label>
</div> </div>
<h4>{{'additions'|translate}}</h4> <h4>{{'additions'|translate}}</h4>
<div *ngFor="let reference of installConfig.references"> <div *ngFor="let reference of installConfig.references">
<label> <label>
<input type="checkbox" [(ngModel)]="reference.id" name="references" <input type="checkbox" [(ngModel)]="reference.id" name="references" value="{{reference.id}}"> {{reference.name}}
value="{{reference.id}}">
{{reference.name}}
</label> </label>
</div> </div>
</div> </div>
......
...@@ -4,31 +4,12 @@ import {InstallConfig} from "./install-config"; ...@@ -4,31 +4,12 @@ import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
import {App} from "./app"; import {App} from "./app";
import {DownloadService} from "./download.service"; import {DownloadService} from "./download.service";
import {clipboard, remote} from "electron";
import * as path from "path";
import * as child_process from "child_process";
declare var System;
declare var $; declare var $;
import * as readline from 'readline';
import * as os from 'os';
import {clipboard, remote} from 'electron';
const sudo = new (System._nodeRequire('electron-sudo').default)({name: 'MyCard'});
sudo.fork = function (modulePath, args, options) {
return sudo.spawn(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',
...@@ -37,12 +18,6 @@ sudo.fork = function (modulePath, args, options) { ...@@ -37,12 +18,6 @@ sudo.fork = function (modulePath, args, options) {
}) })
export class AppDetailComponent implements OnInit { export class AppDetailComponent implements OnInit {
platform = process.platform; platform = process.platform;
fs = window['System']._nodeRequire('fs');
electron = window['System']._nodeRequire('electron');
spawn = window['System']._nodeRequire('child_process').spawn;
path = window['System']._nodeRequire('path');
installConfig: InstallConfig; installConfig: InstallConfig;
constructor(private appsService: AppsService, private settingsService: SettingsService, constructor(private appsService: AppsService, private settingsService: SettingsService,
...@@ -146,7 +121,7 @@ export class AppDetailComponent implements OnInit { ...@@ -146,7 +121,7 @@ export class AppDetailComponent implements OnInit {
} }
startApp(app: App) { startApp(app: App) {
let execute = this.path.join(app.local.path, app.actions.get("main").execute); let execute = path.join(app.local.path, app.actions.get("main").execute);
let args = app.actions.get("main").args; let args = app.actions.get("main").args;
let env = app.actions.get("main").env; let env = app.actions.get("main").env;
let opt = { let opt = {
...@@ -158,7 +133,7 @@ export class AppDetailComponent implements OnInit { ...@@ -158,7 +133,7 @@ export class AppDetailComponent implements OnInit {
let openApp = app.actions.get("main").open; let openApp = app.actions.get("main").open;
if (openApp) { if (openApp) {
if (this.isInstalled) { if (this.isInstalled) {
open = this.path.join(openApp.local.path, openApp.actions.get("main").execute); open = path.join(openApp.local.path, openApp.actions.get("main").execute);
args.push(execute); args.push(execute);
} else { } else {
console.error('open app not found'); console.error('open app not found');
...@@ -168,7 +143,7 @@ export class AppDetailComponent implements OnInit { ...@@ -168,7 +143,7 @@ export class AppDetailComponent implements OnInit {
open = execute; open = execute;
} }
let handle = this.spawn(open, args, opt); let handle = child_process.spawn(open, args, opt);
handle.stdout.on('data', (data) => { handle.stdout.on('data', (data) => {
console.log(`stdout: ${data}`); console.log(`stdout: ${data}`);
......
...@@ -3,20 +3,19 @@ import {Http} from "@angular/http"; ...@@ -3,20 +3,19 @@ import {Http} from "@angular/http";
import {App} from "./app"; import {App} from "./app";
import {InstallConfig} from "./install-config"; import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
import * as os from "os";
declare var process; import * as fs from "fs";
declare var System; import * as path from "path";
const os = System._nodeRequire('os'); import * as readline from "readline";
const fs = System._nodeRequire('fs'); import * as mkdirp from "mkdirp";
const path = System._nodeRequire('path'); import * as child_process from "child_process";
const readline = System._nodeRequire('readline'); import {remote} from "electron";
const mkdirp = System._nodeRequire('mkdirp');
const electron = System._nodeRequire('electron'); const Aria2 = require('aria2');
const Aria2 = System._nodeRequire('aria2'); const Sudo = require('electron-sudo').default;
const execFile = System._nodeRequire('child_process').execFile;
const sudo = new (System._nodeRequire('electron-sudo').default)({name: 'MyCard'}); Sudo.prototype.fork = function (modulePath, args, options) {
sudo.fork = function (modulePath, args, options) { return this.spawn(remote.app.getPath('exe'), ['-e', modulePath].concat(args), options).then((child)=> {
return sudo.spawn(electron.remote.app.getPath('exe'), ['-e', modulePath]).then((child)=> {
readline.createInterface({input: child.stdout}).on('line', (line) => { readline.createInterface({input: child.stdout}).on('line', (line) => {
child.emit('message', JSON.parse(line)); child.emit('message', JSON.parse(line));
}); });
...@@ -30,8 +29,6 @@ sudo.fork = function (modulePath, args, options) { ...@@ -30,8 +29,6 @@ sudo.fork = function (modulePath, args, options) {
}) })
}; };
//const sudo = System._nodeRequire('sudo-prompt');
@Injectable() @Injectable()
export class AppsService { export class AppsService {
...@@ -101,7 +98,7 @@ export class AppsService { ...@@ -101,7 +98,7 @@ export class AppsService {
xzFile: res.files[0].path, xzFile: res.files[0].path,
installDir: this.installConfig.installPath installDir: this.installConfig.installPath
}; };
let promise = new Promise((resolve, reject)=> { new Promise((resolve)=> {
let refs = this.searchApp(this.downloadsInfo[index].id).references; let refs = this.searchApp(this.downloadsInfo[index].id).references;
console.log(refs); console.log(refs);
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}] //[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
...@@ -127,7 +124,7 @@ export class AppsService { ...@@ -127,7 +124,7 @@ export class AppsService {
// } // }
// }); // });
// } // }
console.log("wait obj:", waitObj); //console.log("wait obj:", waitObj);
if (waitObj) { if (waitObj) {
this.waitInstallQueue.push(waitObj); this.waitInstallQueue.push(waitObj);
...@@ -148,16 +145,16 @@ export class AppsService { ...@@ -148,16 +145,16 @@ export class AppsService {
} }
}); });
}; };
this._aria2.onmessage = (m)=> { //this._aria2.onmessage = (m)=> {
//console.log('IN:', m); //console.log('IN:', m);
//console.log('download infoi:', this.downloadsInfo); //console.log('download infoi:', this.downloadsInfo);
} //}
} }
if (!this.aria2IsOpen) { if (!this.aria2IsOpen) {
this._aria2.open().then(()=> { this._aria2.open().then(()=> {
console.log('aria2 websocket open') console.log('aria2 websocket open');
this.aria2IsOpen = true; this.aria2IsOpen = true;
}); });
} }
...@@ -166,9 +163,9 @@ export class AppsService { ...@@ -166,9 +163,9 @@ export class AppsService {
} }
_download_dir; //_download_dir;
get download_dir() { get download_dir() {
const dir = path.join(electron.remote.app.getAppPath(), 'cache'); const dir = path.join(remote.app.getAppPath(), 'cache');
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
console.log('cache not exists'); console.log('cache not exists');
...@@ -189,7 +186,7 @@ export class AppsService { ...@@ -189,7 +186,7 @@ export class AppsService {
.map(response => { .map(response => {
let apps = response.json(); let apps = response.json();
let localAppData = JSON.parse(localStorage.getItem("localAppData")); let localAppData = JSON.parse(localStorage.getItem("localAppData"));
apps = apps.map((app)=> { apps = apps.map((app: any)=> {
if (localAppData) { if (localAppData) {
localAppData.map((v)=> { localAppData.map((v)=> {
if (v.id === app.id) { if (v.id === app.id) {
...@@ -252,7 +249,7 @@ export class AppsService { ...@@ -252,7 +249,7 @@ export class AppsService {
// 设置App关系 // 设置App关系
for (let id of Array.from(apps.keys())) { for (let id of Array.from(apps.keys())) {
let temp = apps.get(id)["actions"] let temp = apps.get(id)["actions"];
let map = new Map<string,any>(); let map = new Map<string,any>();
for (let action of Object.keys(temp)) { for (let action of Object.keys(temp)) {
let openId = temp[action]["open"]; let openId = temp[action]["open"];
...@@ -312,7 +309,7 @@ export class AppsService { ...@@ -312,7 +309,7 @@ export class AppsService {
} }
uninstall(id: string) { uninstall(id: string) {
let current = this; //let current = this;
if (this.checkInstall(id)) { if (this.checkInstall(id)) {
let files: string[] = this.searchApp(id).local.files.sort().reverse(); let files: string[] = this.searchApp(id).local.files.sort().reverse();
// 删除本目录 // 删除本目录
...@@ -362,7 +359,7 @@ export class AppsService { ...@@ -362,7 +359,7 @@ export class AppsService {
getInstallConfig(app: App): InstallConfig { getInstallConfig(app: App): InstallConfig {
let id = app.id; //let id = app.id;
this.installConfig = new InstallConfig(app); this.installConfig = new InstallConfig(app);
let platform = process.platform; let platform = process.platform;
let references: InstallConfig[] = []; let references: InstallConfig[] = [];
...@@ -440,7 +437,7 @@ export class AppsService { ...@@ -440,7 +437,7 @@ export class AppsService {
}); });
} }
let tar = execFile(tarPath, ['xvf', xzFile, '-C', installDir], opt, (err, stdout, stderr)=> { let tar = child_process.execFile(tarPath, ['xvf', xzFile, '-C', installDir], opt, (err, stdout, stderr)=> {
if (err) { if (err) {
throw err; throw err;
} }
...@@ -494,11 +491,7 @@ export class AppsService { ...@@ -494,11 +491,7 @@ export class AppsService {
} }
}); });
this.waitInstallQueue = this.waitInstallQueue.filter((waitObj)=> { this.waitInstallQueue = this.waitInstallQueue.filter((waitObj)=> {
if (waitObj) { return waitObj
return true;
} else {
return false;
}
}); });
console.log(tmp); console.log(tmp);
...@@ -511,15 +504,8 @@ export class AppsService { ...@@ -511,15 +504,8 @@ export class AppsService {
} }
isEmptyObject(e) {
let t;
for (t in e)
return !1;
return !0
}
browse(app: App) { browse(app: App) {
electron.remote.shell.showItemInFolder(app.local.path); remote.shell.showItemInFolder(app.local.path);
} }
connections = new Map<App, {connection: WebSocket, address: string}>(); connections = new Map<App, {connection: WebSocket, address: string}>();
...@@ -527,7 +513,7 @@ export class AppsService { ...@@ -527,7 +513,7 @@ export class AppsService {
network(app: App, server) { network(app: App, server) {
if (!this.maotama) { if (!this.maotama) {
this.maotama = sudo.fork('maotama') this.maotama = new Sudo({name: 'MyCard'}).fork('maotama')
} }
this.maotama.then((child)=> { this.maotama.then((child)=> {
let connection = this.connections.get(app); let connection = this.connections.get(app);
......
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
*/ */
import {Component} from "@angular/core"; import {Component} from "@angular/core";
import {LoginService} from "./login.service"; import {LoginService} from "./login.service";
declare var System; import * as crypto from "crypto";
const crypto = System._nodeRequire('crypto'); import * as querystring from "querystring";
const querystring = System._nodeRequire('querystring'); import * as url from "url";
const url = System._nodeRequire('url');
@Component({ @Component({
selector: 'login', selector: 'login',
......
import {Component, Renderer} from "@angular/core"; import {Component, Renderer} from "@angular/core";
import {TranslateService} from "ng2-translate"; import {TranslateService} from "ng2-translate";
import {LoginService} from "./login.service"; import {remote} from "electron";
const electron = System._nodeRequire('electron');
declare var process;
declare var System;
@Component({ @Component({
selector: 'mycard', selector: 'mycard',
...@@ -18,7 +14,7 @@ export class MyCardComponent { ...@@ -18,7 +14,7 @@ export class MyCardComponent {
platform = process.platform; platform = process.platform;
constructor(private renderer: Renderer, private translate: TranslateService, private loginService: LoginService) { constructor(private renderer: Renderer, private translate: TranslateService) {
renderer.listenGlobal('window', 'message', (event) => { renderer.listenGlobal('window', 'message', (event) => {
console.log(event); console.log(event);
// Do something with 'event' // Do something with 'event'
...@@ -28,12 +24,12 @@ export class MyCardComponent { ...@@ -28,12 +24,12 @@ export class MyCardComponent {
translate.setDefaultLang('en-US'); translate.setDefaultLang('en-US');
// the lang to use, if the lang isn't available, it will use the current loader to get them // the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use(electron.remote.app.getLocale()); translate.use(remote.app.getLocale());
} }
refresh() { refresh() {
electron.remote.getCurrentWindow().reload() remote.getCurrentWindow().reload()
} }
} }
...@@ -3,19 +3,16 @@ ...@@ -3,19 +3,16 @@
*/ */
import {Component, OnInit, ChangeDetectorRef} from "@angular/core"; import {Component, OnInit, ChangeDetectorRef} from "@angular/core";
import {AppsService} from "./apps.service"; import {AppsService} from "./apps.service";
import * as fs from "fs";
import * as path from "path";
import * as crypto from "crypto";
import * as child_process from "child_process";
import {remote} from "electron";
import * as ini from "ini";
import {EncodeOptions} from "ini";
declare var process;
declare var System;
declare var $; declare var $;
const fs = System._nodeRequire('fs');
const path = System._nodeRequire('path');
const crypto = System._nodeRequire('crypto');
const child_process = System._nodeRequire('child_process');
const ini = System._nodeRequire('ini');
const electron = System._nodeRequire('electron');
@Component({ @Component({
selector: 'ygopro', selector: 'ygopro',
templateUrl: 'app/ygopro.component.html', templateUrl: 'app/ygopro.component.html',
...@@ -170,7 +167,7 @@ export class YGOProComponent implements OnInit { ...@@ -170,7 +167,7 @@ export class YGOProComponent implements OnInit {
save_system_conf = (data) => { save_system_conf = (data) => {
return new Promise((resolve, reject)=> { return new Promise((resolve, reject)=> {
fs.writeFile(this.system_conf, ini.stringify(data, {whitespace: true}), (error) => { fs.writeFile(this.system_conf, ini.stringify(data, <EncodeOptions>{whitespace: true}), (error) => {
if (error) return reject(error); if (error) return reject(error);
resolve(data); resolve(data);
}); });
...@@ -186,7 +183,7 @@ export class YGOProComponent implements OnInit { ...@@ -186,7 +183,7 @@ export class YGOProComponent implements OnInit {
data['lastport'] = server.port; data['lastport'] = server.port;
data['roompass'] = name; data['roompass'] = name;
data['nickname'] = this.user.username; data['nickname'] = this.user.username;
console.log(data) console.log(data);
return data return data
}) })
.then(this.save_system_conf) .then(this.save_system_conf)
...@@ -200,10 +197,10 @@ export class YGOProComponent implements OnInit { ...@@ -200,10 +197,10 @@ export class YGOProComponent implements OnInit {
} }
start_game = (args) => { start_game = (args) => {
let win = electron.remote.getCurrentWindow(); let win = remote.getCurrentWindow();
win.minimize(); win.minimize();
return new Promise((resolve, reject)=> { return new Promise((resolve, reject)=> {
let child = child_process.spawn(path.join(this.app.local.path, this.app.actions[process.platform]['main']['execute']), args, {cwd: this.app.local.path}); let child = child_process.spawn(path.join(this.app.local.path, this.app.actions.get('main').execute), args, {cwd: this.app.local.path});
child.on('error', (error)=> { child.on('error', (error)=> {
reject(error); reject(error);
win.restore() win.restore()
...@@ -235,7 +232,7 @@ export class YGOProComponent implements OnInit { ...@@ -235,7 +232,7 @@ export class YGOProComponent implements OnInit {
} }
let password = options_buffer.toString('base64') + options.title.replace(/\s/, String.fromCharCode(0xFEFF)); let password = options_buffer.toString('base64') + options.title.replace(/\s/, String.fromCharCode(0xFEFF));
let room_id = crypto.createHash('md5').update(password + this.user.username).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_') let room_id = crypto.createHash('md5').update(password + this.user.username).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_');
this.join(password, this.servers[0]); this.join(password, this.servers[0]);
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* System configuration for Angular 2 samples * System configuration for Angular 2 samples
* Adjust as necessary for your application needs. * Adjust as necessary for your application needs.
*/ */
(function (global) {
// map tells the System loader where to look for things // map tells the System loader where to look for things
var map = { var map = {
'app': 'app', // 'dist', 'app': 'app', // 'dist',
...@@ -11,8 +10,7 @@ ...@@ -11,8 +10,7 @@
'rxjs': 'node_modules/rxjs', 'rxjs': 'node_modules/rxjs',
'ng2-translate': 'node_modules/ng2-translate/bundles/index.js', 'ng2-translate': 'node_modules/ng2-translate/bundles/index.js',
"electron": "@node/electron", "electron": "@node/electron",
"readline": "@node/readline", "ini": "@node/ini",
"os":"@node/os"
}; };
// packages tells the System loader how to load when no filename and/or no extension // packages tells the System loader how to load when no filename and/or no extension
var packages = { var packages = {
...@@ -20,6 +18,12 @@ ...@@ -20,6 +18,12 @@
'rxjs': {defaultExtension: 'js'}, 'rxjs': {defaultExtension: 'js'},
'angular2-in-memory-web-api': {main: 'index.js', defaultExtension: 'js'} 'angular2-in-memory-web-api': {main: 'index.js', defaultExtension: 'js'}
}; };
let builtin_modules = ["buffer", "querystring", "events", "http", "cluster", "zlib", "os", "https", "punycode", "repl", "readline", "vm", "child_process", "url", "dns", "net", "dgram", "fs", "path", "string_decoder", "tls", "crypto", "stream", "util", "assert", "tty", "domain", "constants", "process", "v8", "timers", "console"];
for (let mod of builtin_modules) {
map[mod] = `@node/${mod}`;
}
var ngPackageNames = [ var ngPackageNames = [
'common', 'common',
'compiler', 'compiler',
...@@ -51,4 +55,3 @@ ...@@ -51,4 +55,3 @@
packages: packages packages: packages
}; };
System.config(config); System.config(config);
})(this);
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
"globalDependencies": { "globalDependencies": {
"core-js": "registry:dt/core-js", "core-js": "registry:dt/core-js",
"electron/github-electron": "registry:dt/electron/github-electron", "electron/github-electron": "registry:dt/electron/github-electron",
"ini": "registry:dt/ini",
"jasmine": "registry:dt/jasmine", "jasmine": "registry:dt/jasmine",
"node": "registry:dt/node" "node": "registry:dt/node"
},
"dependencies": {
"mkdirp": "registry:npm/mkdirp"
} }
} }
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