Commit 3bdfcb80 authored by wudizhanche1000's avatar wudizhanche1000

添加卸载

parent 6c86bc5d
......@@ -17,7 +17,7 @@
</div>
<div *ngIf="isInstalled">
<button (click)="startApp(routingService.app)" type="button" class="btn btn-primary">运行</button>
<button type="button" class="btn btn-secondary">设置</button>
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#settings-modal">设置</button>
<button (click)="openDir(routingService.app)" type="button" class="btn btn-secondary">游览本地文件</button>
<button type="button" class="btn btn-secondary">联机</button>
</div>
......@@ -65,12 +65,22 @@
<td>{{'app.' + mod.id + '.name' | translate}}</td>
<td>{{mod.type}}</td>
<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)">
<button *ngIf="!appsService.getDownloadInfo(mod.id)" (click)="install(mod.id)" type="button" class="btn btn-primary btn-sm">安装</button>
<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>
<div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'wait'">等待安装...</div>
<div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'install'">正在安装...</div>
<button *ngIf="!appsService.getDownloadInfo(mod.id)" (click)="install(mod.id)" type="button"
class="btn btn-primary btn-sm">安装
</button>
<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>
<div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'wait'">
等待安装...
</div>
<div *ngIf="appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'install'">
正在安装...
</div>
</td>
</tr>
</tbody>
......@@ -84,13 +94,60 @@
{{appsService.tarQueue | json}}
{{appsService.waitInstallQueue | json}}
</pre>
<button (click)="appsService.doTar()" >DOTAR</button>
<button (click)="appsService.doTar()">DOTAR</button>
<div class="modal fade" id="settings-modal" tabindex="-1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<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">{{'settings'|translate}}</h4>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#general">
{{'general'|translate}}
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#updates">
{{'updates'|translate}}
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#local-files">
{{'local files'|translate}}
</a>
</li>
</ul>
</div>
<div class="modal-body">
<div class="tab-content">
<div id="general" role="tabpanel" class="tab-pane fade active">
</div>
<div id="updates" role="tabpanel" class="tab-pane fade">
</div>
<div id="local-files" role="tabpanel" class="tab-pane fade">
<button type="button" (click)="uninstall()">
{{'uninstall'|translate}}
</button>
</div>
</div>
</div>
<div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="install-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<form class="modal-content" (ngSubmit)="installSubmit(theForm)" #theForm="ngForm">
<form id="install-form" class="modal-content" (ngSubmit)="installSubmit(theForm)" #theForm="ngForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
......@@ -103,7 +160,8 @@
<h4>安装位置</h4>
<div class="form-group">
<div class="input-group">
<input type="text" [(ngModel)]="appsService.installConfig.installDir" name="installDir" class="form-control" placeholder="安装位置">
<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>
......@@ -112,7 +170,8 @@
<h4>快捷方式</h4>
<div class="checkbox">
<label>
<input type="checkbox" [(ngModel)]="appsService.installConfig.shortcut.application" name="application">
<input type="checkbox" [(ngModel)]="appsService.installConfig.shortcut.application"
name="application">
创建应用程序快捷方式
</label>
</div>
......@@ -133,10 +192,12 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="submit" [disabled]="!theForm.form.valid" class="btn btn-primary">安装</button>
<button id="submit" type="submit" [disabled]="!theForm.form.valid" class="btn btn-primary">安装</button>
</div>
<!--
-->
</form>
</div>
</div>
......@@ -5,7 +5,6 @@ import {App} from "./app";
declare var process;
declare var $;
@Component({
selector: 'app-detail',
templateUrl: 'app/app-detail.component.html',
......@@ -105,13 +104,18 @@ export class AppDetailComponent {
install(id) {
let uri = this.appsService.searchApp(id).download[process.platform];
console.log(process.platform);
$('#install-modal').modal('hide');
if (uri) {
this.appsService.download(id, uri);
} else {
console.log("lost download uri!");
}
}
uninstall(id: string) {
id = this.currentApp.id;
this.appsService.uninstall(id);
}
......@@ -123,8 +127,6 @@ export class AppDetailComponent {
this.install(mod);
}
}
$("#install-modal").modal("hide");
}
selectDir() {
......
......@@ -13,19 +13,15 @@ export class AppsService {
constructor(private http: Http, private translate: TranslateService) {
let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=> {
//console.log('res:', res);
if(res) {
res.map((v)=>{
let index = this.downloadsInfo.findIndex((info)=>{
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);
......@@ -67,12 +63,13 @@ export class AppsService {
this.aria2IsOpen = false;
};
this._aria2.onDownloadComplete = (response)=> {
console.log(response);
this._aria2.tellStatus(response.gid, (err, res)=>{
console.log(res);
let index = this.downloadsInfo.findIndex((v)=>{return v.gid == res.gid});
if(index !== -1) {
if(res.followedBy) {
console.log("download response: ", response);
this._aria2.tellStatus(response.gid, (err, res)=> {
let index = this.downloadsInfo.findIndex((v)=> {
return v.gid == res.gid
});
if (index !== -1) {
if (res.followedBy) {
this.downloadsInfo[index].gid = res.followedBy[0];
this.downloadsInfo[index].progress = 0;
......@@ -80,21 +77,21 @@ export class AppsService {
this.downloadsInfo[index].status = "wait";
let tarObj = {
id: this.downloadsInfo[index].id,
xzFile: res.files[0].path,
installDir: this.installConfig.installDir
xzFile: res.files[0].path,
installDir: this.installConfig.installDir
};
let promise = new Promise((resolve, reject)=>{
let promise = new Promise((resolve, reject)=> {
let refs = this.searchApp(this.downloadsInfo[index].id).references;
console.log(refs);
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
let waitObj;
let waitRef = ["runtime", "emulator", "dependency"];
if(!this.isEmptyObject(refs)) {
refs[process.platform].map((ref)=>{
if(waitRef.includes(ref.type)) {
if(!this.checkInstall(ref.id)) {
if(!waitObj) {
if (!this.isEmptyObject(refs)) {
refs[process.platform].map((ref)=> {
if (waitRef.includes(ref.type)) {
if (!this.checkInstall(ref.id)) {
if (!waitObj) {
waitObj = {
id: this.downloadsInfo[index].id,
wait: [ref.id],
......@@ -110,17 +107,17 @@ export class AppsService {
}
console.log("wait obj:", waitObj);
if(waitObj) {
if (waitObj) {
this.waitInstallQueue.push(waitObj);
} else {
resolve();
}
}).then(()=>{
}).then(()=> {
console.log(tarObj);
this.tarPush(tarObj);
});
promise.catch((err)=>{
promise.catch((err)=> {
console.log("err", err);
})
}
......@@ -170,12 +167,12 @@ 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)=>{
if(v.id == app.id) {
console.log("app:", apps);
console.log("store:", localAppData);
apps = apps.map((app)=> {
if (localAppData) {
localAppData.map((v)=> {
if (v.id == app.id) {
app.local = v.local;
}
});
......@@ -191,7 +188,9 @@ export class AppsService {
for (let app of data) {
//console.log(app)
for (let attribute of ['name', 'description']) {
if(!app[attribute]){continue} //这句应当是不需要的, 如果转换成了 App 类型, 应当保证一定有这些属性
if (!app[attribute]) {
continue
} //这句应当是不需要的, 如果转换成了 App 类型, 应当保证一定有这些属性
for (let locale of Object.keys(app[attribute])) {
let result = {};
result[`app.${app['id']}.${attribute}`] = app[attribute][locale];
......@@ -210,44 +209,59 @@ export class AppsService {
searchApp(id): App {
let data = this.data;
let tmp;
if(data) {
if (data) {
tmp = data.find((v)=>v.id === id);
return tmp;
}
}
checkInstall(id): boolean {
if(this.searchApp(id)) {
if(this.searchApp(id).local.path) {
if (this.searchApp(id)) {
if (this.searchApp(id).local.path) {
return true;
}
}
return false;
}
download(id, uri) {
//console.log(id);
//console.log(uri);
//console.log(i);
if(this.downloadsInfo.findIndex((v)=>{return v.id == id}) !== -1) {
console.log("this app downloading")
deleteFile(path: string) {
return new Promise((resolve, reject)=> {
this.fs.unlink(path, (err)=> {
resolve(path);
});
});
}
uninstall(id) {
if (this.checkInstall(id)) {
let files = this.searchApp(id).local.files.sort().reverse();
files.reduce((pre, curr, index, arr)=> {
this.deleteFile(curr).then((path)=> {
console.log("delete ", path)
});
return "1"
})
}
}
download(id, uri) {
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)=> {
if (error) {
console.error(error);
}
//console.log(gid);
this.downloadsInfo.push({"id": id, "gid": gid, "status": "active", "progress": 0});
});
}
}
getDownloadInfo(id) {
let info;
info = this.downloadsInfo.find((v)=>{
info = this.downloadsInfo.find((v)=> {
return v.id == id;
});
......@@ -255,12 +269,15 @@ export class AppsService {
}
installConfig;
createInstallConfig(id) {
let app = this.data.find((app)=>{return app.id == 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)=>{
if (app.references[platform]) {
app.references[platform].map((mod)=> {
mods[mod.id] = false;
});
......@@ -287,11 +304,10 @@ export class AppsService {
tarPush(tarObj) {
this.tarQueue.push(tarObj);
if(this.tarQueue.length > 0 && !this.isExtracting) {
if (this.tarQueue.length > 0 && !this.isExtracting) {
this.doTar();
}
}
doTar() {
......@@ -306,11 +322,10 @@ export class AppsService {
default:
throw 'unsupported platform';
}
let opt = {
};
let opt = {};
let tarObj;
if(this.tarQueue.length > 0) {
if (this.tarQueue.length > 0) {
tarObj = this.tarQueue[0];
} else {
console.log("Empty Queue!");
......@@ -321,16 +336,16 @@ export class AppsService {
this.isExtracting = true;
console.log("Start tar " + tarObj.id);
let downLoadsInfoIndex = this.downloadsInfo.findIndex((v)=>{return v.id == tarObj.id});
if(downLoadsInfoIndex !== -1) {
let downLoadsInfoIndex = this.downloadsInfo.findIndex((v)=> {
return v.id == tarObj.id
});
if (downLoadsInfoIndex !== -1) {
this.downloadsInfo[downLoadsInfoIndex].status = "install";
} else {
console.log("cannot found download info!");
}
let xzFile = tarObj.xzFile;
let installDir = this.path.join(tarObj.installDir, tarObj.id);
if (!this.fs.existsSync(installDir)) {
......@@ -344,21 +359,15 @@ export class AppsService {
});
}
let tar = this.execFile(tarPath, ['xvf', xzFile, '-C', installDir], opt, (err, stdout, stderr)=>{
if(err) {
let tar = this.execFile(tarPath, ['xvf', xzFile, '-C', installDir], opt, (err, stdout, stderr)=> {
if (err) {
throw err;
}
let re = /^x\s(.*)/;
let logArr = stderr.toString().trim().split(this.os.EOL);
logArr = logArr.map((v)=>{
if(v.match(re)) {
return v.match(re)[1];
} else {
console.log("no match");
return v;
}
});
let logArr = stderr.toString().trim().split("\n")
.map((log, index, array)=> {
return log.split(" ", 2)[1];
});
let appLocal = {
id: tarObj.id,
......@@ -370,14 +379,14 @@ export class AppsService {
};
let localAppData = JSON.parse(localStorage.getItem("localAppData"));
if(!localAppData || !Array.isArray(localAppData)) {
if (!localAppData || !Array.isArray(localAppData)) {
localAppData = [];
}
let index = localAppData.findIndex((v)=>{
let index = localAppData.findIndex((v)=> {
return v.id == tarObj.id;
});
if(index === -1) {
if (index === -1) {
localAppData.push(appLocal);
} else {
localAppData[index] = appLocal;
......@@ -388,16 +397,16 @@ export class AppsService {
this.isExtracting = false;
this.downloadsInfo[downLoadsInfoIndex].status = "complete";
this.data = this.data.map((app)=>{
if(app.id == tarObj.id) {
this.data = this.data.map((app)=> {
if (app.id == tarObj.id) {
app.local = appLocal.local;
}
return app;
});
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
this.waitInstallQueue = this.waitInstallQueue.map((waitObj)=>{
this.waitInstallQueue = this.waitInstallQueue.map((waitObj)=> {
waitObj.wait.splice(waitObj.wait.findIndex(()=>tarObj.id), 1);
if(waitObj.wait.length <= 0) {
if (waitObj.wait.length <= 0) {
waitObj.resolve();
console.log(tarObj);
return;
......@@ -405,8 +414,8 @@ export class AppsService {
return waitObj;
}
});
this.waitInstallQueue = this.waitInstallQueue.filter((waitObj)=>{
if(waitObj){
this.waitInstallQueue = this.waitInstallQueue.filter((waitObj)=> {
if (waitObj) {
return true;
} else {
return false;
......
{
"library": "游戏",
"community": "社区"
"community": "社区",
"settings": "设置",
"uninstall": "卸载",
"general":"常规",
"updates":"更新",
"local files":"本地文件"
}
......@@ -94,7 +94,7 @@ function createAria2c() {
let aria2c = child_process.spawn(aria2c_path, ['--enable-rpc', '--rpc-allow-origin-all', "--continue", "--split=10", "--min-split-size=1M", "--max-connection-per-server=10"]);
aria2c.on('data', (data)=> {
console.log(data);
})
});
return aria2c;
}
......
......@@ -10,6 +10,7 @@
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
'ng2-translate': 'node_modules/ng2-translate/bundles/ng2-translate.js',
"os":''
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
......
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