Commit bac2a8c3 authored by wudizhanche1000's avatar wudizhanche1000

修改AppsService导航方式

parent b8c1f277
......@@ -2,7 +2,7 @@
<h2>{{appsService._aa}}</h2>
<div *ngIf="!isInstalled">
<div *ngIf="!appsService.getDownloadInfo(routingService.app)">
<button type="button" 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>-->
</div>
......@@ -176,52 +176,51 @@
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<form id="install-form" class="modal-content" (ngSubmit)="installSubmit(theForm)" #theForm="ngForm">
<form id="install-form" class="modal-content" (ngSubmit)="installSubmit()" #theForm="ngForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="myModalLabel">安装 {{name}}</h4>
<h4 class="modal-title" id="myModalLabel">{{'install'|translate}} {{name}}</h4>
</div>
<div class="modal-body">
<p>即将开始安装 {{name}}</p>
<!-- 安装位置选择只在 windows 下存在, 为了方便调试暂时不加ngif -->
<h4>安装位置</h4>
<h4>{{'install_path'|translate}}</h4>
<div class="form-group">
<div class="input-group">
<input type="text" [(ngModel)]="appsService.installConfig.installDir" name="installDir"
class="form-control" placeholder="安装位置">
<span class="input-group-btn">
<button (click)="selectDir()" class="btn btn-secondary" type="button">浏览</button>
</span>
</div>
<select class="form-control">
<option *ngFor="let library of settings.getLibraries()" [selected]="library['default']">
{{ library['path']}}
</option>
</select>
</div>
<h4>快捷方式</h4>
<h4>{{'shortcut'|translate}}</h4>
<div class="checkbox">
<label>
<input type="checkbox" [(ngModel)]="appsService.installConfig.shortcut.application"
name="application">
创建应用程序快捷方式
<input type="checkbox" name="application" [(ngModel)]="installConfig.createShortcut">
{{'create_shortcut'|translate}}
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" [(ngModel)]="appsService.installConfig.shortcut.desktop" name="desktop">
创建桌面快捷方式
<input type="checkbox" name="desktop" [(ngModel)]="installConfig.createDesktopShortcut">
{{'create_desktop_shortcut'|translate}}
</label>
</div>
<h4>附加内容</h4>
<div *ngFor="let mod of currentApp.references[platform]">
<h4>{{'additions'|translate}}</h4>
<div *ngFor="let reference of installConfig.references">
<label>
<input type="checkbox" [(ngModel)]="appsService.installConfig.mods[mod.id]" name="{{mod.id}}"
[disabled]="['dependency', 'runtime'].includes(mod.type)">
{{appsService.searchApp(mod.id).name[appsService.searchApp(mod.id).locales[0]]}}
<input type="checkbox" [(ngModel)]="reference.id" name="references"
value="{{reference.id}}">
{{reference.name}}
</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button id="submit" type="submit" [disabled]="!theForm.form.valid" class="btn btn-primary">安装</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{'cancel'|translate}}</button>
<button id="submit" type="submit" [disabled]="!theForm.form.valid" class="btn btn-primary">
{{'install' |translate}}
</button>
</div>
</form>
</div>
......
import {Component} from '@angular/core';
import {AppsService} from './apps.service'
import {RoutingService} from './routing.service'
import {Component, OnInit} from "@angular/core";
import {AppsService} from "./apps.service";
import {RoutingService} from "./routing.service";
import {App} from "./app";
import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices";
declare var process;
declare var $;
@Component({
selector: 'app-detail',
templateUrl: 'app/app-detail.component.html',
styleUrls: ['app/app-detail.component.css'],
})
export class AppDetailComponent {
export class AppDetailComponent implements OnInit{
platform = process.platform;
fs = window['System']._nodeRequire('fs');
......@@ -18,15 +21,22 @@ export class AppDetailComponent {
spawn = window['System']._nodeRequire('child_process').spawn;
path = window['System']._nodeRequire('path');
constructor(private appsService: AppsService, private routingService: RoutingService) {
installConfig: InstallConfig;
ngOnInit(){
this.updateInstallConfig();
}
updateInstallConfig() {
this.installConfig = this.appsService.getInstallConfig(this.currentApp);
}
constructor(private appsService: AppsService, private routingService: RoutingService, private settings: SettingsService) {
}
_currentApp;
get currentApp(): App {
return this.appsService.searchApp(this.routingService.app);
}
_name;
get name() {
if (this.currentApp) {
return this.currentApp.name[this.currentApp.locales[0]];
......@@ -34,13 +44,11 @@ export class AppDetailComponent {
return "Loading";
};
_isInstalled;
get isInstalled() {
return this.checkInstall(this.routingService.app);
}
_news;
get news() {
if (this.currentApp) {
if (this.currentApp.news.length > 0) {
......@@ -49,17 +57,14 @@ export class AppDetailComponent {
}
}
_friends;
get friends() {
return false;
}
_achievement;
get achievement() {
return false;
}
_mods;
get mods() {
let contains = ["optional", "language", "emulator"];
......@@ -127,14 +132,14 @@ export class AppDetailComponent {
}
installSubmit(theForm) {
console.log(theForm);
this.install(this.routingService.app);
for (let mod in this.appsService.installConfig.mods) {
if (this.appsService.installConfig.mods[mod]) {
this.install(mod);
}
}
installSubmit() {
console.log(this.installConfig);
// this.install(this.routingService.app);
// for (let mod in this.appsService.installConfig.mods) {
// if (this.appsService.installConfig.mods[mod]) {
// this.install(mod);
// }
// }
}
selectDir() {
......
import {AppLocal} from "./app-local";
/*
export enum Reference_Type {
runtime, // directx
emulator, // wine, np2
dependency, //
optional, // fxtz
language
}
*/
export enum Reference_Type {
runtime, // directx
emulator, // wine, np2
dependency, //
optional, // fxtz
language,
host
}
*/
/*
export enum App_Category {
game,
music,
book,
runtime, // directx
emulator, // wine, np2
language
}
*/
export enum App_Category {
game,
music,
book,
runtime, // directx
emulator, // wine, np2
language
}
*/
export class App {
id: string;
......@@ -27,21 +28,24 @@ export class App {
author: string; // English Only
homepage: string;
category: string;
parent: App;
actions: {[platform: string]: {[action: string]: {execute: string, args: string[], env: {}, open: string}}};
references: {[platform: string]: {id: string, type: string}[]};
references: Map<string,App>;
dependencies: Map<string,App>;
locales: string[];
download: {[platform: string]: string}; // meta4 url
news: {title: string, url: string, image: string}[];
tags: string[];
version: {[platform: string]: string};
local: AppLocal;
constructor(app: AppInterface) {
this.id = app.id;
this.name = app.name;
this.description = app.description;
this.author = app.author;
this.homepage = app.homepage;
this.category =app.category;
this.category = app.category;
this.actions = app.actions;
this.references = app.references;
this.locales = app.locales;
......
import {Component} from '@angular/core';
import {AppsService} from './apps.service'
import {RoutingService} from './routing.service'
import {Component, OnInit} from "@angular/core";
import {AppsService} from "./apps.service";
import {RoutingService} from "./routing.service";
@Component({
selector: 'apps',
templateUrl: 'app/apps.component.html',
styleUrls: ['app/apps.component.css'],
})
export class AppsComponent {
export class AppsComponent implements OnInit {
constructor(private appsService: AppsService, private routingService: RoutingService) {
appsService.getApps(()=> {
//console.log(appsService.data)
if (appsService.data.length > 0) {
this.selectApp(appsService.data[0].id);
let tmp = this.appsService.data.filter((v)=>v.id === this.routingService.app);
//console.log(tmp);
}
});
}
_apps;
get apps() {
let contains = ["game", "music", "book"];
let data = this.appsService.data;
let apps;
if (data) {
apps = this.appsService.data.filter((app)=> {
return contains.includes(app.category);
});
}
return apps || [];
ngOnInit() {
}
selectApp(id) {
this.routingService.app = id;
this.appsService.createInstallConfig(id);
}
// _apps;
// get apps() {
//
// 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() {
let contains = ["game", "music", "book"];
let apps = Array.from(this.appsService.allApps.values());
let result = {'installed': []};
for (let app of this.apps) {
if (app.local) {
result.installed.push(app)
} else {
if (!result[app.tags[0]]) {
result[app.tags[0]] = []
for (let app of apps) {
if (contains.includes(app.category)) {
if (app.local) {
result.installed.push(app)
} else {
if (!result[app.tags[0]]) {
result[app.tags[0]] = []
}
result[app.tags[0]].push(app)
}
result[app.tags[0]].push(app)
}
}
//console.log(result)
......
import {Injectable, transition} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/Rx';
import {Injectable, OnInit} from "@angular/core";
import {Http} from "@angular/http";
import "rxjs/Rx";
import {App} from "./app";
import {AppLocal} from "./app-local";
import {TranslateService} from "ng2-translate";
import {RoutingService} from "./routing.service";
import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices";
declare var process;
const os = window['System']._nodeRequire('os');
......@@ -16,9 +16,12 @@ const Aria2 = window['System']._nodeRequire('aria2');
const execFile = window['System']._nodeRequire('child_process').execFile;
@Injectable()
export class AppsService {
export class AppsService implements OnInit {
constructor(private http: Http, private translate: TranslateService) {
currentApp: App;
constructor(private http: Http, private translate: TranslateService, private settings: SettingsService) {
let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=> {
if (res) {
......@@ -36,10 +39,23 @@ export class AppsService {
}
ngOnInit() {
this.getApps(()=> {
//console.log(appsService.data)
if (this.data.size > 0) {
this.currentApp = this.data.get('ygopro');
}
});
}
//localStorage = window['localStorage'];
data: App[];
private data: Map<string,App>;
get allApps(): Map<string,App> {
return this.data;
}
//[{"id": "th01", "gid": "aria2gid", "status": "active/install/complete/wait", "progress": "0-100"}]
downloadsInfo = [];
......@@ -174,7 +190,7 @@ export class AppsService {
apps = apps.map((app)=> {
if (localAppData) {
localAppData.map((v)=> {
if (v.id == app.id) {
if (v.id === app.id) {
app.local = v.local;
}
});
......@@ -184,22 +200,25 @@ export class AppsService {
return apps;
})
.subscribe((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);
}
}
}
}).map(this.loadApps)
.subscribe((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') {
callback();
......@@ -207,14 +226,18 @@ export class AppsService {
});
}
loadApps(data: any): Map<string,App> {
let result = new Map<string,App>();
for (let item of data) {
let id = item["id"];
let app = new App(item);
result.set(id, app);
}
return result;
}
searchApp(id): App {
let data = this.data;
let tmp;
if (data) {
tmp = data.find((v)=>v.id === id);
return tmp;
}
return this.data.get(id);
}
checkInstall(id): boolean {
......@@ -291,33 +314,47 @@ export class AppsService {
installConfig;
createInstallConfig(id) {
let app = this.data.find((app)=> {
return app.id == id;
});
getInstallConfig(app: App): InstallConfig {
let id = app.id;
let installConfig = new InstallConfig(app);
let platform = process.platform;
let mods = {};
let references: InstallConfig[] = [];
if (app.references[platform]) {
app.references[platform].map((mod)=> {
mods[mod.id] = false;
});
// app.references[platform].forEach((item)=> {
// references.push();
// });
}
let tmp = {
installDir: path.join(electron.remote.app.getPath('appData'), 'mycard'),
shortcut: {
desktop: false,
application: false
},
mods: mods
};
//console.log(tmp);
this.installConfig = tmp;
return tmp;
installConfig.references = references;
return installConfig;
}
// createInstallConfig(id) {
// let app = this.data.find((app)=> {
// return app.id == id;
// });
// let platform = process.platform;
// let mods = {};
// if (app.references[platform]) {
// app.references[platform].map((mod)=> {
// mods[mod.id] = false;
// });
//
// }
//
// let tmp = {
// installDir: path.join(electron.remote.app.getPath('appData'), 'mycard'),
// shortcut: {
// desktop: false,
// application: false
// },
// mods: mods
// };
// //console.log(tmp);
// this.installConfig = tmp;
// return tmp;
//
// }
// tar
tarQueue = [];
isExtracting = false;
......@@ -421,12 +458,8 @@ export class AppsService {
this.downloadsInfo[downLoadsInfoIndex].status = "complete";
// 为了卸载时能重新显示安装条
this.downloadsInfo.splice(downLoadsInfoIndex, 1);
this.data = this.data.map((app)=> {
if (app.id == tarObj.id) {
app.local = appLocal.local;
}
return app;
});
this.data.get(tarObj.id).local = appLocal.local;
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
this.waitInstallQueue = this.waitInstallQueue.map((waitObj)=> {
waitObj.wait.splice(waitObj.wait.findIndex(()=>tarObj.id), 1);
......
import {App} from "./app";
/**
* Created by weijian on 2016/10/24.
*/
export class InstallConfig {
app: App;
install: boolean;
installPath: string;
installDir: string;
createShortcut: boolean;
createDesktopShortcut: boolean;
references: InstallConfig[];
constructor(app: App, installPath = ".", installDir = "", install = true, shortcut = false, desktopShortcut = false) {
this.app = app;
this.createShortcut = shortcut;
this.createDesktopShortcut = desktopShortcut;
this.install = install;
this.installDir = installDir;
}
updateChecked() {
}
}
\ No newline at end of file
<!-- Begin page content -->
<div id="main">
<apps></apps>
<apps *ngIf="appsService.allApps"></apps>
<app-detail *ngIf="routingService.app"></app-detail>
<roster></roster>
</div>
<webview id="candy" src="./candy/index.html?jid=zh99998@mycard.moe&password=&nickname=zh99998测试&autojoin=ygopro_china_north@conference.mycard.moe" nodeintegration></webview>
\ No newline at end of file
<webview id="candy"
src="./candy/index.html?jid=zh99998@mycard.moe&password=&nickname=zh99998测试&autojoin=ygopro_china_north@conference.mycard.moe"
nodeintegration></webview>
\ No newline at end of file
/**
* 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";
@Component({
selector: 'lobby',
templateUrl: 'app/lobby.component.html',
styleUrls: ['app/lobby.component.css'],
})
export class LobbyComponent {
constructor(private routingService: RoutingService) {
constructor(private routingService: RoutingService, private appsService: AppsService) {
}
}
......@@ -84,8 +84,13 @@ li > a:hover, #window-buttons > i:hover {
}
/* https://github.com/electron/electron/issues/7661#event-827104990 */
.hide {
webview.hide {
width: 0;
height: 0;
flex: 0 1;
display: inherit;
}
.hide {
display: none;
}
\ No newline at end of file
......@@ -6,11 +6,11 @@
<a (click)="changeFouce('store')" class="nav-link" href="#">商店</a>
</li>
-->
<li [ngClass]="{active: routingService.component == 'lobby'}" class="nav-item">
<a (click)="changeFouce('lobby')" class="nav-link" href="#">{{'library'| translate}}<span class="sr-only">(current)</span></a>
<li [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 [ngClass]="{active: routingService.component == 'community'}" class="nav-item">
<a (click)="changeFouce('community')" class="nav-link" href="#">{{'community'| translate}}</a>
<li [ngClass]="{active: currentPage === 'community'}" class="nav-item">
<a (click)="currentPage='community'" class="nav-link" href="#">{{'community'| translate}}</a>
</li>
</ul>
<div class="navbar-right">
......@@ -19,7 +19,7 @@
<img id="avatar" src="https://ygobbs.com/letter_avatar_proxy/v2/letter/a/e47774/36.png" alt="image">
</a>
<a href="#forum" class="require-login profile item" id="username"></a>
<a (click)="changeFouce('login');" href="#ygopro" id="logout" class="require-login item">切换账号</a>
<a (click)="currentPage='login'" href="#ygopro" id="logout" class="require-login item">切换账号</a>
<a (click)="refresh()" href="#ygopro" id="refresh" class="item">刷新</a>
</div>
<div id="window-buttons" [class.darwin]="platform == 'darwin'">
......@@ -31,8 +31,8 @@
</div>
</nav>
<login class="page" [ngClass]="{hide: routingService.component != 'login'}"></login>
<store class="page" [ngClass]="{hide: routingService.component != 'store'}"></store>
<lobby class="page" [ngClass]="{hide: routingService.component != 'lobby'}"></lobby>
<webview id="community" class="page" [ngClass]="{hide: routingService.component != 'community'}"
<login class="page" [ngClass]="{hide: currentPage!= 'login'}"></login>
<store class="page" [ngClass]="{hide: currentPage!= 'store'}"></store>
<lobby class="page" [ngClass]="{hide: currentPage!= 'lobby'}"></lobby>
<webview id="community" class="page" [ngClass]="{hide: currentPage!= 'community'}"
src="https://ygobbs.com"></webview>
\ No newline at end of file
import {Component, Renderer} from '@angular/core';
import {TranslateService} from 'ng2-translate';
import {RoutingService} from './routing.service';
import {Component, Renderer} from "@angular/core";
import {TranslateService} from "ng2-translate";
import {RoutingService} from "./routing.service";
const electron = System._nodeRequire('electron');
declare var process;
declare var System;
......@@ -14,6 +14,8 @@ declare var System;
})
export class MyCardComponent {
currentPage: string="lobby";
platform = process.platform;
constructor(private routingService: RoutingService, private renderer: Renderer, private translate: TranslateService) {
......@@ -30,9 +32,6 @@ export class MyCardComponent {
}
changeFouce(component) {
this.routingService.component = component;
}
refresh() {
electron.remote.getCurrentWindow().reload()
......
import {NgModule, NO_ERRORS_SCHEMA} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';
import {MyCardComponent} from './mycard.component';
import {LoginComponent} from './login.component';
import {StoreComponent} from './store.component';
import {LobbyComponent} from './lobby.component';
import {AppsComponent} from './apps.component';
import {AppDetailComponent} from './app-detail.component';
import {RosterComponent} from './roster.component';
import {CandyComponent} from './candy.component';
import {CommunityComponent} from './community.component';
import {YGOProComponent} from './ygopro.component';
import {RoutingService} from './routing.service';
import {AppsService} from './apps.service';
import {TranslateModule} from 'ng2-translate';
import {NgModule, NO_ERRORS_SCHEMA} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {HttpModule} from "@angular/http";
import {MyCardComponent} from "./mycard.component";
import {LoginComponent} from "./login.component";
import {StoreComponent} from "./store.component";
import {LobbyComponent} from "./lobby.component";
import {AppsComponent} from "./apps.component";
import {AppDetailComponent} from "./app-detail.component";
import {RosterComponent} from "./roster.component";
import {CandyComponent} from "./candy.component";
import {CommunityComponent} from "./community.component";
import {YGOProComponent} from "./ygopro.component";
import {RoutingService} from "./routing.service";
import {AppsService} from "./apps.service";
import {TranslateModule} from "ng2-translate";
import {SettingsService} from "./settings.sevices";
@NgModule({
imports: [BrowserModule, FormsModule, HttpModule, TranslateModule.forRoot()],
imports: [BrowserModule, FormsModule, ReactiveFormsModule, HttpModule, TranslateModule.forRoot()],
declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent, YGOProComponent],
bootstrap: [MyCardComponent],
providers: [RoutingService, AppsService],
providers: [RoutingService, AppsService,SettingsService],
schemas: [NO_ERRORS_SCHEMA]
})
export class MyCard {
......
/**
* Created by weijian on 2016/10/24.
*/
import {Injectable} from "@angular/core";
@Injectable()
export class SettingsService {
static SETTING_LIBRARY = "library";
libraries: [{selected: boolean,path: string}];
getLibraries() {
if (!this.libraries) {
let data = localStorage.getItem(SettingsService.SETTING_LIBRARY);
this.libraries = JSON.parse(data);
}
return this.libraries;
}
getDefaultLibrary() {
if (!this.libraries) {
this.getLibraries()
}
return this.libraries.find((item)=>item.selected === true);
}
static SETTING_LOCALE = "locale";
locale: string;
getLocale(): string {
if (!this.locale) {
this.locale = localStorage.getItem(SettingsService.SETTING_LOCALE);
}
return this.locale;
}
setLocal(locale: string) {
this.locale = locale;
localStorage.setItem(SettingsService.SETTING_LOCALE, locale);
}
}
\ No newline at end of file
......@@ -2,9 +2,17 @@
"library": "游戏",
"community": "社区",
"settings": "设置",
"cancel": "取消",
"install": "安装",
"uninstall": "卸载",
"general": "常规",
"updates": "更新",
"local files": "本地文件",
"uninstall confirm": "这将删除所有本地内容,确认执行?"
"uninstall confirm": "这将删除所有本地内容,确认执行?",
"browse": "浏览",
"install_path": "安装路径",
"shortcut": "快捷方式",
"create_shortcut": "创建应用程序快捷方式",
"create_desktop_shortcut": "创建桌面快捷方式",
"additions": "附加内容"
}
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