Commit c8512fac authored by h3remi7's avatar h3remi7

add mods download

parent 9dcfbadf
<h1>{{'app.' + currentApp.id + '.name' | translate}}</h1> <h1>{{'app.' + currentApp.id + '.name' | translate}}</h1>
<h2>{{appsService._aa}}</h2> <h2>{{appsService._aa}}</h2>
<div *ngIf="!isInstalled"> <div *ngIf="!isInstalled">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#install-modal">安装</button> <div *ngIf="!appsService.getDownloadInfo(routingService.app)">
<button type="button" class="btn btn-secondary">导入</button> <button type="button" 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>
</div>
<div *ngIf="appsService.getDownloadInfo(routingService.app)">
<progress *ngIf="appsService.getDownloadInfo(routingService.app).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress>
</div>
</div> </div>
<div *ngIf="isInstalled"> <div *ngIf="isInstalled">
<button type="button" class="btn btn-primary">运行</button> <button type="button" class="btn btn-primary">运行</button>
...@@ -57,16 +62,19 @@ ...@@ -57,16 +62,19 @@
<td *ngIf="checkInstall(mod.id)"> <td *ngIf="checkInstall(mod.id)">
<button type="button" class="btn btn-danger btn-sm">卸载</button></td> <button type="button" class="btn btn-danger btn-sm">卸载</button></td>
<td *ngIf="!checkInstall(mod.id)"> <td *ngIf="!checkInstall(mod.id)">
<button (click)="install(mod.id)" type="button" class="btn btn-primary btn-sm">安装</button> <button *ngIf="!appsService.getDownloadInfo(mod.id)" (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> <progress *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'" class="progress progress-striped progress-animated" value="{{appsService.getDownloadInfo(mod.id).progress}}" max="100"></progress>
{{appsService.getDownloadStatus(mod.id) | json}}
{{appsService.downloads_info | json}}
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<!== DEBUG -->
<pre class="debug">
{{appsService.downloadsInfo | json}}
</pre>
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" <div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true"> aria-hidden="true">
...@@ -106,7 +114,7 @@ ...@@ -106,7 +114,7 @@
<h4>附加内容</h4> <h4>附加内容</h4>
<div *ngFor="let mod of currentApp.references[platform]"> <div *ngFor="let mod of currentApp.references[platform]">
<label> <label>
<input type="checkbox" (ngModel)="__todo__" <input type="checkbox" [(ngModel)]="model" name="{{mod.id}}"
[disabled]="['dependency', 'runtime'].includes(mod.type)"> [disabled]="['dependency', 'runtime'].includes(mod.type)">
{{searchApp(mod.id).name[searchApp(mod.id).locales[0]]}} {{searchApp(mod.id).name[searchApp(mod.id).locales[0]]}}
</label> </label>
...@@ -116,6 +124,7 @@ ...@@ -116,6 +124,7 @@
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary">安装</button> <button type="button" class="btn btn-primary">安装</button>
</div> </div>
<pre>{{model}}</pre>
</form> </form>
</div> </div>
</div> </div>
...@@ -33,6 +33,7 @@ export class AppDetailComponent { ...@@ -33,6 +33,7 @@ export class AppDetailComponent {
return this.checkInstall(this.routingService.app); return this.checkInstall(this.routingService.app);
} }
_news; _news;
get news() { get news() {
if(this.currentApp) { if(this.currentApp) {
...@@ -112,4 +113,6 @@ export class AppDetailComponent { ...@@ -112,4 +113,6 @@ export class AppDetailComponent {
} }
model;
} }
...@@ -12,7 +12,18 @@ export class AppsService { ...@@ -12,7 +12,18 @@ export class AppsService {
let loop = setInterval(()=> { let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=> { this.aria2.tellActive().then((res)=> {
console.log('res:', res); console.log('res:', res);
this.downloadsInfo = 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;
});
}
//this.downloadsInfo = res;
}) })
}, 1000); }, 1000);
...@@ -25,7 +36,9 @@ export class AppsService { ...@@ -25,7 +36,9 @@ export class AppsService {
Aria2 = window['System']._nodeRequire('aria2'); Aria2 = window['System']._nodeRequire('aria2');
data: App[]; data: App[];
downloadsInfo = {};
//[{"id": "th01", "gid": "aria2gid", "status": "active/install/complete/wait", "progress": "0-100"}]
downloadsInfo = [];
aria2IsOpen = false; aria2IsOpen = false;
...@@ -45,12 +58,21 @@ export class AppsService { ...@@ -45,12 +58,21 @@ export class AppsService {
}; };
this._aria2.onDownloadComplete = (response)=> { this._aria2.onDownloadComplete = (response)=> {
console.log(response); console.log(response);
//aria2.tellStatus(tmp_gid, (err, res)=>{ this.aria2.tellStatus(response.gid, (err, res)=>{
// if(res.followedBy) { console.log(res);
// this.downloadsInfo[id] = res.followedBy[0]; let index = this.downloadsInfo.findIndex((v)=>{return v.gid == res.gid});
// } if(index !== -1) {
// console.log(res); if(res.followedBy) {
//}); this.downloadsInfo[index].gid = res.followedBy[0];
this.downloadsInfo[index].progress = 0;
} else {
this.downloadsInfo[index].status = "wait";
}
} else {
console.log("cannot found download info!");
}
});
}; };
this._aria2.onmessage = (m)=> { this._aria2.onmessage = (m)=> {
console.log('IN:', m); console.log('IN:', m);
...@@ -117,20 +139,30 @@ export class AppsService { ...@@ -117,20 +139,30 @@ export class AppsService {
console.log(id); console.log(id);
console.log(uri); console.log(uri);
let tmp_gid; let tmp_gid;
this.aria2.addUri([uri], {'dir': this.download_dir}, (error, gid)=> { let i = this.downloadsInfo.findIndex((v)=>{return v.id == id});
if (error) { console.log(i);
console.error(error); if(this.downloadsInfo.findIndex((v)=>{return v.id == id}) !== -1) {
} console.log("this app downloading")
console.log(gid);
tmp_gid = gid; } else {
}); this.aria2.addUri([uri], {'dir': this.download_dir}, (error, gid)=> {
if (error) {
console.error(error);
}
console.log(gid);
this.downloadsInfo.push({"id": id, "gid": gid, "status": "active", "progress": 0});
});
}
}
getDownloadStatus(id) {
let info = {}; }
getDownloadInfo(id) {
let info;
info = this.downloadsInfo.find((v)=>{
return v.id == id;
});
return info; return info;
......
import {NgModule, NO_ERRORS_SCHEMA} from '@angular/core'; import {NgModule, NO_ERRORS_SCHEMA} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http'; import {HttpModule} from '@angular/http';
import {MyCardComponent} from './mycard.component'; import {MyCardComponent} from './mycard.component';
...@@ -18,7 +19,7 @@ import {AppsService} from './apps.service'; ...@@ -18,7 +19,7 @@ import {AppsService} from './apps.service';
import {TranslateModule} from 'ng2-translate/ng2-translate'; import {TranslateModule} from 'ng2-translate/ng2-translate';
@NgModule({ @NgModule({
imports: [BrowserModule, HttpModule, TranslateModule.forRoot()], imports: [BrowserModule, FormsModule, HttpModule, TranslateModule.forRoot()],
declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent], declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent],
bootstrap: [MyCardComponent], bootstrap: [MyCardComponent],
providers: [RoutingService, AppsService], providers: [RoutingService, AppsService],
......
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