Commit bbec5216 authored by h3remi7's avatar h3remi7

merge commit

parent e549a400
......@@ -2,6 +2,7 @@
/app/*.js.map
/node_modules/
/dist/
/cache/
/typings/
/npm-debug.log
/.idea/
......
......@@ -15,3 +15,8 @@
padding: 0;
}
progress {
margin: 0;
margin-top: 2px;
}
......@@ -55,7 +55,12 @@
<td>{{searchApp(mod.id).name[searchApp(mod.id).locales[0]]}}</td>
<td>{{mod.type}}</td>
<td *ngIf="checkInstall(mod.id)"><button type="button" class="btn btn-danger btn-sm">卸载</button></td>
<td *ngIf="!checkInstall(mod.id)"><button (click)="install()" type="button" class="btn btn-primary btn-sm">安装</button></td>
<td *ngIf="!checkInstall(mod.id)">
<button (click)="install(mod.id)" type="button" class="btn btn-primary btn-sm">安装</button>
<progress class="progress progress-striped progress-animated" value="25" max="100"></progress>
{{appsService.getDownloadStatus(mod.id) | json}}
{{appsService.downloads_info | json}}
</td>
</tr>
</tbody>
</table>
......
import { Component } from '@angular/core';
import { AppsService } from './apps.service'
import { AppService } from './app.service'
import { RoutingService } from './routing.service'
import {App} from "./app";
......@@ -13,7 +12,7 @@ declare var process;
})
export class AppDetailComponent {
constructor(private appsService: AppsService, private appService: AppService, private routingService: RoutingService ) {
constructor(private appsService: AppsService, private routingService: RoutingService ) {
}
_currentApp;
get currentApp(): App {
......@@ -103,8 +102,11 @@ export class AppDetailComponent {
return false;
}
install() {
this.appService.download();
install(id) {
let uri = this.searchApp(id).download;
if(uri) {
this.appsService.download(id, uri);
}
}
......
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/Rx';
import {AppLocal} from "./app-local";
// declare var System;
@Injectable()
export class AppService {
Aria2 = window['System']._nodeRequire('aria2');
constructor(private http: Http) {
}
download() {
const aria2 = new this.Aria2();
console.log(aria2);
aria2.open(()=>{
//aria2.addUri(['http://thief.mycard.moe/metalinks/th13.meta4']);
})
}
}
......@@ -6,10 +6,38 @@ import {AppLocal} from "./app-local";
@Injectable()
export class AppsService {
constructor(private http: Http) {
let cc = "abdas19238d";
this.downloads_info[cc] = 1;
}
fs = window['System']._nodeRequire('fs');
path = window['System']._nodeRequire('path');
mkdirp = window['System']._nodeRequire('mkdirp');
electron = window['System']._nodeRequire('electron');
Aria2 = window['System']._nodeRequire('aria2');
data : App[];
downloads_info = {};
constructor(private http: Http) {
_download_dir;
get download_dir() {
const dir = this.path.join(this.electron.remote.app.getAppPath(), 'cache');
if(!this.fs.existsSync(dir)) {
console.log('cache not exists');
this.mkdirp(dir, (err)=>{
if(err) {
console.error(err)
} else {
console.log('create cache dir');
}
});
}
return dir;
}
getApps(callback) {
......@@ -26,5 +54,50 @@ export class AppsService {
});
}
download(id, uri) {
const aria2 = new this.Aria2();
console.log(id);
console.log(uri);
let tmp_gid;
aria2.open().then(()=>{
aria2.addUri([uri], {'dir': this.download_dir}, (error, gid)=> {
if(error) {
console.error(error);
}
console.log(gid);
tmp_gid = gid;
});
});
aria2.onDownloadComplete = (response)=>{
console.log(response);
aria2.tellStatus(tmp_gid, (err, res)=>{
if(res.followedBy) {
this.downloads_info[id] = res.followedBy[0];
}
console.log(res);
});
};
}
getDownloadStatus(id) {
let gid = this.downloads_info[id];
console.log(this.downloads_info);
let info = {};
const aria2 = new this.Aria2();
aria2.tellStatus(gid, (err, res)=>{
console.log(res);
info = res;
});
return info;
}
}
......@@ -14,13 +14,12 @@ import {CommunityComponent} from './community.component';
import {RoutingService} from './routing.service';
import {AppsService} from './apps.service';
import {AppService} from './app.service';
@NgModule({
imports: [BrowserModule, HttpModule],
declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent],
bootstrap: [MyCardComponent],
providers: [RoutingService, AppsService, AppService],
providers: [RoutingService, AppsService],
schemas: [NO_ERRORS_SCHEMA]
})
export class MyCard {
......
......@@ -24,7 +24,7 @@
"locales": [
"zh-CN"
],
"download": "",
"download": "http://thief.mycard.moe/metalinks/th13.meta4",
"news": [
{
"title": "News Title",
......
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