Commit f343473e authored by 神楽坂玲奈's avatar 神楽坂玲奈

Merge branch 'v3' of github.com:mycard/mycard into v3

parents e770e834 6d8cb676
......@@ -4,7 +4,7 @@
/dist/
/cache/
/typings/
/npm-debug.log
/npm-debug.log*
/.idea/
.DS_Store
Thumbs.db
......@@ -42,7 +42,9 @@ export class AppDetailComponent implements OnInit {
};
get isInstalled() {
return this.checkInstall(this.appsService.currentApp.id);
let currentApp=this.appsService.currentApp;
return !!(currentApp.local && currentApp.local.path);
}
......@@ -93,17 +95,6 @@ export class AppDetailComponent implements OnInit {
}
}
checkInstall(id): boolean {
if (this.appsService.searchApp(id)) {
let local = this.appsService.searchApp(id).local;
if (local && local.path) {
return true;
}
}
return false;
}
uninstalling: boolean;
uninstall(id: string) {
......@@ -141,8 +132,7 @@ export class AppDetailComponent implements OnInit {
let open = '';
let openId = app.actions[process.platform]["main"].open;
if (openId) {
//this.appsService.searchApp(openId).actions[process.platform]["main"].execute;
if (this.checkInstall(openId)) {
if (this.isInstalled) {
open = this.path.join(this.appsService.searchApp(openId).local.path, this.appsService.searchApp(openId).actions[process.platform]["main"].execute);
args.push(execute);
} else {
......
......@@ -29,7 +29,7 @@ export class App {
homepage: string;
category: string;
parent: App;
actions: {[platform: string]: {[action: string]: {execute: string, args: string[], env: {}, open: string}}};
actions: {[action: string]: {execute: string, args: string[], env: {}, open: App}};
references: Map<string,App>;
dependencies: Map<string,App>;
locales: string[];
......@@ -39,7 +39,7 @@ export class App {
version: {[platform: string]: string};
local: AppLocal;
constructor(app: AppInterface) {
constructor(app) {
this.id = app.id;
this.name = app.name;
this.description = app.description;
......@@ -47,6 +47,8 @@ export class App {
this.homepage = app.homepage;
this.category = app.category;
this.actions = app.actions;
this.dependencies = app.dependencies;
this.parent = app.parent;
this.references = app.references;
this.locales = app.locales;
this.download = app.download;
......@@ -58,13 +60,3 @@ export class App {
}
export interface AppInterface extends App {
}
/*export interface TestInterface {
id: string;
name: {[locale: string]: string};
}
let test: TestInterface = <TestInterface>{id: '1', name: {"x": "Guy"}};
console.log(test)*/
\ No newline at end of file
import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
import "rxjs/Rx";
import {App} from "./app";
import {TranslateService} from "ng2-translate";
import {InstallConfig} from "./install-config";
import {SettingsService} from "./settings.sevices";
......@@ -37,7 +35,6 @@ sudo.fork = function (modulePath, args, options) {
@Injectable()
export class AppsService {
installConfig: InstallConfig;
private _currentApp: App;
......@@ -49,23 +46,8 @@ export class AppsService {
this._currentApp = app;
}
constructor(private http: Http, private translate: TranslateService, private settingsService: SettingsService) {
let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=> {
if (res) {
res.map((v)=> {
let index = this.downloadsInfo.findIndex((info)=> {
return info.gid == v.gid;
});
this.downloadsInfo[index].progress = (v.completedLength / v.totalLength) * 100;
});
}
})
}, 1000);
this.getApps(()=> {
//console.log(appsService.data)
constructor(private http: Http, private settingsService: SettingsService) {
this.loadApps(()=> {
if (this.data.size > 0) {
this.currentApp = this.data.get('ygopro');
}
......@@ -201,7 +183,7 @@ export class AppsService {
return dir;
}
getApps(callback) {
loadApps(callback) {
this.http.get('./apps.json')
.map(response => {
let apps = response.json();
......@@ -217,7 +199,7 @@ export class AppsService {
return app;
});
return apps;
}).map(this.loadApps)
}).map(this.loadAppsList)
.subscribe((apps) => {
this.data = apps;
if (typeof(callback) === 'function') {
......@@ -235,24 +217,55 @@ export class AppsService {
return value;
}
loadApps = (data: any): Map<string,App> => {
let result = new Map<string,App>();
loadAppsList = (data: any): Map<string,App> => {
let apps = new Map<string,App>();
let locale = this.settingsService.getLocale();
let platform = process.platform;
for (let item of data) {
let id = item["id"];
['name', 'description'].forEach((key, index)=> {
let value = item[key][locale];
let app = new App(item);
// 去除无关语言
['name', 'description'].forEach((key)=> {
let value = app[key][locale];
if (!value) {
value = item[key]["en-US"];
value = app[key]["en-US"];
}
item[key] = value;
app[key] = value;
});
let app = new App(item);
result.set(id, app);
// 去除平台无关的内容
['actions', 'dependencies', 'references', 'download'].forEach((key)=> {
if (app[key]) {
if (app[key][platform]) {
app[key] = app[key][platform];
}
else {
app[key] = null;
}
}
});
apps.set(item.id, app);
}
for (let id of Array.from(apps.keys())) {
['dependencies', 'references', 'parent'].forEach((key)=> {
let app = apps.get(id);
let value = app[key];
if (value) {
if (Array.isArray(value)) {
value.forEach((appId, index, array)=> {
array[index] = apps.get(appId);
})
} else {
app[key] = apps.get(value);
}
}
});
}
return result;
return apps;
};
searchApp(id): App {
......
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