Commit 63c630a6 authored by 神楽坂玲奈's avatar 神楽坂玲奈

修复中文用户名登录不进聊天室和Mac ygopro意外退出的问题

parent 7af45124
...@@ -83,7 +83,7 @@ export class DownloadService { ...@@ -83,7 +83,7 @@ export class DownloadService {
map: Map<string,any> = new Map(); map: Map<string,any> = new Map();
async addMetalink(metalink: string, library: string) { async addMetalink(metalink: string, library: string) {
let meta4 = btoa(metalink); let meta4 = new Buffer((metalink)).toString('base64');
let gid = ( await this.aria2.addMetalink(meta4, {dir: library}))[0]; let gid = ( await this.aria2.addMetalink(meta4, {dir: library}))[0];
return Observable.create((observer) => { return Observable.create((observer) => {
this.map.set(gid, observer); this.map.set(gid, observer);
...@@ -111,7 +111,7 @@ export class DownloadService { ...@@ -111,7 +111,7 @@ export class DownloadService {
meta4link = `${this.baseURL}${id}-${process.platform}.meta4` meta4link = `${this.baseURL}${id}-${process.platform}.meta4`
} }
let response = await this.http.get(meta4link).toPromise(); let response = await this.http.get(meta4link).toPromise();
let meta4 = btoa(response.text()); let meta4 = new Buffer(response.text()).toString('base64');
let gid = (await this.aria2.addMetalink(meta4, {dir: path}))[0]; let gid = (await this.aria2.addMetalink(meta4, {dir: path}))[0];
this.appGidMap.set(app, gid); this.appGidMap.set(app, gid);
this.gidAppMap.set(gid, app); this.gidAppMap.set(gid, app);
......
...@@ -23,14 +23,15 @@ ...@@ -23,14 +23,15 @@
<a href="#" (click)="loginService.logout()" class="item">切换账号</a> <a href="#" (click)="loginService.logout()" class="item">切换账号</a>
</div> </div>
<div id="window-buttons" *ngIf="platform != 'darwin'"> <div id="window-buttons" *ngIf="platform != 'darwin'">
<i (click)="currentWindow.minimize()" class="fa fa-minus" aria-hidden="true"></i> <i (click)="currentWindow.minimize()" class="fa fa-minus"></i>
<i *ngIf="!currentWindow.isMaximized()" (click)="currentWindow.maximize()" class="fa fa-expand" aria-hidden="true"></i> <i *ngIf="!currentWindow.isMaximized()" (click)="currentWindow.maximize()" class="fa fa-expand"></i>
<i *ngIf="currentWindow.isMaximized()" (click)="currentWindow.unmaximize()" class="fa fa-clone" aria-hidden="true"></i> <i *ngIf="currentWindow.isMaximized()" (click)="currentWindow.unmaximize()" class="fa fa-clone"></i>
<i (click)="window.close()" class="fa fa-times" aria-hidden="true"></i> <i (click)="window.close()" class="fa fa-times"></i>
</div> </div>
</div> </div>
</nav> </nav>
<login class="page" *ngIf="!loginService.logged_in"></login> <login class="page" *ngIf="!loginService.logged_in"></login>
<store class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'store'"></store> <store class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'store'"></store>
<lobby class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'lobby'"></lobby> <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> <webview class="page" *ngIf="loginService.logged_in" [hidden]="currentPage != 'community'"
\ No newline at end of file src="https://ygobbs.com"></webview>
\ No newline at end of file
import {Component, Renderer, ChangeDetectorRef, OnInit} from "@angular/core"; import {Component, Renderer, ChangeDetectorRef, OnInit} from "@angular/core";
import {TranslateService} from "ng2-translate"; import {TranslateService} from "ng2-translate";
import {remote} from "electron"; import {ipcRenderer, remote} from "electron";
import {LoginService} from "./login.service"; import {LoginService} from "./login.service";
const autoUpdater: Electron.AutoUpdater = remote.getGlobal('autoUpdater');
@Component({ @Component({
...@@ -34,7 +35,23 @@ export class MyCardComponent implements OnInit { ...@@ -34,7 +35,23 @@ export class MyCardComponent implements OnInit {
// 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(remote.app.getLocale()); translate.use(remote.app.getLocale());
this.currentWindow.on('maximize', ()=>ref.detectChanges()); this.currentWindow.on('maximize', () => ref.detectChanges());
this.currentWindow.on('unmaximize', ()=>ref.detectChanges()); this.currentWindow.on('unmaximize', () => ref.detectChanges());
autoUpdater.on('error', (error) => {
console.log('autoUpdater', 'error', error.message)
});
autoUpdater.on('checking-for-update', () => {
console.log('autoUpdater', 'checking-for-update')
});
autoUpdater.on('update-available', () => {
console.log('autoUpdater', 'update-available')
});
autoUpdater.on('update-not-available', () => {
console.log('autoUpdater', 'update-not-available')
});
autoUpdater.on('update-downloaded', (event) => {
console.log('autoUpdater', 'update-downloaded')
});
} }
} }
...@@ -76,9 +76,9 @@ export class YGOProComponent implements OnInit { ...@@ -76,9 +76,9 @@ export class YGOProComponent implements OnInit {
app: App; app: App;
decks: string[] = []; decks: string[] = [];
current_deck: string; current_deck: string;
system_conf; system_conf: string;
numfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']}; numfont: string[];
textfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']}; textfont: string[];
windbot = ["琪露诺", "谜之剑士LV4", "复制植物", "尼亚"]; windbot = ["琪露诺", "谜之剑士LV4", "复制植物", "尼亚"];
...@@ -108,6 +108,16 @@ export class YGOProComponent implements OnInit { ...@@ -108,6 +108,16 @@ export class YGOProComponent implements OnInit {
connections: WebSocket[] = []; connections: WebSocket[] = [];
constructor(private http: Http, private appsService: AppsService, private loginService: LoginService, private ref: ChangeDetectorRef) { constructor(private http: Http, private appsService: AppsService, private loginService: LoginService, private ref: ChangeDetectorRef) {
switch (process.platform) {
case 'darwin':
this.numfont = ['/System/Library/Fonts/SFNSTextCondensed-Bold.otf'];
this.textfont = ['/System/Library/Fonts/PingFang.ttc'];
break;
case 'win32':
this.numfont = [path.join(process.env['SystemRoot'], 'Fonts', 'arialbd.ttf')];
this.textfont = [path.join(process.env['SystemRoot'], 'Fonts', 'simsun.ttc')];
break;
}
} }
ngOnInit() { ngOnInit() {
...@@ -173,8 +183,10 @@ export class YGOProComponent implements OnInit { ...@@ -173,8 +183,10 @@ export class YGOProComponent implements OnInit {
} }
async get_font(files: string[]): Promise<string | undefined> { async get_font(files: string[]): Promise<string | undefined> {
for (let file in files) { for (let file of files) {
console.log(file);
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)));
console.log(found);
if (found) { if (found) {
return file; return file;
} }
...@@ -188,14 +200,14 @@ export class YGOProComponent implements OnInit { ...@@ -188,14 +200,14 @@ export class YGOProComponent implements OnInit {
async fix_fonts(data) { async fix_fonts(data) {
if (!await this.get_font([data.numfont])) { if (!await this.get_font([data.numfont])) {
let font = await this.get_font(this.numfont[process.platform]); let font = await this.get_font(this.numfont);
if (font) { if (font) {
data['numfont'] = font data['numfont'] = font
} }
} }
if (!await this.get_font([data.textfont.split(' ', 2)[0]])) { if (!await this.get_font([data.textfont.split(' ', 2)[0]])) {
let font = await this.get_font(this.textfont[process.platform]); let font = await this.get_font(this.textfont);
if (font) { if (font) {
data['textfont'] = `${font} 14` data['textfont'] = `${font} 14`
} }
...@@ -247,6 +259,7 @@ export class YGOProComponent implements OnInit { ...@@ -247,6 +259,7 @@ export class YGOProComponent implements OnInit {
start_game(args) { start_game(args) {
let win = remote.getCurrentWindow(); let win = remote.getCurrentWindow();
win.minimize(); win.minimize();
console.log(path.join((<AppLocal>this.app.local).path, (<any>this.app.actions.get('main')).execute), args, {cwd: (<AppLocal>this.app.local).path});
return new Promise((resolve, reject) => { 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}); 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) => { child.on('error', (error) => {
...@@ -310,7 +323,7 @@ export class YGOProComponent implements OnInit { ...@@ -310,7 +323,7 @@ export class YGOProComponent implements OnInit {
request_match(arena = 'entertain') { request_match(arena = 'entertain') {
let headers = new Headers(); let headers = new Headers();
headers.append("Authorization", "Basic " + btoa(this.loginService.user.username + ":" + this.loginService.user.external_id)); headers.append("Authorization", "Basic " + new Buffer(this.loginService.user.username + ":" + this.loginService.user.external_id).toString('base64'));
let search = new URLSearchParams(); let search = new URLSearchParams();
search.set("arena", arena); search.set("arena", arena);
this.matching_arena = arena; this.matching_arena = arena;
......
...@@ -2043,9 +2043,7 @@ ...@@ -2043,9 +2043,7 @@
], ],
"dependencies": { "dependencies": {
"win32": [], "win32": [],
"darwin": [ "darwin": []
"wine"
]
}, },
"references": { "references": {
"win32": [], "win32": [],
......
...@@ -20,15 +20,15 @@ ...@@ -20,15 +20,15 @@
const {remote, ipcRenderer} = require('electron'); const {remote, ipcRenderer} = require('electron');
require('electron-cookies'); // https://github.com/hstove/electron-cookies require('electron-cookies'); // https://github.com/hstove/electron-cookies
// remote.getCurrentWebContents().openDevTools(); // remote.getCurrentWebContents().openDevTools();
ipcRenderer.on('join', (event, message) => { ipcRenderer.on('join', (event, message) => {
Candy.Core.Action.Jabber.Room.Join(message); Candy.Core.Action.Jabber.Room.Join(message);
Candy.View.Pane.Chat.setActiveTab(message); Candy.View.Pane.Chat.setActiveTab(message);
}); });
// fix // fix
Base64.encode = btoa.bind(window); Base64.encode = (data) => new Buffer(data).toString('base64');
Base64.decode = atob.bind(window); Base64.decode = (data) => new Buffer(data, 'base64').toString();
// candy init // candy init
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
......
...@@ -12,13 +12,25 @@ if (process.platform == 'darwin') { ...@@ -12,13 +12,25 @@ if (process.platform == 'darwin') {
} }
} }
autoUpdater.on('error', (event)=>console.log('error', event)); global.autoUpdater = autoUpdater;
autoUpdater.on('checking-for-update', (event)=>console.log('checking-for-update'));
autoUpdater.on('update-available', (event)=>console.log('update-available')); autoUpdater.on('error', (event) => {
autoUpdater.on('update-not-available', (event)=>console.log('update-not-available')); console.log('autoUpdater', 'error', event);
});
autoUpdater.on('checking-for-update', () => {
console.log('autoUpdater', 'checking-for-update');
});
autoUpdater.on('update-available', () => {
console.log('autoUpdater', 'update-available');
});
autoUpdater.on('update-not-available', () => {
console.log('autoUpdater', 'update-not-available');
});
let updateWindow; let updateWindow;
autoUpdater.on('update-downloaded', (event)=> { autoUpdater.on('update-downloaded', (event) => {
console.log('autoUpdater', 'update-downloaded', event);
updateWindow = new BrowserWindow({ updateWindow = new BrowserWindow({
width: 640, width: 640,
height: 480, height: 480,
...@@ -114,9 +126,9 @@ function createWindow() { ...@@ -114,9 +126,9 @@ function createWindow() {
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', ()=> { app.on('ready', () => {
autoUpdater.checkForUpdates(); createWindow();
createWindow() setTimeout(autoUpdater.checkForUpdates, 2000);
}); });
// Quit when all windows are closed. // Quit when all windows are closed.
...@@ -135,7 +147,7 @@ app.on('activate', function () { ...@@ -135,7 +147,7 @@ app.on('activate', function () {
// In this file you can include the rest of your app's specific main process // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.
app.on('quit', ()=> { app.on('quit', () => {
// windows 在非 detach 模式下会自动退出子进程 // windows 在非 detach 模式下会自动退出子进程
if (process.platform != 'win32') { if (process.platform != 'win32') {
aria2c.kill() aria2c.kill()
......
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