Commit 14834cc8 authored by 神楽坂玲奈's avatar 神楽坂玲奈

strict null checks

parent 327e6687
......@@ -51,7 +51,7 @@ export class App {
network: any;
tags: string[];
version: string;
local: AppLocal;
local: AppLocal | null;
status: AppStatus;
isInstalled(): boolean {
......
......@@ -12,6 +12,10 @@ import {AppLocal} from "./app-local";
const Aria2 = require('aria2');
const sudo = require('electron-sudo');
interface Connection {
connection: WebSocket, address: string | null
}
@Injectable()
export class AppsService {
......@@ -24,7 +28,7 @@ export class AppsService {
loadApps() {
return this.http.get('./apps.json')
.toPromise()
.then((response)=> {
.then((response) => {
let data = response.json();
this.apps = this.loadAppsList(data);
return this.apps;
......@@ -51,7 +55,7 @@ export class AppsService {
}
// 去除无关语言
['name', 'description'].forEach((key)=> {
['name', 'description'].forEach((key) => {
let value = app[key][locale];
if (!value) {
value = app[key]["en-US"];
......@@ -60,7 +64,7 @@ export class AppsService {
});
// 去除平台无关的内容
['actions', 'dependencies', 'references', 'download', 'version'].forEach((key)=> {
['actions', 'dependencies', 'references', 'download', 'version'].forEach((key) => {
if (app[key]) {
if (app[key][platform]) {
app[key] = app[key][platform];
......@@ -75,8 +79,8 @@ export class AppsService {
}
// 设置App关系
for (let id of Array.from(apps.keys())) {
let temp = apps.get(id)["actions"];
for (let [id] of apps) {
let temp = (<App>apps.get(id))["actions"];
let map = new Map<string,any>();
for (let action of Object.keys(temp)) {
let openId = temp[action]["open"];
......@@ -85,15 +89,15 @@ export class AppsService {
}
map.set(action, temp[action]);
}
apps.get(id).actions = map;
(<App>apps.get(id)).actions = map;
['dependencies', 'references', 'parent'].forEach((key)=> {
let app = apps.get(id);
['dependencies', 'references', 'parent'].forEach((key) => {
let app = <App>apps.get(id);
let value = app[key];
if (value) {
if (Array.isArray(value)) {
let map = new Map<string,App>();
value.forEach((appId, index, array)=> {
value.forEach((appId, index, array) => {
map.set(appId, apps.get(appId));
});
app[key] = map;
......@@ -107,8 +111,8 @@ export class AppsService {
};
findChildren(app: App): App[] {
let children = [];
for (let child of this.apps.values()) {
let children: App[] = [];
for (let [id,child] of this.apps) {
if (child.parent === app) {
children.push(child);
}
......@@ -118,9 +122,9 @@ export class AppsService {
runApp(app: App) {
let children = this.findChildren(app);
let cwd = app.local.path;
let action = app.actions.get('main');
let args = [];
let cwd = (<AppLocal>app.local).path;
let action: any = app.actions.get('main');
let args: string[] = [];
let env = {};
for (let child of children) {
action = child.actions.get('main');
......@@ -154,17 +158,17 @@ export class AppsService {
}
browse(app: App) {
remote.shell.showItemInFolder(app.local.path);
remote.shell.showItemInFolder((<AppLocal>app.local).path);
}
connections = new Map<App, {connection: WebSocket, address: string}>();
connections = new Map<App, Connection>();
maotama;
async network(app: App, server) {
if (!this.maotama) {
this.maotama = new Promise((resolve, reject)=> {
this.maotama = new Promise((resolve, reject) => {
let child = sudo.fork('maotama', [], {stdio: ['inherit', 'inherit', 'inherit', 'ipc']});
child.once('message', ()=>resolve(child));
child.once('message', () => resolve(child));
child.once('error', reject);
child.once('exit', reject);
})
......@@ -177,24 +181,24 @@ export class AppsService {
return
}
let connection = this.connections.get(app);
let connection: Connection | undefined = this.connections.get(app);
if (connection) {
connection.connection.close();
}
connection = {connection: new WebSocket(server.url), address: null};
let id;
this.connections.set(app, connection);
connection.connection.onmessage = (event)=> {
connection.connection.onmessage = (event) => {
console.log(event.data);
let [action, args] = event.data.split(' ', 2);
let [address, port] = args.split(':');
switch (action) {
case 'LISTEN':
connection.address = args;
(<Connection>connection).address = args;
this.ref.tick();
break;
case 'CONNECT':
id = setInterval(()=> {
id = setInterval(() => {
child.send({
action: 'connect',
arguments: [app.network.port, port, address]
......@@ -207,14 +211,14 @@ export class AppsService {
break;
}
};
connection.connection.onclose = (event: CloseEvent)=> {
connection.connection.onclose = (event: CloseEvent) => {
if (id) {
clearInterval(id);
}
// 如果还是在界面上显示的那个连接
if (this.connections.get(app) == connection) {
this.connections.delete(app);
if (event.code != 1000 && !connection.address) {
if (event.code != 1000 && !(<Connection>connection).address) {
alert(`出错了 ${event.code}`);
}
}
......
......@@ -21,7 +21,7 @@ export class DownloadService {
open = this.aria2.open();
constructor(private ngZone: NgZone, private http: Http) {
this.aria2.onDownloadComplete = (result)=> {
this.aria2.onDownloadComplete = (result) => {
let app = this.gidAppMap.get(result.gid);
if (app) {
this.appGidMap.delete(app);
......@@ -38,22 +38,23 @@ export class DownloadService {
}
getComplete(app: App): Promise<App> {
if (this.appGidMap.has(app)) {
return new Promise((resolve, reject)=> {
this.eventEmitter.once(app.id, (event)=> {
resolve(app);
})
});
if (!this.appGidMap.has(app)) {
throw('nyaa');
}
return new Promise((resolve, reject) => {
this.eventEmitter.once(app.id, (event) => {
resolve(app);
})
});
}
getProgress(app: App): Observable<any> {
let gid = this.appGidMap.get(app);
return Observable.create((observer)=> {
return Observable.create((observer) => {
let interval;
this.ngZone.runOutsideAngular(()=> {
interval = setInterval(()=> {
this.aria2.tellStatus(gid).then((status: any)=> {
this.ngZone.runOutsideAngular(() => {
interval = setInterval(() => {
this.aria2.tellStatus(gid).then((status: any) => {
if (status.status === 'complete') {
observer.complete();
} else if (status.status === "active") {
......@@ -64,14 +65,14 @@ export class DownloadService {
});
}, 1000);
});
return ()=> {
return () => {
clearInterval(interval);
}
});
}
async addUris(apps: App[], path: string): Promise<App[]> {
let tasks = [];
let tasks: App[] = [];
for (let app of apps) {
let task = await this.addUri(app, path);
tasks.push(task);
......@@ -84,16 +85,16 @@ export class DownloadService {
async addMetalink(metalink: string, library: string) {
let meta4 = btoa(metalink);
let gid = ( await this.aria2.addMetalink(meta4, {dir: library}))[0];
return Observable.create((observer)=> {
return Observable.create((observer) => {
this.map.set(gid, observer);
let interval;
this.ngZone.runOutsideAngular(()=> {
interval = setInterval(async()=> {
this.ngZone.runOutsideAngular(() => {
interval = setInterval(async() => {
let status = await this.aria2.tellStatus(gid);
this.map.get(gid).next(status);
}, 1000)
});
return ()=> {
return () => {
clearInterval(interval);
}
});
......
......@@ -36,29 +36,29 @@ export class InstallService {
createDirectory(dir: string) {
return new Promise((resolve, reject)=> {
return new Promise((resolve, reject) => {
mkdirp(dir, resolve);
})
}
getComplete(app: App): Promise<App> {
return new Promise((resolve, reject)=> {
this.eventEmitter.once(app.id, (complete)=> {
return new Promise((resolve, reject) => {
this.eventEmitter.once(app.id, (complete) => {
resolve();
});
});
}
extract(file: string, destPath: string) {
return new Promise((resolve, reject)=> {
return new Promise((resolve, reject) => {
let tarProcess = child_process.spawn(this.tarPath, ['xvf', file, '-C', destPath]);
let rl = readline.createInterface({
input: <ReadableStream>tarProcess.stderr,
});
rl.on('line', (input)=> {
rl.on('line', (input) => {
console.log(input);
});
tarProcess.on('exit', (code)=> {
tarProcess.on('exit', (code) => {
if (code === 0) {
resolve();
} else {
......@@ -72,26 +72,26 @@ export class InstallService {
let action = app.actions.get('install');
if (action) {
let env = Object.assign({}, action.env);
let command = [];
let command: string[] = [];
command.push(path.join(appPath, action.execute));
command.push(...action.args);
let open = action.open;
if (open) {
let openAction = open.actions.get("main");
let openAction: any = open.actions.get("main");
env = Object.assign(env, openAction.env);
command.unshift(...openAction.args);
command.unshift(path.join(open.local.path, openAction.execute));
command.unshift(path.join((<AppLocal>open.local).path, openAction.execute));
}
return new Promise((resolve, reject)=> {
let child = child_process.spawn(command.shift(), command, {
return new Promise((resolve, reject) => {
let child = child_process.spawn(<string>command.shift(), command, {
env: env,
stdio: 'inherit',
shell: true,
});
child.on('error', (error)=> {
child.on('error', (error) => {
console.log(error);
});
child.on('exit', (code)=> {
child.on('exit', (code) => {
if (code === 0) {
resolve();
} else {
......@@ -109,11 +109,11 @@ export class InstallService {
}
async backupFiles(app: App, files: Iterable<string>) {
let backupPath = path.join(app.local.path, "backup");
let backupPath = path.join((<AppLocal>app.local).path, "backup");
await this.createDirectory(backupPath);
for (let file of files) {
await new Promise((resolve, reject)=> {
let oldPath = path.join(app.local.path, file);
await new Promise((resolve, reject) => {
let oldPath = path.join((<AppLocal>app.local).path, file);
let newPath = path.join(backupPath, file);
fs.rename(oldPath, newPath, resolve);
});
......@@ -122,7 +122,7 @@ export class InstallService {
async getChecksumFile(app: App): Promise<Map<string,string> > {
let checksumMap: Map<string,string> = await this.http.get(this.checksumUri + app.id)
.map((response)=> {
.map((response) => {
let map = new Map<string,string>();
for (let line of response.text().split('\n')) {
if (line !== "") {
......@@ -138,23 +138,23 @@ export class InstallService {
async doInstall() {
for (let app of this.installQueue.keys()) {
let depInstalled = app.findDependencies()
.every((dependency)=>dependency.isInstalled());
.every((dependency) => dependency.isInstalled());
if (depInstalled && !this.installingQueue.has(app)) {
this.installingQueue.add(app);
let options = this.installQueue.get(app);
let options = <InstallConfig>this.installQueue.get(app);
let checksumMap = await this.getChecksumFile(app);
let packagePath = path.join(options.installLibrary, 'downloading', `${app.id}.tar.xz`);
let destPath: string;
if (app.parent) {
let differenceSet = new Set<string>();
let parentFilesMap = app.parent.local.files;
let parentFilesMap = (<AppLocal>app.parent.local).files;
for (let key of checksumMap.keys()) {
if (parentFilesMap.has(key)) {
differenceSet.add(key);
}
}
await this.backupFiles(app.parent, differenceSet);
destPath = app.parent.local.path;
destPath = (<AppLocal>app.parent.local).path;
} else {
destPath = path.join(options.installLibrary, app.id);
await this.createDirectory(destPath);
......@@ -187,15 +187,15 @@ export class InstallService {
}
deleteFile(file: string): Promise<string> {
return new Promise((resolve, reject)=> {
fs.lstat(file, (err, stats)=> {
return new Promise((resolve, reject) => {
fs.lstat(file, (err, stats) => {
if (err) return resolve(path);
if (stats.isDirectory()) {
fs.rmdir(file, (err)=> {
fs.rmdir(file, (err) => {
resolve(file);
});
} else {
fs.unlink(file, (err)=> {
fs.unlink(file, (err) => {
resolve(file);
});
}
......@@ -212,17 +212,17 @@ export class InstallService {
}
}
}
let files = Array.from(app.local.files.keys()).sort().reverse();
let files = Array.from((<AppLocal>app.local).files.keys()).sort().reverse();
for (let file of files) {
let oldFile = file;
if (!path.isAbsolute(file)) {
oldFile = path.join(app.local.path, file);
oldFile = path.join((<AppLocal>app.local).path, file);
}
if (restore) {
await this.deleteFile(oldFile);
if (app.parent) {
let backFile = path.join(app.local.path, "backup", file);
await new Promise((resolve, reject)=> {
let backFile = path.join((<AppLocal>app.local).path, "backup", file);
await new Promise((resolve, reject) => {
fs.rename(backFile, oldFile, resolve);
});
}
......@@ -230,9 +230,9 @@ export class InstallService {
}
if (app.parent) {
await this.deleteFile(path.join(app.local.path, "backup"));
await this.deleteFile(path.join((<AppLocal>app.local).path, "backup"));
} else {
await this.deleteFile(app.local.path);
await this.deleteFile((<AppLocal>app.local).path);
}
app.local = null;
localStorage.removeItem(app.id);
......
......@@ -3,13 +3,14 @@
*/
import {Component, OnInit} from "@angular/core";
import {AppsService} from "./apps.service";
import {LoginService} from "./login.service";
import {LoginService, User} from "./login.service";
import {App, Category} from "./app";
import {DownloadService} from "./download.service";
import {InstallService} from "./install.service";
import {Http} from "@angular/http";
import * as path from 'path';
import {InstallConfig} from "./install-config";
import {AppLocal} from "./app-local";
@Component({
selector: 'lobby',
......@@ -29,9 +30,9 @@ export class LobbyComponent implements OnInit {
ngOnInit() {
this.appsService.loadApps()
.then((apps)=> {
.then((apps) => {
this.apps = apps;
this.currentApp = this.apps.get("th06");
this.currentApp = <App>this.apps.get("th06");
this.updateApp();
})
......@@ -41,12 +42,12 @@ export class LobbyComponent implements OnInit {
let updateServer = "http://thief.mycard.moe/update/metalinks/";
let checksumServer = "http://thief.mycard.moe/checksums/";
for (let app of this.apps.values()) {
if (app.isInstalled() && app.version != app.local.version) {
if (app.isInstalled() && app.version != (<AppLocal>app.local).version) {
let checksumMap = await this.installService.getChecksumFile(app);
let filesMap = app.local.files;
let deleteList = [];
let addList = [];
let changeList = [];
let filesMap = (<AppLocal>app.local).files;
let deleteList: string[] = [];
let addList: string[] = [];
let changeList: string[] = [];
for (let [file,checksum] of filesMap) {
let t = checksumMap.get(file);
if (!t) {
......@@ -60,19 +61,19 @@ export class LobbyComponent implements OnInit {
changeList.push(file);
}
}
let metalink = await this.http.post(updateServer + app.id, changeList).map((response)=>response.text())
let metalink = await this.http.post(updateServer + app.id, changeList).map((response) => response.text())
.toPromise();
let meta = new DOMParser().parseFromString(metalink, "text/xml");
let filename = meta.getElementsByTagName('file')[0].getAttribute('name');
let dir = path.join(path.dirname(app.local.path), "downloading");
let dir = path.join(path.dirname((<AppLocal>app.local).path), "downloading");
let a = await this.downloadService.addMetalink(metalink, dir);
await new Promise((resolve, reject)=> {
a.subscribe((status)=> {
await new Promise((resolve, reject) => {
a.subscribe((status) => {
console.log(status);
}, (err)=> {
}, (err) => {
reject()
}, ()=> {
}, () => {
resolve();
});
});
......@@ -80,15 +81,15 @@ export class LobbyComponent implements OnInit {
for (let file of deleteList) {
await this.installService.deleteFile(file);
}
app.local.version=app.version;
app.local.files = checksumMap;
(<AppLocal>app.local).version = app.version;
(<AppLocal>app.local).files = checksumMap;
localStorage.setItem(app.id, JSON.stringify(app.local));
await this.installService.extract(path.join(dir, filename), app.local.path);
await this.installService.extract(path.join(dir, filename), (<AppLocal>app.local).path);
let children = this.appsService.findChildren(app);
for (let child of children) {
if (child.isInstalled()) {
await this.installService.uninstall(child, false);
this.installService.add(child, new InstallConfig(child, path.dirname((app.local.path))));
this.installService.add(child, new InstallConfig(child, path.dirname(((<AppLocal>app.local).path))));
await this.installService.getComplete(child);
console.log("282828")
}
......@@ -103,7 +104,7 @@ export class LobbyComponent implements OnInit {
}
get grouped_apps() {
let contains = ["game", "music", "book"].map((value)=>Category[value]);
let contains = ["game", "music", "book"].map((value) => Category[value]);
let result = {};
for (let app of this.apps.values()) {
if (contains.includes(app.category)) {
......
......@@ -4,7 +4,7 @@
import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
interface User {
export interface User {
admin: boolean;
avatar_url: string;
email: string;
......@@ -16,20 +16,27 @@ interface User {
@Injectable()
export class LoginService {
user: User = JSON.parse(localStorage.getItem('login'));
logging_out;
user: User;
logged_in = false;
logging_out = false;
constructor(private http: Http) {
let data = localStorage.getItem('login');
if (data) {
this.user = JSON.parse(data);
this.logged_in = true;
}
}
login(user) {
this.user = user;
this.logged_in = true;
localStorage.setItem('login', JSON.stringify(user));
}
logout() {
this.logging_out = true;
this.user = null;
this.logged_in = false;
localStorage.removeItem('login');
}
......
<nav class="navbar navbar-dark bg-inverse" [class.darwin]="platform == 'darwin'">
<a class="navbar-brand" href="#">MyCard</a>
<ul class="nav navbar-nav">
<li *ngIf="!loginService.user" class="nav-item active">
<li *ngIf="!loginService.logged_in" class="nav-item active">
<a class="nav-link" href="#">登录<span class="sr-only">(current)</span></a>
</li>
<!--
......@@ -9,15 +9,15 @@
<a (click)="changeFouce('store')" class="nav-link" href="#">商店</a>
</li>
-->
<li *ngIf="loginService.user" [ngClass]="{active: currentPage === 'lobby'}" class="nav-item">
<li *ngIf="loginService.logged_in" [ngClass]="{active: currentPage === 'lobby'}" class="nav-item">
<a (click)="currentPage='lobby'" class="nav-link" href="#">{{'library'| translate}}<span class="sr-only">(current)</span></a>
</li>
<li *ngIf="loginService.user" [ngClass]="{active: currentPage === 'community'}" class="nav-item">
<li *ngIf="loginService.logged_in" [ngClass]="{active: currentPage === 'community'}" class="nav-item">
<a (click)="currentPage='community'" class="nav-link" href="#">{{'community'| translate}}</a>
</li>
</ul>
<div class="navbar-right">
<div id="user" *ngIf="loginService.user">
<div id="user" *ngIf="loginService.logged_in">
<a href="#" class="profile"><img id="avatar" [src]="loginService.user.avatar_url" alt="image"></a>
<a href="#" class="profile item" id="username">{{loginService.user.username}}</a>
<a href="#" (click)="loginService.logout()" class="item">切换账号</a>
......@@ -30,7 +30,7 @@
</div>
</div>
</nav>
<login class="page" *ngIf="!loginService.user"></login>
<store class="page" *ngIf="loginService.user" [hidden]="currentPage != 'store'"></store>
<lobby class="page" *ngIf="loginService.user" [hidden]="currentPage != 'lobby'"></lobby>
<webview id="community" class="page" *ngIf="loginService.user" [hidden]="currentPage != 'community'" src="https://ygobbs.com"></webview>
\ No newline at end of file
<login class="page" *ngIf="!loginService.logged_in"></login>
<store class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'store'"></store>
<lobby class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'lobby'"></lobby>
<webview id="community" class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'community'" src="https://ygobbs.com"></webview>
\ No newline at end of file
......@@ -6,6 +6,10 @@ import {Injectable} from "@angular/core";
import {remote} from "electron";
import * as path from "path";
interface Library {
"default": boolean,path: string
}
@Injectable()
export class SettingsService {
......@@ -16,7 +20,7 @@ export class SettingsService {
path: path.join(remote.app.getPath("appData"), "library")
},
];
libraries: {"default": boolean,path: string}[];
libraries: Library[];
getLibraries() {
......@@ -33,11 +37,16 @@ export class SettingsService {
return this.libraries;
}
getDefaultLibrary() {
getDefaultLibrary(): Library {
if (!this.libraries) {
this.getLibraries()
}
return this.libraries.find((item)=>item.default === true);
let result = this.libraries.find((item) => item.default === true);
if (result) {
return result
} else {
throw('no default library found')
}
}
static SETTING_LOCALE = "locale";
......
......@@ -15,6 +15,7 @@ import {App} from "./app";
import {Http, Headers, URLSearchParams} from "@angular/http";
import "rxjs/Rx";
import {ISubscription} from "rxjs/Subscription";
import {AppLocal} from "./app-local";
declare var $;
......@@ -45,8 +46,8 @@ interface SystemConf {
}
interface Server {
id?: string
url?: string
id: string
url: string
address: string
port: number
}
......@@ -76,7 +77,7 @@ export class YGOProComponent implements OnInit {
decks: string[] = [];
current_deck: string;
system_conf = path.join(this.app.local.path, 'system.conf');
system_conf = path.join((<AppLocal>this.app.local).path, 'system.conf');
numfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']};
textfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']};
......@@ -115,10 +116,10 @@ export class YGOProComponent implements OnInit {
let modal = $('#game-list-modal');
modal.on('show.bs.modal', (event) => {
this.connections = this.servers.map((server)=> {
this.connections = this.servers.map((server) => {
let connection = new WebSocket(server.url);
connection.onclose = () => {
this.rooms = this.rooms.filter(room=>room.server != server)
this.rooms = this.rooms.filter(room => room.server != server)
};
connection.onmessage = (event) => {
let message = JSON.parse(event.data);
......@@ -131,10 +132,10 @@ export class YGOProComponent implements OnInit {
this.rooms.push(Object.assign({server: server}, this.default_options, message.data));
break;
case 'update':
Object.assign(this.rooms.find(room=>room.server == server && room.id == message.data.id), this.default_options, message.data);
Object.assign(this.rooms.find(room => room.server == server && room.id == message.data.id), this.default_options, message.data);
break;
case 'delete':
this.rooms.splice(this.rooms.findIndex(room=>room.server == server && room.id == message.data), 1);
this.rooms.splice(this.rooms.findIndex(room => room.server == server && room.id == message.data), 1);
}
this.ref.detectChanges()
};
......@@ -159,20 +160,20 @@ export class YGOProComponent implements OnInit {
};
get_decks(): Promise<string[]> {
return new Promise((resolve, reject)=> {
fs.readdir(path.join(this.app.local.path, 'deck'), (error, files)=> {
return new Promise((resolve, reject) => {
fs.readdir(path.join((<AppLocal>this.app.local).path, 'deck'), (error, files) => {
if (error) {
resolve([])
} else {
resolve(files.filter(file=>path.extname(file) == ".ydk").map(file=>path.basename(file, '.ydk')));
resolve(files.filter(file => path.extname(file) == ".ydk").map(file => path.basename(file, '.ydk')));
}
})
})
}
async get_font(files: string[]): Promise<string> {
async get_font(files: string[]): Promise<string | undefined> {
for (let file in files) {
let found = await new Promise((resolve)=>fs.access(file, fs.constants.R_OK, error=>resolve(!error)));
let found = await new Promise((resolve) => fs.access(file, fs.constants.R_OK, error => resolve(!error)));
if (found) {
return file;
}
......@@ -180,7 +181,7 @@ export class YGOProComponent implements OnInit {
}
async delete_deck(deck) {
await new Promise(resolve => fs.unlink(path.join(this.app.local.path, 'deck', deck + '.ydk'), resolve));
await new Promise(resolve => fs.unlink(path.join((<AppLocal>this.app.local).path, 'deck', deck + '.ydk'), resolve));
return this.refresh()
}
......@@ -201,7 +202,7 @@ export class YGOProComponent implements OnInit {
};
load_system_conf(): Promise<SystemConf> {
return new Promise((resolve, reject)=> {
return new Promise((resolve, reject) => {
fs.readFile(this.system_conf, {encoding: 'utf-8'}, (error, data) => {
if (error) return reject(error);
resolve(ini.parse(data));
......@@ -210,7 +211,7 @@ export class YGOProComponent implements OnInit {
};
save_system_conf(data: SystemConf) {
return new Promise((resolve, reject)=> {
return new Promise((resolve, reject) => {
fs.writeFile(this.system_conf, ini.stringify(data, <EncodeOptions>{whitespace: true}), (error) => {
if (error) return reject(error);
resolve(data);
......@@ -245,13 +246,13 @@ export class YGOProComponent implements OnInit {
start_game(args) {
let win = remote.getCurrentWindow();
win.minimize();
return new Promise((resolve, reject)=> {
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)=> {
return new Promise((resolve, reject) => {
let child = child_process.spawn(path.join((<AppLocal>this.app.local).path, (<any>this.app.actions.get('main')).execute), args, {cwd: (<AppLocal>this.app.local).path});
child.on('error', (error) => {
reject(error);
win.restore()
});
child.on('exit', (code, signal)=> {
child.on('exit', (code, signal) => {
// error 触发之后还可能会触发exit,但是Promise只承认首次状态转移,因此这里无需重复判断是否已经error过。
resolve();
win.restore()
......@@ -315,22 +316,22 @@ export class YGOProComponent implements OnInit {
this.matching = this.http.post('https://mycard.moe/ygopro/match', null, {
headers: headers,
search: search
}).map(response=>response.json())
.subscribe((data)=> {
}).map(response => response.json())
.subscribe((data) => {
this.join(data['password'], {
address: data['address'],
port: data['port']
});
}, (error)=> {
}, (error) => {
alert(`匹配失败\n${error}`)
}, ()=> {
}, () => {
this.matching = null;
this.matching_arena = null;
});
}
cancel_match() {
this.matching.unsubscribe();
(<ISubscription>this.matching).unsubscribe();
this.matching = null;
this.matching_arena = null;
}
......
......@@ -11,6 +11,8 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
"noImplicitAny": false,
"strictNullChecks": true,
"skipLibCheck": true
}
}
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