Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
moecube
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
JoyJ
moecube
Commits
a349dda6
Commit
a349dda6
authored
Oct 20, 2016
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v3' of github.com:mycard/mycard into v3
parents
f010d597
7e26c85b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
32 deletions
+53
-32
app/app-detail.component.html
app/app-detail.component.html
+1
-1
app/apps.service.ts
app/apps.service.ts
+52
-31
No files found.
app/app-detail.component.html
View file @
a349dda6
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
</div>
</div>
<div
*ngIf=
"isInstalled && (routingService.app != 'ygopro')"
>
<div
*ngIf=
"isInstalled && (routingService.app != 'ygopro')"
>
<button
(click)=
"startApp(routingService.app)"
type=
"button"
class=
"btn btn-primary"
>
运行
</button>
<button
(click)=
"startApp(routingService.app)"
type=
"button"
class=
"btn btn-primary"
>
运行
</button>
<button
type=
"button"
class=
"btn btn-secondary"
>
设置
</button>
<button
type=
"button"
data-toggle=
"modal"
data-target=
"#settings-modal"
class=
"btn btn-secondary"
>
设置
</button>
<button
(click)=
"appsService.browse(routingService.app)"
type=
"button"
class=
"btn btn-secondary"
>
游览本地文件
</button>
<button
(click)=
"appsService.browse(routingService.app)"
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>
...
...
app/apps.service.ts
View file @
a349dda6
...
@@ -4,8 +4,16 @@ import 'rxjs/Rx';
...
@@ -4,8 +4,16 @@ import 'rxjs/Rx';
import
{
App
}
from
"
./app
"
;
import
{
App
}
from
"
./app
"
;
import
{
AppLocal
}
from
"
./app-local
"
;
import
{
AppLocal
}
from
"
./app-local
"
;
import
{
TranslateService
}
from
"
ng2-translate
"
;
import
{
TranslateService
}
from
"
ng2-translate
"
;
import
{
RoutingService
}
from
"
./routing.service
"
;
declare
var
process
;
declare
var
process
;
const
os
=
window
[
'
System
'
].
_nodeRequire
(
'
os
'
);
const
fs
=
window
[
'
System
'
].
_nodeRequire
(
'
fs
'
);
const
path
=
window
[
'
System
'
].
_nodeRequire
(
'
path
'
);
const
mkdirp
=
window
[
'
System
'
].
_nodeRequire
(
'
mkdirp
'
);
const
electron
=
window
[
'
System
'
].
_nodeRequire
(
'
electron
'
);
const
Aria2
=
window
[
'
System
'
].
_nodeRequire
(
'
aria2
'
);
const
execFile
=
window
[
'
System
'
].
_nodeRequire
(
'
child_process
'
).
execFile
;
@
Injectable
()
@
Injectable
()
export
class
AppsService
{
export
class
AppsService
{
...
@@ -27,13 +35,7 @@ export class AppsService {
...
@@ -27,13 +35,7 @@ export class AppsService {
}
}
os
=
window
[
'
System
'
].
_nodeRequire
(
'
os
'
);
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
'
);
execFile
=
window
[
'
System
'
].
_nodeRequire
(
'
child_process
'
).
execFile
;
//localStorage = window['localStorage'];
//localStorage = window['localStorage'];
...
@@ -53,7 +55,7 @@ export class AppsService {
...
@@ -53,7 +55,7 @@ export class AppsService {
_aria2
;
_aria2
;
get
aria2
()
{
get
aria2
()
{
if
(
!
this
.
_aria2
)
{
if
(
!
this
.
_aria2
)
{
this
.
_aria2
=
new
this
.
Aria2
();
this
.
_aria2
=
new
Aria2
();
console
.
log
(
"
new aria2
"
);
console
.
log
(
"
new aria2
"
);
this
.
_aria2
.
onopen
=
()
=>
{
this
.
_aria2
.
onopen
=
()
=>
{
console
.
log
(
'
aria2 open
'
);
console
.
log
(
'
aria2 open
'
);
...
@@ -146,11 +148,11 @@ export class AppsService {
...
@@ -146,11 +148,11 @@ export class AppsService {
_download_dir
;
_download_dir
;
get
download_dir
()
{
get
download_dir
()
{
const
dir
=
this
.
path
.
join
(
this
.
electron
.
remote
.
app
.
getAppPath
(),
'
cache
'
);
const
dir
=
path
.
join
(
electron
.
remote
.
app
.
getAppPath
(),
'
cache
'
);
if
(
!
this
.
fs
.
existsSync
(
dir
))
{
if
(
!
fs
.
existsSync
(
dir
))
{
console
.
log
(
'
cache not exists
'
);
console
.
log
(
'
cache not exists
'
);
this
.
mkdirp
(
dir
,
(
err
)
=>
{
mkdirp
(
dir
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
err
)
console
.
error
(
err
)
}
else
{
}
else
{
...
@@ -224,24 +226,42 @@ export class AppsService {
...
@@ -224,24 +226,42 @@ export class AppsService {
return
false
;
return
false
;
}
}
deleteFile
(
path
:
string
)
{
deleteFile
(
path
:
string
)
:
Promise
<
string
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
fs
.
unlink
(
path
,
(
err
)
=>
{
fs
.
lstat
(
path
,
(
err
,
stats
)
=>
{
resolve
(
path
);
if
(
stats
.
isDirectory
())
{
fs
.
rmdir
(
path
,
(
err
)
=>
{
resolve
(
path
);
});
}
else
{
fs
.
unlink
(
path
,
(
err
)
=>
{
resolve
(
path
);
});
}
});
});
})
;
})
}
}
uninstall
(
id
)
{
uninstall
(
id
:
string
)
{
let
current
=
this
;
if
(
this
.
checkInstall
(
id
))
{
if
(
this
.
checkInstall
(
id
))
{
let
files
=
this
.
searchApp
(
id
).
local
.
files
.
sort
().
reverse
();
let
files
:
string
[]
=
this
.
searchApp
(
id
).
local
.
files
.
sort
().
reverse
();
files
.
reduce
((
pre
,
curr
,
index
,
arr
)
=>
{
// 删除本目录
this
.
deleteFile
(
curr
).
then
((
path
)
=>
{
files
.
push
(
'
.
'
);
console
.
log
(
"
delete
"
,
path
)
let
install_dir
=
this
.
searchApp
(
id
).
local
.
path
;
files
.
map
((
file
)
=>
()
=>
Promise
.
resolve
(
path
.
join
(
install_dir
,
file
))
)
.
reduce
((
promise
:
Promise
<
string
>
,
task
)
=>
promise
.
then
(
task
).
then
(
this
.
deleteFile
)
,
Promise
.
resolve
(
''
))
.
then
((
value
)
=>
{
this
.
searchApp
(
id
).
local
=
null
;
localStorage
.
setItem
(
"
localAppData
"
,
JSON
.
stringify
(
this
.
data
));
});
});
return
"
1
"
})
}
}
}
}
download
(
id
,
uri
)
{
download
(
id
,
uri
)
{
...
@@ -284,7 +304,7 @@ export class AppsService {
...
@@ -284,7 +304,7 @@ export class AppsService {
}
}
let
tmp
=
{
let
tmp
=
{
installDir
:
this
.
path
.
join
(
this
.
electron
.
remote
.
app
.
getPath
(
'
appData
'
),
'
mycard
'
),
installDir
:
path
.
join
(
electron
.
remote
.
app
.
getPath
(
'
appData
'
),
'
mycard
'
),
shortcut
:
{
shortcut
:
{
desktop
:
false
,
desktop
:
false
,
application
:
false
application
:
false
...
@@ -314,7 +334,7 @@ export class AppsService {
...
@@ -314,7 +334,7 @@ export class AppsService {
let
tarPath
;
let
tarPath
;
switch
(
process
.
platform
)
{
switch
(
process
.
platform
)
{
case
'
win32
'
:
case
'
win32
'
:
tarPath
=
this
.
path
.
join
(
process
.
execPath
,
'
..
'
,
'
../../../bin/
'
,
'
tar.exe
'
);
tarPath
=
path
.
join
(
process
.
execPath
,
'
..
'
,
'
../../../bin/
'
,
'
tar.exe
'
);
break
;
break
;
case
'
darwin
'
:
case
'
darwin
'
:
tarPath
=
'
bsdtar
'
;
// for debug
tarPath
=
'
bsdtar
'
;
// for debug
...
@@ -323,7 +343,7 @@ export class AppsService {
...
@@ -323,7 +343,7 @@ export class AppsService {
throw
'
unsupported platform
'
;
throw
'
unsupported platform
'
;
}
}
let
opt
=
{
let
opt
=
{
maxBuffer
:
20
*
1024
*
1024
maxBuffer
:
20
*
1024
*
1024
};
};
let
tarObj
;
let
tarObj
;
...
@@ -349,10 +369,10 @@ export class AppsService {
...
@@ -349,10 +369,10 @@ export class AppsService {
let
xzFile
=
tarObj
.
xzFile
;
let
xzFile
=
tarObj
.
xzFile
;
let
installDir
=
this
.
path
.
join
(
tarObj
.
installDir
,
tarObj
.
id
);
let
installDir
=
path
.
join
(
tarObj
.
installDir
,
tarObj
.
id
);
if
(
!
this
.
fs
.
existsSync
(
installDir
))
{
if
(
!
fs
.
existsSync
(
installDir
))
{
console
.
log
(
'
app dir not exists
'
);
console
.
log
(
'
app dir not exists
'
);
this
.
mkdirp
(
installDir
,
(
err
)
=>
{
mkdirp
(
installDir
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
err
)
console
.
error
(
err
)
}
else
{
}
else
{
...
@@ -361,7 +381,7 @@ export class AppsService {
...
@@ -361,7 +381,7 @@ export class AppsService {
});
});
}
}
let
tar
=
this
.
execFile
(
tarPath
,
[
'
xvf
'
,
xzFile
,
'
-C
'
,
installDir
],
opt
,
(
err
,
stdout
,
stderr
)
=>
{
let
tar
=
execFile
(
tarPath
,
[
'
xvf
'
,
xzFile
,
'
-C
'
,
installDir
],
opt
,
(
err
,
stdout
,
stderr
)
=>
{
if
(
err
)
{
if
(
err
)
{
throw
err
;
throw
err
;
}
}
...
@@ -398,7 +418,8 @@ export class AppsService {
...
@@ -398,7 +418,8 @@ export class AppsService {
let
tmp
=
this
.
tarQueue
.
shift
();
let
tmp
=
this
.
tarQueue
.
shift
();
this
.
isExtracting
=
false
;
this
.
isExtracting
=
false
;
this
.
downloadsInfo
[
downLoadsInfoIndex
].
status
=
"
complete
"
;
this
.
downloadsInfo
[
downLoadsInfoIndex
].
status
=
"
complete
"
;
// 为了卸载时能重新显示安装条
this
.
downloadsInfo
.
splice
(
downLoadsInfoIndex
,
1
);
this
.
data
=
this
.
data
.
map
((
app
)
=>
{
this
.
data
=
this
.
data
.
map
((
app
)
=>
{
if
(
app
.
id
==
tarObj
.
id
)
{
if
(
app
.
id
==
tarObj
.
id
)
{
app
.
local
=
appLocal
.
local
;
app
.
local
=
appLocal
.
local
;
...
@@ -442,6 +463,6 @@ export class AppsService {
...
@@ -442,6 +463,6 @@ export class AppsService {
}
}
browse
(
id
)
{
browse
(
id
)
{
this
.
electron
.
remote
.
shell
.
showItemInFolder
(
this
.
searchApp
(
id
).
local
.
path
);
electron
.
remote
.
shell
.
showItemInFolder
(
this
.
searchApp
(
id
).
local
.
path
);
}
}
}
}
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