Commit c081fbf4 authored by nanahira's avatar nanahira

some little changes for Linux

parent 0e0a36de
/**
* Created by zh99998 on 16/9/2.
*/
import {
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
ViewChild
} from '@angular/core';
import { Headers, Http } from '@angular/http';
import {ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core';
import {Headers, Http} from '@angular/http';
import * as child_process from 'child_process';
import { clipboard, remote, shell } from 'electron';
import {clipboard, remote, shell} from 'electron';
import * as fs from 'fs-extra';
import * as ini from 'ini';
import { EncodeOptions } from 'ini';
import {EncodeOptions} from 'ini';
import * as $ from 'jquery';
import * as path from 'path';
import 'rxjs/Rx';
import { ISubscription } from 'rxjs/Subscription';
import { App } from './app';
import { AppsService } from './apps.service';
import { LoginService } from './login.service';
import { SettingsService } from './settings.sevices';
import {ISubscription} from 'rxjs/Subscription';
import {App} from './app';
import {AppsService} from './apps.service';
import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices';
import Timer = NodeJS.Timer;
import WillNavigateEvent = Electron.WillNavigateEvent;
......@@ -87,6 +77,7 @@ interface Options {
lflist?: number;
time_limit?: number;
}
export interface Points {
exp: number;
exp_rank: number;
......@@ -155,7 +146,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
time_limit: 180
};
room: Room = { title: this.loginService.user.username + '的房间', options: Object.assign({}, this.default_options) };
room: Room = {title: this.loginService.user.username + '的房间', options: Object.assign({}, this.default_options)};
rooms: Room[] = [];
......@@ -184,8 +175,23 @@ export class YGOProComponent implements OnInit, OnDestroy {
constructor(private http: Http, private appsService: AppsService, private loginService: LoginService,
public settingsService: SettingsService, private ref: ChangeDetectorRef) {
switch (process.platform) {
// linux should have fonts set by default
case 'linux':
this.numfont = [
'/usr/share/fonts/truetype/DroidSansFallbackFull.ttf',
'/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc',
'/usr/share/fonts/google-noto-cjk/NotoSansCJK-Bold.ttc',
'/usr/share/fonts/noto-cjk/NotoSansCJK-Bold.ttc',
];
this.textfont = [
'/usr/share/fonts/truetype/DroidSansFallbackFull.ttf',
'/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc',
'/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc',
'/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc',
];
break;
case 'darwin':
this.numfont = ['/System/Library/Fonts/SFNSTextCondensed-Bold.otf','/System/Library/Fonts/Supplemental/Arial.ttf'];
this.numfont = ['/System/Library/Fonts/SFNSTextCondensed-Bold.otf', '/System/Library/Fonts/Supplemental/Arial.ttf'];
this.textfont = ['/System/Library/Fonts/PingFang.ttc'];
break;
case 'win32':
......@@ -246,11 +252,11 @@ export class YGOProComponent implements OnInit, OnDestroy {
refresh_replay_rooms() {
this.replay_rooms_show = this.replay_rooms.filter((room) => {
return ((this.replay_rooms_filter.athletic && room.arena === 'athletic') ||
(this.replay_rooms_filter.entertain && room.arena === 'entertain') ||
(this.replay_rooms_filter.single && room.options.mode === 0 && !room.arena && !room.id!.startsWith('AI#')) ||
(this.replay_rooms_filter.match && room.options.mode === 1 && !room.arena && !room.id!.startsWith('AI#')) ||
(this.replay_rooms_filter.tag && room.options.mode === 2 && !room.arena && !room.id!.startsWith('AI#')) ||
(this.replay_rooms_filter.windbot && room.id!.startsWith('AI#')));
(this.replay_rooms_filter.entertain && room.arena === 'entertain') ||
(this.replay_rooms_filter.single && room.options.mode === 0 && !room.arena && !room.id!.startsWith('AI#')) ||
(this.replay_rooms_filter.match && room.options.mode === 1 && !room.arena && !room.id!.startsWith('AI#')) ||
(this.replay_rooms_filter.tag && room.options.mode === 2 && !room.arena && !room.id!.startsWith('AI#')) ||
(this.replay_rooms_filter.windbot && room.id!.startsWith('AI#')));
}).sort((a, b) => {
// if (a.arena === 'athletic' && b.arena === 'athletic') {
// return a.dp - b.dp;
......@@ -306,11 +312,11 @@ export class YGOProComponent implements OnInit, OnDestroy {
case 'init':
this.rooms_loading = false;
this.rooms = this.rooms.filter(room => room.server !== server).concat(
message.data.map((room: Room) => Object.assign({ server: server }, room))
message.data.map((room: Room) => Object.assign({server: server}, room))
);
break;
case 'create':
this.rooms.push(Object.assign({ server: server }, message.data));
this.rooms.push(Object.assign({server: server}, message.data));
break;
case 'update':
Object.assign(this.rooms.find(room => room.server === server && room.id === message.data.id), message.data);
......@@ -467,12 +473,12 @@ export class YGOProComponent implements OnInit, OnDestroy {
};
async load_system_conf(): Promise<SystemConf> {
let data = await fs.readFile(this.system_conf, { encoding: 'utf-8' });
let data = await fs.readFile(this.system_conf, {encoding: 'utf-8'});
return <any>ini.parse(data);
};
save_system_conf(data: SystemConf) {
return fs.writeFile(this.system_conf, ini.unsafe(ini.stringify(data, <EncodeOptions>{ whitespace: true })));
return fs.writeFile(this.system_conf, ini.unsafe(ini.stringify(data, <EncodeOptions>{whitespace: true})));
};
async join(name: string, server: Server) {
......@@ -551,7 +557,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
console.log(error);
}
try {
this.http.get('https://api.mycard.moe/ygopro/arena/user', { search: { username: this.loginService.user.username } })
this.http.get('https://api.mycard.moe/ygopro/arena/user', {search: {username: this.loginService.user.username}})
.map((response) => response.json())
.toPromise()
.then((d2) => {
......@@ -629,7 +635,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
}
let password = options_buffer.toString('base64') + (room.private ? this.host_password :
room.title!.replace(/\s/, String.fromCharCode(0xFEFF)));
room.title!.replace(/\s/, String.fromCharCode(0xFEFF)));
// let room_id = crypto.createHash('md5').update(password + this.loginService.user.username).digest('base64')
// .slice(0, 10).replace('+', '-').replace('/', '_');
......@@ -644,7 +650,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
copy(text: string, event: Event) {
clipboard.writeText(text);
const copyWrapper = $('#copy-wrapper');
copyWrapper.tooltip({ trigger: 'manual' })
copyWrapper.tooltip({trigger: 'manual'});
copyWrapper.tooltip('show');
}
......@@ -701,7 +707,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
}
}).map(response => response.json())
.subscribe((data) => {
this.join(data['password'], { address: data['address'], port: data['port'] });
this.join(data['password'], {address: data['address'], port: data['port']});
}, (error) => {
alert(`匹配失败`);
this.matching = matching = undefined;
......
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