Commit ebdab037 authored by wudizhanche1000's avatar wudizhanche1000

除去RoutingService的使用

parent 65b3f181
<h1>{{'app.' + currentApp.id + '.name' | translate}}</h1> <h1>{{'app.' + appsService.currentApp.id + '.name' | translate}}</h1>
<h2>{{appsService._aa}}</h2> <h2>{{appsService._aa}}</h2>
<div *ngIf="!isInstalled"> <div *ngIf="!isInstalled">
<div *ngIf="!appsService.getDownloadInfo(routingService.app)"> <div *ngIf="!appsService.getDownloadInfo(appsService.currentApp)">
<button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal" data-target="#install-modal">安装</button> <button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal"
data-target="#install-modal">安装
</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>-->
</div> </div>
<div *ngIf="appsService.getDownloadInfo(routingService.app)"> <div *ngIf="appsService.getDownloadInfo(appsService.currentApp)">
<div *ngIf="appsService.getDownloadInfo(routingService.app).status === 'install'">正在安装...</div> <div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'install'">正在安装...</div>
<div *ngIf="appsService.getDownloadInfo(routingService.app).status === 'wait'">等待安装...</div> <div *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'wait'">等待安装...</div>
<progress *ngIf="appsService.getDownloadInfo(routingService.app).status === 'active'" <progress *ngIf="appsService.getDownloadInfo(appsService.currentApp).status === 'active'"
class="progress progress-striped progress-animated" class="progress progress-striped progress-animated"
value="{{appsService.getDownloadInfo(routingService.app).progress}}" max="100"> value="{{appsService.getDownloadInfo(appsService.currentApp).progress}}" max="100">
</progress> </progress>
</div> </div>
</div> </div>
<div *ngIf="isInstalled && (routingService.app != 'ygopro')"> <div *ngIf="isInstalled && (appsService.currentApp != 'ygopro')">
<button (click)="startApp(routingService.app)" 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(routingService.app)" 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">联机</button> <button type="button" class="btn btn-secondary">联机</button>
</div> </div>
<ygopro *ngIf="isInstalled && (routingService.app == 'ygopro')"></ygopro> <ygopro *ngIf="isInstalled && (appsService.currentApp == 'ygopro')"></ygopro>
<br> <br>
<h2 *ngIf="news">新闻</h2> <h2 *ngIf="news">新闻</h2>
<!--<div *ngIf="news">
<div class="list-group">
<a *ngFor="let item of news" href="{{item.url}}" class="list-group-item">{{item.title}}</a>
</div>
</div>-->
<!--<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li *ngFor="let item of news; let index = index;" data-target="#carousel-example-generic" [data-slide-to]="index" [class.active]="index == 0"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div *ngFor="let item of news; let index = index;" class="carousel-item" [class.active]="index == 0">
<img [src]="item.image" [alt]="item.title">
<div class="carousel-caption">
<h3>{{item.title}}</h3>
<p>{{item.text}}</p>
</div>
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="icon-prev" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="icon-next" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>-->
<div id="news" *ngFor="let item of news"> <div id="news" *ngFor="let item of news">
<h3>{{item.title}}</h3> <h3>{{item.title}}</h3>
<p>{{item.text}}</p> <p>{{item.text}}</p>
...@@ -116,7 +88,7 @@ ...@@ -116,7 +88,7 @@
<div *ngIf="isInstalled"> <div *ngIf="isInstalled">
<h2>本地文件</h2> <h2>本地文件</h2>
<button (click)="appsService.browse(routingService.app)" type="button" class="btn btn-secondary">浏览本地文件</button> <button (click)="appsService.browse(appsService.currentApp)" type="button" class="btn btn-secondary">浏览本地文件</button>
<button (click)="uninstall()" type="button" class="btn btn-secondary">{{'uninstall'|translate}}</button> <button (click)="uninstall()" type="button" class="btn btn-secondary">{{'uninstall'|translate}}</button>
</div> </div>
...@@ -189,7 +161,7 @@ ...@@ -189,7 +161,7 @@
<h4>{{'install_path'|translate}}</h4> <h4>{{'install_path'|translate}}</h4>
<div class="form-group"> <div class="form-group">
<select class="form-control"> <select class="form-control">
<option *ngFor="let library of settings.getLibraries()" [selected]="library['default']"> <option *ngFor="let library of settingsService.getLibraries()" [selected]="library['default']">
{{ library['path']}} {{ library['path']}}
</option> </option>
</select> </select>
......
import {Component, OnInit} from "@angular/core"; import {Component, OnInit} from "@angular/core";
import {AppsService} from "./apps.service"; import {AppsService} from "./apps.service";
import {RoutingService} from "./routing.service";
import {App} from "./app";
import {InstallConfig} from "./install-config"; import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
...@@ -13,7 +11,7 @@ declare var $; ...@@ -13,7 +11,7 @@ declare var $;
templateUrl: 'app/app-detail.component.html', templateUrl: 'app/app-detail.component.html',
styleUrls: ['app/app-detail.component.css'], styleUrls: ['app/app-detail.component.css'],
}) })
export class AppDetailComponent implements OnInit{ export class AppDetailComponent implements OnInit {
platform = process.platform; platform = process.platform;
fs = window['System']._nodeRequire('fs'); fs = window['System']._nodeRequire('fs');
...@@ -23,37 +21,34 @@ export class AppDetailComponent implements OnInit{ ...@@ -23,37 +21,34 @@ export class AppDetailComponent implements OnInit{
installConfig: InstallConfig; installConfig: InstallConfig;
ngOnInit(){ constructor(private appsService: AppsService, private settingsService: SettingsService) {
this.updateInstallConfig();
}
updateInstallConfig() {
this.installConfig = this.appsService.getInstallConfig(this.currentApp);
} }
constructor(private appsService: AppsService, private routingService: RoutingService, private settings: SettingsService) { ngOnInit() {
this.updateInstallConfig();
} }
get currentApp(): App { updateInstallConfig() {
return this.appsService.searchApp(this.routingService.app); this.installConfig = this.appsService.getInstallConfig(this.appsService.currentApp);
} }
get name() { get name() {
if (this.currentApp) { let currentApp = this.appsService.currentApp;
return this.currentApp.name[this.currentApp.locales[0]]; if (currentApp) {
return currentApp.name[this.settingsService.getLocale()];
} }
return "Loading"; return "Loading";
}; };
get isInstalled() { get isInstalled() {
return this.checkInstall(this.routingService.app); return this.checkInstall(this.appsService.currentApp);
} }
get news() { get news() {
if (this.currentApp) { let currentApp = this.appsService.currentApp;
if (this.currentApp.news.length > 0) { if (currentApp) {
return this.currentApp.news; return currentApp.news;
}
} }
} }
...@@ -68,9 +63,10 @@ export class AppDetailComponent implements OnInit{ ...@@ -68,9 +63,10 @@ export class AppDetailComponent implements OnInit{
get mods() { get mods() {
let contains = ["optional", "language", "emulator"]; let contains = ["optional", "language", "emulator"];
if (this.currentApp) { let currentApp = this.appsService.currentApp;
if (this.currentApp.references[process.platform] && this.currentApp.references[process.platform].length > 0) { if (currentApp) {
let refs = this.currentApp.references[process.platform]; if (currentApp.references[process.platform] && currentApp.references[process.platform].length > 0) {
let refs = currentApp.references[process.platform];
refs = refs.filter((ref)=> { refs = refs.filter((ref)=> {
return contains.includes(ref.type); return contains.includes(ref.type);
}); });
...@@ -123,7 +119,6 @@ export class AppDetailComponent implements OnInit{ ...@@ -123,7 +119,6 @@ export class AppDetailComponent implements OnInit{
uninstall(id: string) { uninstall(id: string) {
if (confirm("确认删除?")) { if (confirm("确认删除?")) {
this.uninstalling = true; this.uninstalling = true;
id = this.currentApp.id;
this.appsService.uninstall(id).then(()=> { this.appsService.uninstall(id).then(()=> {
this.uninstalling = false; this.uninstalling = false;
} }
......
<span *ngIf="grouped_apps.installed">已安装</span> <span *ngIf="grouped_apps.installed">已安装</span>
<ul *ngIf="grouped_apps.installed" class="nav nav-sidebar"> <ul *ngIf="grouped_apps.installed" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.installed" [class.active]="app.id==routingService.app"> <li *ngFor="let app of grouped_apps.installed" [class.active]="app===appsService.currentApp">
<a (click)="selectApp(app.id)" href="#">{{app.name[app.locales[0]]}}</a> <a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
</li> </li>
</ul> </ul>
<span *ngIf="grouped_apps.yugioh">游戏王</span> <span *ngIf="grouped_apps.yugioh">游戏王</span>
<ul *ngIf="grouped_apps.yugioh" class="nav nav-sidebar"> <ul *ngIf="grouped_apps.yugioh" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.yugioh" [class.active]="app.id==routingService.app"> <li *ngFor="let app of grouped_apps.yugioh" [class.active]="app===appsService.currentApp">
<a (click)="selectApp(app.id)" href="#">{{app.name[app.locales[0]]}}</a> <a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
</li> </li>
</ul> </ul>
<span *ngIf="grouped_apps.touhou">东方 Project</span> <span *ngIf="grouped_apps.touhou">东方 Project</span>
<ul *ngIf="grouped_apps.touhou" class="nav nav-sidebar"> <ul *ngIf="grouped_apps.touhou" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou" [class.active]="app.id==routingService.app"> <li *ngFor="let app of grouped_apps.touhou" [class.active]="app===appsService.currentApp">
<a (click)="selectApp(app.id)" href="#">{{app.name[app.locales[0]]}}</a> <a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
</li> </li>
</ul> </ul>
<span *ngIf="grouped_apps.touhou_pc98">东方旧作</span> <span *ngIf="grouped_apps.touhou_pc98">东方旧作</span>
<ul *ngIf="grouped_apps.touhou_pc98" class="nav nav-sidebar"> <ul *ngIf="grouped_apps.touhou_pc98" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou_pc98" [class.active]="app.id==routingService.app"> <li *ngFor="let app of grouped_apps.touhou_pc98" [class.active]="app===appsService.currentApp">
<a (click)="selectApp(app.id)" href="#">{{app.name[app.locales[0]]}}</a> <a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
</li> </li>
</ul> </ul>
\ No newline at end of file
import {Component, OnInit} from "@angular/core"; import {Component, OnInit} from "@angular/core";
import {AppsService} from "./apps.service"; import {AppsService} from "./apps.service";
import {RoutingService} from "./routing.service"; import {App} from "./app";
@Component({ @Component({
selector: 'apps', selector: 'apps',
...@@ -9,31 +9,16 @@ import {RoutingService} from "./routing.service"; ...@@ -9,31 +9,16 @@ import {RoutingService} from "./routing.service";
}) })
export class AppsComponent implements OnInit { export class AppsComponent implements OnInit {
constructor(private appsService: AppsService, private routingService: RoutingService) { constructor(private appsService: AppsService) {
} }
ngOnInit() { ngOnInit() {
} }
// _apps; chooseApp(app: App) {
// get apps() { this.appsService.currentApp = app;
// }
// let data = this.appsService.data;
// let apps;
//
// if (data) {
// apps = this.appsService.data.filter((app)=> {
// return contains.includes(app.category);
// });
// }
//
// return apps || [];
// }
//
// selectApp(id) {
// this.routingService.app = id;
// this.appsService.createInstallConfig(id);
// }
get grouped_apps() { get grouped_apps() {
let contains = ["game", "music", "book"]; let contains = ["game", "music", "book"];
......
...@@ -19,7 +19,15 @@ const execFile = window['System']._nodeRequire('child_process').execFile; ...@@ -19,7 +19,15 @@ const execFile = window['System']._nodeRequire('child_process').execFile;
export class AppsService { export class AppsService {
currentApp: App; private _currentApp: App;
get currentApp(): App {
return this._currentApp;
}
set currentApp(app: App) {
this._currentApp = app;
}
constructor(private http: Http, private translate: TranslateService, private settings: SettingsService) { constructor(private http: Http, private translate: TranslateService, private settings: SettingsService) {
let loop = setInterval(()=> { let loop = setInterval(()=> {
...@@ -197,23 +205,6 @@ export class AppsService { ...@@ -197,23 +205,6 @@ export class AppsService {
.subscribe((apps) => { .subscribe((apps) => {
console.log(apps); console.log(apps);
this.data = apps; this.data = apps;
// for (let app of data) {
// }
// this.data = data;
// for (let app of data) {
// //console.log(app)
// for (let attribute of ['name', 'description']) {
// if (!app[attribute]) {
// continue
// } //这句应当是不需要的, 如果转换成了 App 类型, 应当保证一定有这些属性
// for (let locale of Object.keys(app[attribute])) {
// let result = {};
// result[`app.${app['id']}.${attribute}`] = app[attribute][locale];
// this.translate.setTranslation(locale, result, true);
// }
// }
// }
//console.log(this.data);
if (typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import {RoutingService} from "./routing.service";
@Component({ @Component({
selector: '#candy', selector: '#candy',
templateUrl: 'app/candy.component.html', templateUrl: 'app/candy.component.html',
styleUrls: ['app/candy.component.css'], styleUrls: ['app/candy.component.css'],
}) })
export class CandyComponent { export class CandyComponent {
constructor(private routingService: RoutingService){ constructor(){
} }
} }
<!-- Begin page content --> <!-- Begin page content -->
<div id="main"> <div id="main">
<apps *ngIf="appsService.allApps"></apps> <apps *ngIf="appsService.allApps"></apps>
<app-detail *ngIf="routingService.app"></app-detail> <app-detail *ngIf="appsService._currentApp"></app-detail>
<roster></roster> <roster></roster>
</div> </div>
<webview id="candy" <webview id="candy"
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
import {Component} from "@angular/core"; import {Component} from "@angular/core";
import {RoutingService} from "./routing.service";
import {AppsService} from "./apps.service"; import {AppsService} from "./apps.service";
@Component({ @Component({
selector: 'lobby', selector: 'lobby',
...@@ -10,6 +9,6 @@ import {AppsService} from "./apps.service"; ...@@ -10,6 +9,6 @@ import {AppsService} from "./apps.service";
styleUrls: ['app/lobby.component.css'], styleUrls: ['app/lobby.component.css'],
}) })
export class LobbyComponent { export class LobbyComponent {
constructor(private routingService: RoutingService, private appsService: AppsService) { constructor(private appsService: AppsService) {
} }
} }
import {Component, Renderer} from "@angular/core"; import {Component, Renderer} from "@angular/core";
import {TranslateService} from "ng2-translate"; import {TranslateService} from "ng2-translate";
import {RoutingService} from "./routing.service";
const electron = System._nodeRequire('electron'); const electron = System._nodeRequire('electron');
declare var process; declare var process;
declare var System; declare var System;
...@@ -18,7 +17,7 @@ export class MyCardComponent { ...@@ -18,7 +17,7 @@ export class MyCardComponent {
platform = process.platform; platform = process.platform;
constructor(private routingService: RoutingService, private renderer: Renderer, private translate: TranslateService) { 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'
......
...@@ -12,7 +12,6 @@ import {RosterComponent} from "./roster.component"; ...@@ -12,7 +12,6 @@ import {RosterComponent} from "./roster.component";
import {CandyComponent} from "./candy.component"; import {CandyComponent} from "./candy.component";
import {CommunityComponent} from "./community.component"; import {CommunityComponent} from "./community.component";
import {YGOProComponent} from "./ygopro.component"; import {YGOProComponent} from "./ygopro.component";
import {RoutingService} from "./routing.service";
import {AppsService} from "./apps.service"; import {AppsService} from "./apps.service";
import {TranslateModule} from "ng2-translate"; import {TranslateModule} from "ng2-translate";
import {SettingsService} from "./settings.sevices"; import {SettingsService} from "./settings.sevices";
...@@ -21,7 +20,7 @@ import {SettingsService} from "./settings.sevices"; ...@@ -21,7 +20,7 @@ import {SettingsService} from "./settings.sevices";
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpModule, TranslateModule.forRoot()], imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpModule, TranslateModule.forRoot()],
declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent, YGOProComponent], declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent, YGOProComponent],
bootstrap: [MyCardComponent], bootstrap: [MyCardComponent],
providers: [RoutingService, AppsService,SettingsService], providers: [ AppsService,SettingsService],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}) })
export class MyCard { export class MyCard {
......
import { Injectable } from '@angular/core';
@Injectable()
export class RoutingService {
component = 'lobby';
app;
}
\ No newline at end of file
/** /**
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
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 {RoutingService} from "./routing.service";
declare var process; declare var process;
...@@ -56,7 +55,7 @@ export class YGOProComponent implements OnInit { ...@@ -56,7 +55,7 @@ export class YGOProComponent implements OnInit {
connections = []; connections = [];
constructor(private appsService: AppsService, private routingService: RoutingService, private ref: ChangeDetectorRef) { constructor(private appsService: AppsService, private ref: ChangeDetectorRef) {
this.refresh(); this.refresh();
} }
......
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