Commit cdcf2540 authored by wudizhanche1000's avatar wudizhanche1000

修复安装

parent dcff19e1
<h1>{{'app.' + appsService.currentApp.id + '.name' | translate}}</h1>
<h2>{{appsService._aa}}</h2>
<h1>{{appsService.currentApp.name}}</h1>
<div *ngIf="!isInstalled">
<div *ngIf="!appsService.getDownloadInfo(appsService.currentApp)">
<button type="button" (click)="updateInstallConfig()" class="btn btn-primary" data-toggle="modal"
......@@ -146,9 +145,9 @@
</div>
<!-- Modal -->
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
aria-hidden="true" *ngIf="installConfig">
<div class="modal-dialog" role="document">
<form id="install-form" class="modal-content" (ngSubmit)="installSubmit()" #theForm="ngForm">
<form id="install-form" class="modal-content" (ngSubmit)="install()" #theForm="ngForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
......@@ -160,8 +159,8 @@
<!-- 安装位置选择只在 windows 下存在, 为了方便调试暂时不加ngif -->
<h4>{{'install_path'|translate}}</h4>
<div class="form-group">
<select class="form-control">
<option *ngFor="let library of settingsService.getLibraries()" [selected]="library['default']">
<select class="form-control" name="installPath" [(ngModel)]="installConfig.installPath">
<option *ngFor="let library of settingsService.getLibraries()" value="{{library['path']}}">
{{ library['path']}}
</option>
</select>
......
......@@ -30,6 +30,7 @@ export class AppDetailComponent implements OnInit {
updateInstallConfig() {
this.installConfig = this.appsService.getInstallConfig(this.appsService.currentApp);
this.installConfig.installPath = this.settingsService.getDefaultLibrary().path;
}
get name() {
......@@ -41,7 +42,7 @@ export class AppDetailComponent implements OnInit {
};
get isInstalled() {
return this.checkInstall(this.appsService.currentApp);
return this.checkInstall(this.appsService.currentApp.id);
}
......@@ -103,17 +104,6 @@ export class AppDetailComponent implements OnInit {
return false;
}
install(id) {
let uri = this.appsService.searchApp(id).download[process.platform];
$('#install-modal').modal('hide');
if (uri) {
this.appsService.download(id, uri);
} else {
console.log("lost download uri!");
}
}
uninstalling: boolean;
uninstall(id: string) {
......@@ -127,14 +117,9 @@ export class AppDetailComponent implements OnInit {
}
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);
// }
// }
install() {
$('#install-modal').modal('hide');
this.appsService.download();
}
selectDir() {
......
......@@ -23,8 +23,8 @@ import {AppLocal} from "./app-local";
export class App {
id: string;
name: {[locale: string]: string}; // i18n
description: {[locale: string]: string}; //i18n
name: string; // i18n
description: string; //i18n
author: string; // English Only
homepage: string;
category: string;
......@@ -55,6 +55,7 @@ export class App {
this.version = app.version;
this.local = app.local;
}
}
export interface AppInterface extends App {
......
<span *ngIf="grouped_apps.installed.length">已安装</span>
<ul *ngIf="grouped_apps.installed" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.installed" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.yugioh.length">游戏王</span>
<ul *ngIf="grouped_apps.yugioh" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.yugioh" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.touhou.length">东方 Project</span>
<ul *ngIf="grouped_apps.touhou" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.touhou_pc98.length">东方旧作</span>
<ul *ngIf="grouped_apps.touhou_pc98" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou_pc98" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name[app.locales[0]]}}</a>
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
\ No newline at end of file
......@@ -19,6 +19,7 @@ const execFile = window['System']._nodeRequire('child_process').execFile;
export class AppsService {
installConfig: InstallConfig;
private _currentApp: App;
get currentApp(): App {
......@@ -29,7 +30,7 @@ export class AppsService {
this._currentApp = app;
}
constructor(private http: Http, private translate: TranslateService, private settings: SettingsService) {
constructor(private http: Http, private translate: TranslateService, private settingsService: SettingsService) {
let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=> {
if (res) {
......@@ -97,7 +98,7 @@ export class AppsService {
let tarObj = {
id: this.downloadsInfo[index].id,
xzFile: res.files[0].path,
installDir: this.installConfig.installDir
installDir: this.installConfig.installPath
};
let promise = new Promise((resolve, reject)=> {
let refs = this.searchApp(this.downloadsInfo[index].id).references;
......@@ -186,8 +187,6 @@ export class AppsService {
.map(response => {
let apps = response.json();
let localAppData = JSON.parse(localStorage.getItem("localAppData"));
console.log("app:", apps);
console.log("store:", localAppData);
apps = apps.map((app)=> {
if (localAppData) {
localAppData.map((v)=> {
......@@ -198,12 +197,9 @@ export class AppsService {
}
return app;
});
return apps;
}).map(this.loadApps)
.subscribe((apps) => {
console.log(apps);
this.data = apps;
if (typeof(callback) === 'function') {
callback();
......@@ -211,15 +207,34 @@ export class AppsService {
});
}
loadApps(data: any): Map<string,App> {
getLocalString(app: App, tag: string): string {
let locale = this.settingsService.getLocale();
let value = app[tag][locale];
if (!value) {
value = app[tag]["en-US"];
}
return value;
}
loadApps = (data: any): Map<string,App> => {
let result = new Map<string,App>();
let locale = this.settingsService.getLocale();
for (let item of data) {
let id = item["id"];
['name', 'description'].forEach((key, index)=> {
let value = item[key][locale];
if (!value) {
value = item[key]["en-US"];
}
item[key] = value;
});
let app = new App(item);
result.set(id, app);
}
return result;
}
};
searchApp(id): App {
return this.data.get(id);
......@@ -273,13 +288,16 @@ export class AppsService {
}
download(id, uri) {
download() {
let id = this.currentApp.id;
if (this.downloadsInfo.findIndex((v)=> {
return v.id == id
}) !== -1) {
console.log("this app is downloading")
} else {
this.aria2.addUri([uri], {'dir': this.download_dir}, (error, gid)=> {
let url = this.currentApp.download[process.platform];
this.aria2.addUri([url], {'dir': this.download_dir}, (error, gid)=> {
console.log(error, gid);
if (error) {
console.error(error);
}
......@@ -297,11 +315,10 @@ export class AppsService {
return info;
}
installConfig;
getInstallConfig(app: App): InstallConfig {
let id = app.id;
let installConfig = new InstallConfig(app);
this.installConfig = new InstallConfig(app);
let platform = process.platform;
let references: InstallConfig[] = [];
if (app.references[platform]) {
......@@ -309,36 +326,10 @@ export class AppsService {
// references.push();
// });
}
installConfig.references = references;
return installConfig;
this.installConfig.references = references;
return this.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 = [];
......@@ -444,6 +435,7 @@ export class AppsService {
// 为了卸载时能重新显示安装条
this.downloadsInfo.splice(downLoadsInfoIndex, 1);
this.data.get(tarObj.id).local = appLocal.local;
console.log(11111, this.data.get(tarObj.id), appLocal);
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
this.waitInstallQueue = this.waitInstallQueue.map((waitObj)=> {
......@@ -481,7 +473,7 @@ export class AppsService {
return !0
}
browse(id) {
electron.remote.shell.showItemInFolder(this.searchApp(id).local.path);
browse(app: App) {
electron.remote.shell.showItemInFolder(app.local.path);
}
}
......@@ -7,7 +7,7 @@ import {Injectable} from "@angular/core";
export class SettingsService {
static SETTING_LIBRARY = "library";
libraries: [{selected: boolean,path: string}];
libraries: [{"default": boolean,path: string}];
getLibraries() {
if (!this.libraries) {
......@@ -21,7 +21,7 @@ export class SettingsService {
if (!this.libraries) {
this.getLibraries()
}
return this.libraries.find((item)=>item.selected === true);
return this.libraries.find((item)=>item.default === true);
}
static SETTING_LOCALE = "locale";
......
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