Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
syntax_j
mycard
Commits
6a4f6518
Commit
6a4f6518
authored
Nov 04, 2016
by
wudizhanche1000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
安装完成更新界面
parent
32be85f0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
291 deletions
+20
-291
app/app-detail.component.ts
app/app-detail.component.ts
+9
-3
app/app-local.ts
app/app-local.ts
+2
-0
app/apps.service.ts
app/apps.service.ts
+0
-286
app/install.service.ts
app/install.service.ts
+9
-2
No files found.
app/app-detail.component.ts
View file @
6a4f6518
...
...
@@ -136,9 +136,11 @@ export class AppDetailComponent implements OnInit {
(
error
)
=>
{
},
()
=>
{
// 避免安装过快
if
(
currentApp
.
status
.
status
===
"
downloading
"
)
{
currentApp
.
status
.
status
=
"
waiting
"
;
this
.
ref
.
detectChanges
();
}
});
await
Promise
.
all
(
downloadApps
.
map
((
app
)
=>
{
return
this
.
downloadService
.
getComplete
(
app
)
...
...
@@ -146,7 +148,11 @@ export class AppDetailComponent implements OnInit {
return
this
.
installService
.
add
(
completeApp
,
options
);
});
}));
console
.
log
(
"
before
"
)
await
this
.
installService
.
getComplete
(
currentApp
);
console
.
log
(
"
install complete
"
);
currentApp
.
status
.
status
=
"
ready
"
;
this
.
ref
.
detectChanges
();
}
catch
(
e
)
{
new
Notification
(
currentApp
.
name
,
{
body
:
"
下载失败
"
});
}
...
...
app/app-local.ts
View file @
6a4f6518
import
{
App
}
from
"
./app
"
;
/**
* Created by zh99998 on 16/9/6.
*/
...
...
@@ -5,6 +6,7 @@ export class AppLocal {
path
:
string
;
version
:
string
;
files
:
Map
<
string
,
string
>
;
action
:
Map
<
string
,{
execute
:
string
,
args
:
string
[],
env
:
{},
open
:
App
}
>
;
update
(
local
)
{
this
.
path
=
local
.
path
;
...
...
app/apps.service.ts
View file @
6a4f6518
...
...
@@ -39,134 +39,6 @@ export class AppsService {
}
// get allApps(): Map<string,App> {
// return this.data;
// }
//[{"id": "th01", "gid": "aria2gid", "status": "active/install/complete/wait", "progress": "0-100"}]
downloadsInfo
=
[];
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
// th01
waitInstallQueue
=
[];
aria2IsOpen
=
false
;
_aria2
;
get
aria2
()
{
if
(
!
this
.
_aria2
)
{
this
.
_aria2
=
new
Aria2
();
console
.
log
(
"
new aria2
"
);
this
.
_aria2
.
onopen
=
()
=>
{
console
.
log
(
'
aria2 open
'
);
};
this
.
_aria2
.
onclose
=
()
=>
{
console
.
log
(
'
aria2 close
'
);
this
.
aria2IsOpen
=
false
;
};
this
.
_aria2
.
onDownloadComplete
=
(
response
)
=>
{
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
;
}
else
{
this
.
downloadsInfo
[
index
].
status
=
"
wait
"
;
let
tarObj
=
{
id
:
this
.
downloadsInfo
[
index
].
id
,
xzFile
:
res
.
files
[
0
].
path
,
// installDir: this.installConfig.installLibrary
};
new
Promise
((
resolve
)
=>
{
// let refs = this.searchApp(this.downloadsInfo[index].id).references;
// console.log(refs);
//[{"id": "th01", "wait":["wine", "dx"], resolve: resolve, tarObj: tarObj}]
let
waitObj
;
// TODO 重写依赖的安装
// 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) {
// waitObj = {
// id: this.downloadsInfo[index].id,
// wait: [ref.id],
// resolve: resolve,
// tarObj: tarObj
// }
// } else {
// waitObj.wait.push(ref.id);
// }
// }
// }
// });
// }
// console.log("wait obj:", waitObj);
if
(
waitObj
)
{
this
.
waitInstallQueue
.
push
(
waitObj
);
}
else
{
resolve
();
}
}).
then
(()
=>
{
console
.
log
(
tarObj
);
this
.
tarPush
(
tarObj
);
});
// promise.catch((err)=> {
// err.printt
// })
}
}
else
{
console
.
log
(
"
cannot found download info!
"
);
}
});
};
//this._aria2.onmessage = (m)=> {
//console.log('IN:', m);
//console.log('download infoi:', this.downloadsInfo);
//}
}
if
(
!
this
.
aria2IsOpen
)
{
this
.
_aria2
.
open
().
then
(()
=>
{
console
.
log
(
'
aria2 websocket open
'
);
this
.
aria2IsOpen
=
true
;
});
}
return
this
.
_aria2
;
}
//_download_dir;
get
download_dir
()
{
const
dir
=
path
.
join
(
remote
.
app
.
getAppPath
(),
'
cache
'
);
if
(
!
fs
.
existsSync
(
dir
))
{
console
.
log
(
'
cache not exists
'
);
mkdirp
(
dir
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
)
}
else
{
console
.
log
(
'
create cache dir
'
);
}
});
}
return
dir
;
}
loadApps
()
{
return
this
.
http
.
get
(
'
./apps.json
'
)
.
toPromise
()
...
...
@@ -300,164 +172,6 @@ export class AppsService {
}
download
()
{
// let id = this.currentApp.id;
// if (this.downloadsInfo.findIndex((v)=> {
// return v.id == id
// }) !== -1) {
// console.log("this app is downloading")
// } else {
// let url = this.currentApp.download;
// this.aria2.addUri([url], {'dir': this.download_dir}, (error, gid)=> {
// console.log(error, gid);
// if (error) {
// console.error(error);
// }
// this.downloadsInfo.push({"id": id, "gid": gid, "status": "active", "progress": 0});
// });
// }
}
getDownloadInfo
(
id
)
{
let
info
;
info
=
this
.
downloadsInfo
.
find
((
v
)
=>
{
return
v
.
id
==
id
;
});
return
info
;
}
// tar
tarQueue
=
[];
isExtracting
=
false
;
tarPush
(
tarObj
)
{
this
.
tarQueue
.
push
(
tarObj
);
if
(
this
.
tarQueue
.
length
>
0
&&
!
this
.
isExtracting
)
{
this
.
doTar
();
}
}
doTar
()
{
let
tarPath
;
switch
(
process
.
platform
)
{
case
'
win32
'
:
tarPath
=
path
.
join
(
process
.
execPath
,
'
..
'
,
'
../../../bin/
'
,
'
tar.exe
'
);
break
;
case
'
darwin
'
:
tarPath
=
'
bsdtar
'
;
// for debug
break
;
default
:
throw
'
unsupported platform
'
;
}
let
opt
=
{
maxBuffer
:
20
*
1024
*
1024
};
let
tarObj
;
if
(
this
.
tarQueue
.
length
>
0
)
{
tarObj
=
this
.
tarQueue
[
0
];
}
else
{
console
.
log
(
"
Empty Queue!
"
);
return
;
}
this
.
isExtracting
=
true
;
console
.
log
(
"
Start tar
"
+
tarObj
.
id
);
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
=
path
.
join
(
tarObj
.
installDir
,
tarObj
.
id
);
if
(
!
fs
.
existsSync
(
installDir
))
{
console
.
log
(
'
app dir not exists
'
);
mkdirp
(
installDir
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
)
}
else
{
console
.
log
(
'
create app dir
'
);
}
});
}
let
tar
=
child_process
.
execFile
(
tarPath
,
[
'
xvf
'
,
xzFile
,
'
-C
'
,
installDir
],
opt
,
(
err
,
stdout
,
stderr
)
=>
{
if
(
err
)
{
throw
err
;
}
let
logArr
=
stderr
.
toString
().
trim
().
split
(
"
\n
"
)
.
map
((
log
,
index
,
array
)
=>
{
return
log
.
split
(
"
"
,
2
)[
1
];
});
let
appLocal
=
{
id
:
tarObj
.
id
,
local
:
{
path
:
installDir
,
version
:
"
0.1
"
,
files
:
logArr
}
};
let
localAppData
=
JSON
.
parse
(
localStorage
.
getItem
(
"
localAppData
"
));
if
(
!
localAppData
||
!
Array
.
isArray
(
localAppData
))
{
localAppData
=
[];
}
let
index
=
localAppData
.
findIndex
((
v
)
=>
{
return
v
.
id
==
tarObj
.
id
;
});
if
(
index
===
-
1
)
{
localAppData
.
push
(
appLocal
);
}
else
{
localAppData
[
index
]
=
appLocal
;
}
localStorage
.
setItem
(
"
localAppData
"
,
JSON
.
stringify
(
localAppData
));
let
tmp
=
this
.
tarQueue
.
shift
();
this
.
isExtracting
=
false
;
this
.
downloadsInfo
[
downLoadsInfoIndex
].
status
=
"
complete
"
;
// 为了卸载时能重新显示安装条
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
)
=>
{
waitObj
.
wait
.
splice
(
waitObj
.
wait
.
findIndex
(()
=>
tarObj
.
id
),
1
);
if
(
waitObj
.
wait
.
length
<=
0
)
{
waitObj
.
resolve
();
console
.
log
(
tarObj
);
return
;
}
else
{
return
waitObj
;
}
});
this
.
waitInstallQueue
=
this
.
waitInstallQueue
.
filter
((
waitObj
)
=>
{
return
waitObj
});
console
.
log
(
tmp
);
console
.
log
(
"
this app complete!
"
);
console
.
log
(
localAppData
);
this
.
doTar
();
});
}
browse
(
app
:
App
)
{
remote
.
shell
.
showItemInFolder
(
app
.
local
.
path
);
...
...
app/install.service.ts
View file @
6a4f6518
...
...
@@ -41,7 +41,12 @@ export class InstallService {
}
getComplete
(
app
:
App
):
Promise
<
App
>
{
return
null
;
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
eventEmitter
.
once
(
app
.
id
,
(
complete
)
=>
{
console
.
log
(
"
receive
"
,
app
.
id
);
resolve
();
});
});
}
extract
(
file
:
string
,
destPath
:
string
)
{
...
...
@@ -151,7 +156,6 @@ export class InstallService {
destPath
=
path
.
join
(
options
.
installLibrary
,
app
.
id
);
await
this
.
createDirectory
(
destPath
);
}
this
.
installQueue
.
delete
(
app
);
await
this
.
extract
(
packagePath
,
destPath
);
await
this
.
postInstall
(
app
,
destPath
);
let
local
=
new
AppLocal
();
...
...
@@ -160,6 +164,9 @@ export class InstallService {
local
.
version
=
app
.
version
;
app
.
local
=
local
;
this
.
saveAppLocal
(
app
);
console
.
log
(
"
send
"
,
app
.
id
);
this
.
eventEmitter
.
emit
(
app
.
id
,
'
install complete
'
);
this
.
installQueue
.
delete
(
app
);
this
.
installingQueue
.
delete
(
app
);
if
(
this
.
installQueue
.
size
>
0
)
{
await
this
.
doInstall
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment