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
14834cc8
Commit
14834cc8
authored
Nov 22, 2016
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strict null checks
parent
327e6687
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
157 additions
and
132 deletions
+157
-132
app/app.ts
app/app.ts
+1
-1
app/apps.service.ts
app/apps.service.ts
+28
-24
app/download.service.ts
app/download.service.ts
+18
-17
app/install.service.ts
app/install.service.ts
+31
-31
app/lobby.component.ts
app/lobby.component.ts
+20
-19
app/login.service.ts
app/login.service.ts
+11
-4
app/mycard.component.html
app/mycard.component.html
+8
-8
app/settings.sevices.ts
app/settings.sevices.ts
+12
-3
app/ygopro.component.ts
app/ygopro.component.ts
+25
-24
tsconfig.json
tsconfig.json
+3
-1
No files found.
app/app.ts
View file @
14834cc8
...
@@ -51,7 +51,7 @@ export class App {
...
@@ -51,7 +51,7 @@ export class App {
network
:
any
;
network
:
any
;
tags
:
string
[];
tags
:
string
[];
version
:
string
;
version
:
string
;
local
:
AppLocal
;
local
:
AppLocal
|
null
;
status
:
AppStatus
;
status
:
AppStatus
;
isInstalled
():
boolean
{
isInstalled
():
boolean
{
...
...
app/apps.service.ts
View file @
14834cc8
...
@@ -12,6 +12,10 @@ import {AppLocal} from "./app-local";
...
@@ -12,6 +12,10 @@ import {AppLocal} from "./app-local";
const
Aria2
=
require
(
'
aria2
'
);
const
Aria2
=
require
(
'
aria2
'
);
const
sudo
=
require
(
'
electron-sudo
'
);
const
sudo
=
require
(
'
electron-sudo
'
);
interface
Connection
{
connection
:
WebSocket
,
address
:
string
|
null
}
@
Injectable
()
@
Injectable
()
export
class
AppsService
{
export
class
AppsService
{
...
@@ -24,7 +28,7 @@ export class AppsService {
...
@@ -24,7 +28,7 @@ export class AppsService {
loadApps
()
{
loadApps
()
{
return
this
.
http
.
get
(
'
./apps.json
'
)
return
this
.
http
.
get
(
'
./apps.json
'
)
.
toPromise
()
.
toPromise
()
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
let
data
=
response
.
json
();
let
data
=
response
.
json
();
this
.
apps
=
this
.
loadAppsList
(
data
);
this
.
apps
=
this
.
loadAppsList
(
data
);
return
this
.
apps
;
return
this
.
apps
;
...
@@ -51,7 +55,7 @@ export class AppsService {
...
@@ -51,7 +55,7 @@ export class AppsService {
}
}
// 去除无关语言
// 去除无关语言
[
'
name
'
,
'
description
'
].
forEach
((
key
)
=>
{
[
'
name
'
,
'
description
'
].
forEach
((
key
)
=>
{
let
value
=
app
[
key
][
locale
];
let
value
=
app
[
key
][
locale
];
if
(
!
value
)
{
if
(
!
value
)
{
value
=
app
[
key
][
"
en-US
"
];
value
=
app
[
key
][
"
en-US
"
];
...
@@ -60,7 +64,7 @@ export class AppsService {
...
@@ -60,7 +64,7 @@ export class AppsService {
});
});
// 去除平台无关的内容
// 去除平台无关的内容
[
'
actions
'
,
'
dependencies
'
,
'
references
'
,
'
download
'
,
'
version
'
].
forEach
((
key
)
=>
{
[
'
actions
'
,
'
dependencies
'
,
'
references
'
,
'
download
'
,
'
version
'
].
forEach
((
key
)
=>
{
if
(
app
[
key
])
{
if
(
app
[
key
])
{
if
(
app
[
key
][
platform
])
{
if
(
app
[
key
][
platform
])
{
app
[
key
]
=
app
[
key
][
platform
];
app
[
key
]
=
app
[
key
][
platform
];
...
@@ -75,8 +79,8 @@ export class AppsService {
...
@@ -75,8 +79,8 @@ export class AppsService {
}
}
// 设置App关系
// 设置App关系
for
(
let
id
of
Array
.
from
(
apps
.
keys
())
)
{
for
(
let
[
id
]
of
apps
)
{
let
temp
=
apps
.
get
(
id
)[
"
actions
"
];
let
temp
=
(
<
App
>
apps
.
get
(
id
)
)[
"
actions
"
];
let
map
=
new
Map
<
string
,
any
>
();
let
map
=
new
Map
<
string
,
any
>
();
for
(
let
action
of
Object
.
keys
(
temp
))
{
for
(
let
action
of
Object
.
keys
(
temp
))
{
let
openId
=
temp
[
action
][
"
open
"
];
let
openId
=
temp
[
action
][
"
open
"
];
...
@@ -85,15 +89,15 @@ export class AppsService {
...
@@ -85,15 +89,15 @@ export class AppsService {
}
}
map
.
set
(
action
,
temp
[
action
]);
map
.
set
(
action
,
temp
[
action
]);
}
}
apps
.
get
(
id
).
actions
=
map
;
(
<
App
>
apps
.
get
(
id
)
).
actions
=
map
;
[
'
dependencies
'
,
'
references
'
,
'
parent
'
].
forEach
((
key
)
=>
{
[
'
dependencies
'
,
'
references
'
,
'
parent
'
].
forEach
((
key
)
=>
{
let
app
=
apps
.
get
(
id
);
let
app
=
<
App
>
apps
.
get
(
id
);
let
value
=
app
[
key
];
let
value
=
app
[
key
];
if
(
value
)
{
if
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
if
(
Array
.
isArray
(
value
))
{
let
map
=
new
Map
<
string
,
App
>
();
let
map
=
new
Map
<
string
,
App
>
();
value
.
forEach
((
appId
,
index
,
array
)
=>
{
value
.
forEach
((
appId
,
index
,
array
)
=>
{
map
.
set
(
appId
,
apps
.
get
(
appId
));
map
.
set
(
appId
,
apps
.
get
(
appId
));
});
});
app
[
key
]
=
map
;
app
[
key
]
=
map
;
...
@@ -107,8 +111,8 @@ export class AppsService {
...
@@ -107,8 +111,8 @@ export class AppsService {
};
};
findChildren
(
app
:
App
):
App
[]
{
findChildren
(
app
:
App
):
App
[]
{
let
children
=
[];
let
children
:
App
[]
=
[];
for
(
let
child
of
this
.
apps
.
values
()
)
{
for
(
let
[
id
,
child
]
of
this
.
apps
)
{
if
(
child
.
parent
===
app
)
{
if
(
child
.
parent
===
app
)
{
children
.
push
(
child
);
children
.
push
(
child
);
}
}
...
@@ -118,9 +122,9 @@ export class AppsService {
...
@@ -118,9 +122,9 @@ export class AppsService {
runApp
(
app
:
App
)
{
runApp
(
app
:
App
)
{
let
children
=
this
.
findChildren
(
app
);
let
children
=
this
.
findChildren
(
app
);
let
cwd
=
app
.
local
.
path
;
let
cwd
=
(
<
AppLocal
>
app
.
local
)
.
path
;
let
action
=
app
.
actions
.
get
(
'
main
'
);
let
action
:
any
=
app
.
actions
.
get
(
'
main
'
);
let
args
=
[];
let
args
:
string
[]
=
[];
let
env
=
{};
let
env
=
{};
for
(
let
child
of
children
)
{
for
(
let
child
of
children
)
{
action
=
child
.
actions
.
get
(
'
main
'
);
action
=
child
.
actions
.
get
(
'
main
'
);
...
@@ -154,17 +158,17 @@ export class AppsService {
...
@@ -154,17 +158,17 @@ export class AppsService {
}
}
browse
(
app
:
App
)
{
browse
(
app
:
App
)
{
remote
.
shell
.
showItemInFolder
(
app
.
local
.
path
);
remote
.
shell
.
showItemInFolder
(
(
<
AppLocal
>
app
.
local
)
.
path
);
}
}
connections
=
new
Map
<
App
,
{
connection
:
WebSocket
,
address
:
string
}
>
();
connections
=
new
Map
<
App
,
Connection
>
();
maotama
;
maotama
;
async
network
(
app
:
App
,
server
)
{
async
network
(
app
:
App
,
server
)
{
if
(
!
this
.
maotama
)
{
if
(
!
this
.
maotama
)
{
this
.
maotama
=
new
Promise
((
resolve
,
reject
)
=>
{
this
.
maotama
=
new
Promise
((
resolve
,
reject
)
=>
{
let
child
=
sudo
.
fork
(
'
maotama
'
,
[],
{
stdio
:
[
'
inherit
'
,
'
inherit
'
,
'
inherit
'
,
'
ipc
'
]});
let
child
=
sudo
.
fork
(
'
maotama
'
,
[],
{
stdio
:
[
'
inherit
'
,
'
inherit
'
,
'
inherit
'
,
'
ipc
'
]});
child
.
once
(
'
message
'
,
()
=>
resolve
(
child
));
child
.
once
(
'
message
'
,
()
=>
resolve
(
child
));
child
.
once
(
'
error
'
,
reject
);
child
.
once
(
'
error
'
,
reject
);
child
.
once
(
'
exit
'
,
reject
);
child
.
once
(
'
exit
'
,
reject
);
})
})
...
@@ -177,24 +181,24 @@ export class AppsService {
...
@@ -177,24 +181,24 @@ export class AppsService {
return
return
}
}
let
connection
=
this
.
connections
.
get
(
app
);
let
connection
:
Connection
|
undefined
=
this
.
connections
.
get
(
app
);
if
(
connection
)
{
if
(
connection
)
{
connection
.
connection
.
close
();
connection
.
connection
.
close
();
}
}
connection
=
{
connection
:
new
WebSocket
(
server
.
url
),
address
:
null
};
connection
=
{
connection
:
new
WebSocket
(
server
.
url
),
address
:
null
};
let
id
;
let
id
;
this
.
connections
.
set
(
app
,
connection
);
this
.
connections
.
set
(
app
,
connection
);
connection
.
connection
.
onmessage
=
(
event
)
=>
{
connection
.
connection
.
onmessage
=
(
event
)
=>
{
console
.
log
(
event
.
data
);
console
.
log
(
event
.
data
);
let
[
action
,
args
]
=
event
.
data
.
split
(
'
'
,
2
);
let
[
action
,
args
]
=
event
.
data
.
split
(
'
'
,
2
);
let
[
address
,
port
]
=
args
.
split
(
'
:
'
);
let
[
address
,
port
]
=
args
.
split
(
'
:
'
);
switch
(
action
)
{
switch
(
action
)
{
case
'
LISTEN
'
:
case
'
LISTEN
'
:
connection
.
address
=
args
;
(
<
Connection
>
connection
)
.
address
=
args
;
this
.
ref
.
tick
();
this
.
ref
.
tick
();
break
;
break
;
case
'
CONNECT
'
:
case
'
CONNECT
'
:
id
=
setInterval
(()
=>
{
id
=
setInterval
(()
=>
{
child
.
send
({
child
.
send
({
action
:
'
connect
'
,
action
:
'
connect
'
,
arguments
:
[
app
.
network
.
port
,
port
,
address
]
arguments
:
[
app
.
network
.
port
,
port
,
address
]
...
@@ -207,14 +211,14 @@ export class AppsService {
...
@@ -207,14 +211,14 @@ export class AppsService {
break
;
break
;
}
}
};
};
connection
.
connection
.
onclose
=
(
event
:
CloseEvent
)
=>
{
connection
.
connection
.
onclose
=
(
event
:
CloseEvent
)
=>
{
if
(
id
)
{
if
(
id
)
{
clearInterval
(
id
);
clearInterval
(
id
);
}
}
// 如果还是在界面上显示的那个连接
// 如果还是在界面上显示的那个连接
if
(
this
.
connections
.
get
(
app
)
==
connection
)
{
if
(
this
.
connections
.
get
(
app
)
==
connection
)
{
this
.
connections
.
delete
(
app
);
this
.
connections
.
delete
(
app
);
if
(
event
.
code
!=
1000
&&
!
connection
.
address
)
{
if
(
event
.
code
!=
1000
&&
!
(
<
Connection
>
connection
)
.
address
)
{
alert
(
`出错了
${
event
.
code
}
`
);
alert
(
`出错了
${
event
.
code
}
`
);
}
}
}
}
...
...
app/download.service.ts
View file @
14834cc8
...
@@ -21,7 +21,7 @@ export class DownloadService {
...
@@ -21,7 +21,7 @@ export class DownloadService {
open
=
this
.
aria2
.
open
();
open
=
this
.
aria2
.
open
();
constructor
(
private
ngZone
:
NgZone
,
private
http
:
Http
)
{
constructor
(
private
ngZone
:
NgZone
,
private
http
:
Http
)
{
this
.
aria2
.
onDownloadComplete
=
(
result
)
=>
{
this
.
aria2
.
onDownloadComplete
=
(
result
)
=>
{
let
app
=
this
.
gidAppMap
.
get
(
result
.
gid
);
let
app
=
this
.
gidAppMap
.
get
(
result
.
gid
);
if
(
app
)
{
if
(
app
)
{
this
.
appGidMap
.
delete
(
app
);
this
.
appGidMap
.
delete
(
app
);
...
@@ -38,22 +38,23 @@ export class DownloadService {
...
@@ -38,22 +38,23 @@ export class DownloadService {
}
}
getComplete
(
app
:
App
):
Promise
<
App
>
{
getComplete
(
app
:
App
):
Promise
<
App
>
{
if
(
this
.
appGidMap
.
has
(
app
))
{
if
(
!
this
.
appGidMap
.
has
(
app
))
{
return
new
Promise
((
resolve
,
reject
)
=>
{
throw
(
'
nyaa
'
);
this
.
eventEmitter
.
once
(
app
.
id
,
(
event
)
=>
{
resolve
(
app
);
})
});
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
eventEmitter
.
once
(
app
.
id
,
(
event
)
=>
{
resolve
(
app
);
})
});
}
}
getProgress
(
app
:
App
):
Observable
<
any
>
{
getProgress
(
app
:
App
):
Observable
<
any
>
{
let
gid
=
this
.
appGidMap
.
get
(
app
);
let
gid
=
this
.
appGidMap
.
get
(
app
);
return
Observable
.
create
((
observer
)
=>
{
return
Observable
.
create
((
observer
)
=>
{
let
interval
;
let
interval
;
this
.
ngZone
.
runOutsideAngular
(()
=>
{
this
.
ngZone
.
runOutsideAngular
(()
=>
{
interval
=
setInterval
(()
=>
{
interval
=
setInterval
(()
=>
{
this
.
aria2
.
tellStatus
(
gid
).
then
((
status
:
any
)
=>
{
this
.
aria2
.
tellStatus
(
gid
).
then
((
status
:
any
)
=>
{
if
(
status
.
status
===
'
complete
'
)
{
if
(
status
.
status
===
'
complete
'
)
{
observer
.
complete
();
observer
.
complete
();
}
else
if
(
status
.
status
===
"
active
"
)
{
}
else
if
(
status
.
status
===
"
active
"
)
{
...
@@ -64,14 +65,14 @@ export class DownloadService {
...
@@ -64,14 +65,14 @@ export class DownloadService {
});
});
},
1000
);
},
1000
);
});
});
return
()
=>
{
return
()
=>
{
clearInterval
(
interval
);
clearInterval
(
interval
);
}
}
});
});
}
}
async
addUris
(
apps
:
App
[],
path
:
string
):
Promise
<
App
[]
>
{
async
addUris
(
apps
:
App
[],
path
:
string
):
Promise
<
App
[]
>
{
let
tasks
=
[];
let
tasks
:
App
[]
=
[];
for
(
let
app
of
apps
)
{
for
(
let
app
of
apps
)
{
let
task
=
await
this
.
addUri
(
app
,
path
);
let
task
=
await
this
.
addUri
(
app
,
path
);
tasks
.
push
(
task
);
tasks
.
push
(
task
);
...
@@ -84,16 +85,16 @@ export class DownloadService {
...
@@ -84,16 +85,16 @@ export class DownloadService {
async
addMetalink
(
metalink
:
string
,
library
:
string
)
{
async
addMetalink
(
metalink
:
string
,
library
:
string
)
{
let
meta4
=
btoa
(
metalink
);
let
meta4
=
btoa
(
metalink
);
let
gid
=
(
await
this
.
aria2
.
addMetalink
(
meta4
,
{
dir
:
library
}))[
0
];
let
gid
=
(
await
this
.
aria2
.
addMetalink
(
meta4
,
{
dir
:
library
}))[
0
];
return
Observable
.
create
((
observer
)
=>
{
return
Observable
.
create
((
observer
)
=>
{
this
.
map
.
set
(
gid
,
observer
);
this
.
map
.
set
(
gid
,
observer
);
let
interval
;
let
interval
;
this
.
ngZone
.
runOutsideAngular
(()
=>
{
this
.
ngZone
.
runOutsideAngular
(()
=>
{
interval
=
setInterval
(
async
()
=>
{
interval
=
setInterval
(
async
()
=>
{
let
status
=
await
this
.
aria2
.
tellStatus
(
gid
);
let
status
=
await
this
.
aria2
.
tellStatus
(
gid
);
this
.
map
.
get
(
gid
).
next
(
status
);
this
.
map
.
get
(
gid
).
next
(
status
);
},
1000
)
},
1000
)
});
});
return
()
=>
{
return
()
=>
{
clearInterval
(
interval
);
clearInterval
(
interval
);
}
}
});
});
...
...
app/install.service.ts
View file @
14834cc8
...
@@ -36,29 +36,29 @@ export class InstallService {
...
@@ -36,29 +36,29 @@ export class InstallService {
createDirectory
(
dir
:
string
)
{
createDirectory
(
dir
:
string
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
mkdirp
(
dir
,
resolve
);
mkdirp
(
dir
,
resolve
);
})
})
}
}
getComplete
(
app
:
App
):
Promise
<
App
>
{
getComplete
(
app
:
App
):
Promise
<
App
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
eventEmitter
.
once
(
app
.
id
,
(
complete
)
=>
{
this
.
eventEmitter
.
once
(
app
.
id
,
(
complete
)
=>
{
resolve
();
resolve
();
});
});
});
});
}
}
extract
(
file
:
string
,
destPath
:
string
)
{
extract
(
file
:
string
,
destPath
:
string
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
tarProcess
=
child_process
.
spawn
(
this
.
tarPath
,
[
'
xvf
'
,
file
,
'
-C
'
,
destPath
]);
let
tarProcess
=
child_process
.
spawn
(
this
.
tarPath
,
[
'
xvf
'
,
file
,
'
-C
'
,
destPath
]);
let
rl
=
readline
.
createInterface
({
let
rl
=
readline
.
createInterface
({
input
:
<
ReadableStream
>
tarProcess
.
stderr
,
input
:
<
ReadableStream
>
tarProcess
.
stderr
,
});
});
rl
.
on
(
'
line
'
,
(
input
)
=>
{
rl
.
on
(
'
line
'
,
(
input
)
=>
{
console
.
log
(
input
);
console
.
log
(
input
);
});
});
tarProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
tarProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
if
(
code
===
0
)
{
if
(
code
===
0
)
{
resolve
();
resolve
();
}
else
{
}
else
{
...
@@ -72,26 +72,26 @@ export class InstallService {
...
@@ -72,26 +72,26 @@ export class InstallService {
let
action
=
app
.
actions
.
get
(
'
install
'
);
let
action
=
app
.
actions
.
get
(
'
install
'
);
if
(
action
)
{
if
(
action
)
{
let
env
=
Object
.
assign
({},
action
.
env
);
let
env
=
Object
.
assign
({},
action
.
env
);
let
command
=
[];
let
command
:
string
[]
=
[];
command
.
push
(
path
.
join
(
appPath
,
action
.
execute
));
command
.
push
(
path
.
join
(
appPath
,
action
.
execute
));
command
.
push
(...
action
.
args
);
command
.
push
(...
action
.
args
);
let
open
=
action
.
open
;
let
open
=
action
.
open
;
if
(
open
)
{
if
(
open
)
{
let
openAction
=
open
.
actions
.
get
(
"
main
"
);
let
openAction
:
any
=
open
.
actions
.
get
(
"
main
"
);
env
=
Object
.
assign
(
env
,
openAction
.
env
);
env
=
Object
.
assign
(
env
,
openAction
.
env
);
command
.
unshift
(...
openAction
.
args
);
command
.
unshift
(...
openAction
.
args
);
command
.
unshift
(
path
.
join
(
open
.
local
.
path
,
openAction
.
execute
));
command
.
unshift
(
path
.
join
(
(
<
AppLocal
>
open
.
local
)
.
path
,
openAction
.
execute
));
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
child
=
child_process
.
spawn
(
command
.
shift
(),
command
,
{
let
child
=
child_process
.
spawn
(
<
string
>
command
.
shift
(),
command
,
{
env
:
env
,
env
:
env
,
stdio
:
'
inherit
'
,
stdio
:
'
inherit
'
,
shell
:
true
,
shell
:
true
,
});
});
child
.
on
(
'
error
'
,
(
error
)
=>
{
child
.
on
(
'
error
'
,
(
error
)
=>
{
console
.
log
(
error
);
console
.
log
(
error
);
});
});
child
.
on
(
'
exit
'
,
(
code
)
=>
{
child
.
on
(
'
exit
'
,
(
code
)
=>
{
if
(
code
===
0
)
{
if
(
code
===
0
)
{
resolve
();
resolve
();
}
else
{
}
else
{
...
@@ -109,11 +109,11 @@ export class InstallService {
...
@@ -109,11 +109,11 @@ export class InstallService {
}
}
async
backupFiles
(
app
:
App
,
files
:
Iterable
<
string
>
)
{
async
backupFiles
(
app
:
App
,
files
:
Iterable
<
string
>
)
{
let
backupPath
=
path
.
join
(
app
.
local
.
path
,
"
backup
"
);
let
backupPath
=
path
.
join
(
(
<
AppLocal
>
app
.
local
)
.
path
,
"
backup
"
);
await
this
.
createDirectory
(
backupPath
);
await
this
.
createDirectory
(
backupPath
);
for
(
let
file
of
files
)
{
for
(
let
file
of
files
)
{
await
new
Promise
((
resolve
,
reject
)
=>
{
await
new
Promise
((
resolve
,
reject
)
=>
{
let
oldPath
=
path
.
join
(
app
.
local
.
path
,
file
);
let
oldPath
=
path
.
join
(
(
<
AppLocal
>
app
.
local
)
.
path
,
file
);
let
newPath
=
path
.
join
(
backupPath
,
file
);
let
newPath
=
path
.
join
(
backupPath
,
file
);
fs
.
rename
(
oldPath
,
newPath
,
resolve
);
fs
.
rename
(
oldPath
,
newPath
,
resolve
);
});
});
...
@@ -122,7 +122,7 @@ export class InstallService {
...
@@ -122,7 +122,7 @@ export class InstallService {
async
getChecksumFile
(
app
:
App
):
Promise
<
Map
<
string
,
string
>
>
{
async
getChecksumFile
(
app
:
App
):
Promise
<
Map
<
string
,
string
>
>
{
let
checksumMap
:
Map
<
string
,
string
>
=
await
this
.
http
.
get
(
this
.
checksumUri
+
app
.
id
)
let
checksumMap
:
Map
<
string
,
string
>
=
await
this
.
http
.
get
(
this
.
checksumUri
+
app
.
id
)
.
map
((
response
)
=>
{
.
map
((
response
)
=>
{
let
map
=
new
Map
<
string
,
string
>
();
let
map
=
new
Map
<
string
,
string
>
();
for
(
let
line
of
response
.
text
().
split
(
'
\n
'
))
{
for
(
let
line
of
response
.
text
().
split
(
'
\n
'
))
{
if
(
line
!==
""
)
{
if
(
line
!==
""
)
{
...
@@ -138,23 +138,23 @@ export class InstallService {
...
@@ -138,23 +138,23 @@ export class InstallService {
async
doInstall
()
{
async
doInstall
()
{
for
(
let
app
of
this
.
installQueue
.
keys
())
{
for
(
let
app
of
this
.
installQueue
.
keys
())
{
let
depInstalled
=
app
.
findDependencies
()
let
depInstalled
=
app
.
findDependencies
()
.
every
((
dependency
)
=>
dependency
.
isInstalled
());
.
every
((
dependency
)
=>
dependency
.
isInstalled
());
if
(
depInstalled
&&
!
this
.
installingQueue
.
has
(
app
))
{
if
(
depInstalled
&&
!
this
.
installingQueue
.
has
(
app
))
{
this
.
installingQueue
.
add
(
app
);
this
.
installingQueue
.
add
(
app
);
let
options
=
this
.
installQueue
.
get
(
app
);
let
options
=
<
InstallConfig
>
this
.
installQueue
.
get
(
app
);
let
checksumMap
=
await
this
.
getChecksumFile
(
app
);
let
checksumMap
=
await
this
.
getChecksumFile
(
app
);
let
packagePath
=
path
.
join
(
options
.
installLibrary
,
'
downloading
'
,
`
${
app
.
id
}
.tar.xz`
);
let
packagePath
=
path
.
join
(
options
.
installLibrary
,
'
downloading
'
,
`
${
app
.
id
}
.tar.xz`
);
let
destPath
:
string
;
let
destPath
:
string
;
if
(
app
.
parent
)
{
if
(
app
.
parent
)
{
let
differenceSet
=
new
Set
<
string
>
();
let
differenceSet
=
new
Set
<
string
>
();
let
parentFilesMap
=
app
.
parent
.
local
.
files
;
let
parentFilesMap
=
(
<
AppLocal
>
app
.
parent
.
local
)
.
files
;
for
(
let
key
of
checksumMap
.
keys
())
{
for
(
let
key
of
checksumMap
.
keys
())
{
if
(
parentFilesMap
.
has
(
key
))
{
if
(
parentFilesMap
.
has
(
key
))
{
differenceSet
.
add
(
key
);
differenceSet
.
add
(
key
);
}
}
}
}
await
this
.
backupFiles
(
app
.
parent
,
differenceSet
);
await
this
.
backupFiles
(
app
.
parent
,
differenceSet
);
destPath
=
app
.
parent
.
local
.
path
;
destPath
=
(
<
AppLocal
>
app
.
parent
.
local
)
.
path
;
}
else
{
}
else
{
destPath
=
path
.
join
(
options
.
installLibrary
,
app
.
id
);
destPath
=
path
.
join
(
options
.
installLibrary
,
app
.
id
);
await
this
.
createDirectory
(
destPath
);
await
this
.
createDirectory
(
destPath
);
...
@@ -187,15 +187,15 @@ export class InstallService {
...
@@ -187,15 +187,15 @@ export class InstallService {
}
}
deleteFile
(
file
:
string
):
Promise
<
string
>
{
deleteFile
(
file
:
string
):
Promise
<
string
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
lstat
(
file
,
(
err
,
stats
)
=>
{
fs
.
lstat
(
file
,
(
err
,
stats
)
=>
{
if
(
err
)
return
resolve
(
path
);
if
(
err
)
return
resolve
(
path
);
if
(
stats
.
isDirectory
())
{
if
(
stats
.
isDirectory
())
{
fs
.
rmdir
(
file
,
(
err
)
=>
{
fs
.
rmdir
(
file
,
(
err
)
=>
{
resolve
(
file
);
resolve
(
file
);
});
});
}
else
{
}
else
{
fs
.
unlink
(
file
,
(
err
)
=>
{
fs
.
unlink
(
file
,
(
err
)
=>
{
resolve
(
file
);
resolve
(
file
);
});
});
}
}
...
@@ -212,17 +212,17 @@ export class InstallService {
...
@@ -212,17 +212,17 @@ export class InstallService {
}
}
}
}
}
}
let
files
=
Array
.
from
(
app
.
local
.
files
.
keys
()).
sort
().
reverse
();
let
files
=
Array
.
from
(
(
<
AppLocal
>
app
.
local
)
.
files
.
keys
()).
sort
().
reverse
();
for
(
let
file
of
files
)
{
for
(
let
file
of
files
)
{
let
oldFile
=
file
;
let
oldFile
=
file
;
if
(
!
path
.
isAbsolute
(
file
))
{
if
(
!
path
.
isAbsolute
(
file
))
{
oldFile
=
path
.
join
(
app
.
local
.
path
,
file
);
oldFile
=
path
.
join
(
(
<
AppLocal
>
app
.
local
)
.
path
,
file
);
}
}
if
(
restore
)
{
if
(
restore
)
{
await
this
.
deleteFile
(
oldFile
);
await
this
.
deleteFile
(
oldFile
);
if
(
app
.
parent
)
{
if
(
app
.
parent
)
{
let
backFile
=
path
.
join
(
app
.
local
.
path
,
"
backup
"
,
file
);
let
backFile
=
path
.
join
(
(
<
AppLocal
>
app
.
local
)
.
path
,
"
backup
"
,
file
);
await
new
Promise
((
resolve
,
reject
)
=>
{
await
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
rename
(
backFile
,
oldFile
,
resolve
);
fs
.
rename
(
backFile
,
oldFile
,
resolve
);
});
});
}
}
...
@@ -230,9 +230,9 @@ export class InstallService {
...
@@ -230,9 +230,9 @@ export class InstallService {
}
}
if
(
app
.
parent
)
{
if
(
app
.
parent
)
{
await
this
.
deleteFile
(
path
.
join
(
app
.
local
.
path
,
"
backup
"
));
await
this
.
deleteFile
(
path
.
join
(
(
<
AppLocal
>
app
.
local
)
.
path
,
"
backup
"
));
}
else
{
}
else
{
await
this
.
deleteFile
(
app
.
local
.
path
);
await
this
.
deleteFile
(
(
<
AppLocal
>
app
.
local
)
.
path
);
}
}
app
.
local
=
null
;
app
.
local
=
null
;
localStorage
.
removeItem
(
app
.
id
);
localStorage
.
removeItem
(
app
.
id
);
...
...
app/lobby.component.ts
View file @
14834cc8
...
@@ -3,13 +3,14 @@
...
@@ -3,13 +3,14 @@
*/
*/
import
{
Component
,
OnInit
}
from
"
@angular/core
"
;
import
{
Component
,
OnInit
}
from
"
@angular/core
"
;
import
{
AppsService
}
from
"
./apps.service
"
;
import
{
AppsService
}
from
"
./apps.service
"
;
import
{
LoginService
}
from
"
./login.service
"
;
import
{
LoginService
,
User
}
from
"
./login.service
"
;
import
{
App
,
Category
}
from
"
./app
"
;
import
{
App
,
Category
}
from
"
./app
"
;
import
{
DownloadService
}
from
"
./download.service
"
;
import
{
DownloadService
}
from
"
./download.service
"
;
import
{
InstallService
}
from
"
./install.service
"
;
import
{
InstallService
}
from
"
./install.service
"
;
import
{
Http
}
from
"
@angular/http
"
;
import
{
Http
}
from
"
@angular/http
"
;
import
*
as
path
from
'
path
'
;
import
*
as
path
from
'
path
'
;
import
{
InstallConfig
}
from
"
./install-config
"
;
import
{
InstallConfig
}
from
"
./install-config
"
;
import
{
AppLocal
}
from
"
./app-local
"
;
@
Component
({
@
Component
({
selector
:
'
lobby
'
,
selector
:
'
lobby
'
,
...
@@ -29,9 +30,9 @@ export class LobbyComponent implements OnInit {
...
@@ -29,9 +30,9 @@ export class LobbyComponent implements OnInit {
ngOnInit
()
{
ngOnInit
()
{
this
.
appsService
.
loadApps
()
this
.
appsService
.
loadApps
()
.
then
((
apps
)
=>
{
.
then
((
apps
)
=>
{
this
.
apps
=
apps
;
this
.
apps
=
apps
;
this
.
currentApp
=
this
.
apps
.
get
(
"
th06
"
);
this
.
currentApp
=
<
App
>
this
.
apps
.
get
(
"
th06
"
);
this
.
updateApp
();
this
.
updateApp
();
})
})
...
@@ -41,12 +42,12 @@ export class LobbyComponent implements OnInit {
...
@@ -41,12 +42,12 @@ export class LobbyComponent implements OnInit {
let
updateServer
=
"
http://thief.mycard.moe/update/metalinks/
"
;
let
updateServer
=
"
http://thief.mycard.moe/update/metalinks/
"
;
let
checksumServer
=
"
http://thief.mycard.moe/checksums/
"
;
let
checksumServer
=
"
http://thief.mycard.moe/checksums/
"
;
for
(
let
app
of
this
.
apps
.
values
())
{
for
(
let
app
of
this
.
apps
.
values
())
{
if
(
app
.
isInstalled
()
&&
app
.
version
!=
app
.
local
.
version
)
{
if
(
app
.
isInstalled
()
&&
app
.
version
!=
(
<
AppLocal
>
app
.
local
)
.
version
)
{
let
checksumMap
=
await
this
.
installService
.
getChecksumFile
(
app
);
let
checksumMap
=
await
this
.
installService
.
getChecksumFile
(
app
);
let
filesMap
=
app
.
local
.
files
;
let
filesMap
=
(
<
AppLocal
>
app
.
local
)
.
files
;
let
deleteList
=
[];
let
deleteList
:
string
[]
=
[];
let
addList
=
[];
let
addList
:
string
[]
=
[];
let
changeList
=
[];
let
changeList
:
string
[]
=
[];
for
(
let
[
file
,
checksum
]
of
filesMap
)
{
for
(
let
[
file
,
checksum
]
of
filesMap
)
{
let
t
=
checksumMap
.
get
(
file
);
let
t
=
checksumMap
.
get
(
file
);
if
(
!
t
)
{
if
(
!
t
)
{
...
@@ -60,19 +61,19 @@ export class LobbyComponent implements OnInit {
...
@@ -60,19 +61,19 @@ export class LobbyComponent implements OnInit {
changeList
.
push
(
file
);
changeList
.
push
(
file
);
}
}
}
}
let
metalink
=
await
this
.
http
.
post
(
updateServer
+
app
.
id
,
changeList
).
map
((
response
)
=>
response
.
text
())
let
metalink
=
await
this
.
http
.
post
(
updateServer
+
app
.
id
,
changeList
).
map
((
response
)
=>
response
.
text
())
.
toPromise
();
.
toPromise
();
let
meta
=
new
DOMParser
().
parseFromString
(
metalink
,
"
text/xml
"
);
let
meta
=
new
DOMParser
().
parseFromString
(
metalink
,
"
text/xml
"
);
let
filename
=
meta
.
getElementsByTagName
(
'
file
'
)[
0
].
getAttribute
(
'
name
'
);
let
filename
=
meta
.
getElementsByTagName
(
'
file
'
)[
0
].
getAttribute
(
'
name
'
);
let
dir
=
path
.
join
(
path
.
dirname
(
app
.
local
.
path
),
"
downloading
"
);
let
dir
=
path
.
join
(
path
.
dirname
(
(
<
AppLocal
>
app
.
local
)
.
path
),
"
downloading
"
);
let
a
=
await
this
.
downloadService
.
addMetalink
(
metalink
,
dir
);
let
a
=
await
this
.
downloadService
.
addMetalink
(
metalink
,
dir
);
await
new
Promise
((
resolve
,
reject
)
=>
{
await
new
Promise
((
resolve
,
reject
)
=>
{
a
.
subscribe
((
status
)
=>
{
a
.
subscribe
((
status
)
=>
{
console
.
log
(
status
);
console
.
log
(
status
);
},
(
err
)
=>
{
},
(
err
)
=>
{
reject
()
reject
()
},
()
=>
{
},
()
=>
{
resolve
();
resolve
();
});
});
});
});
...
@@ -80,15 +81,15 @@ export class LobbyComponent implements OnInit {
...
@@ -80,15 +81,15 @@ export class LobbyComponent implements OnInit {
for
(
let
file
of
deleteList
)
{
for
(
let
file
of
deleteList
)
{
await
this
.
installService
.
deleteFile
(
file
);
await
this
.
installService
.
deleteFile
(
file
);
}
}
app
.
local
.
version
=
app
.
version
;
(
<
AppLocal
>
app
.
local
).
version
=
app
.
version
;
app
.
local
.
files
=
checksumMap
;
(
<
AppLocal
>
app
.
local
)
.
files
=
checksumMap
;
localStorage
.
setItem
(
app
.
id
,
JSON
.
stringify
(
app
.
local
));
localStorage
.
setItem
(
app
.
id
,
JSON
.
stringify
(
app
.
local
));
await
this
.
installService
.
extract
(
path
.
join
(
dir
,
filename
),
app
.
local
.
path
);
await
this
.
installService
.
extract
(
path
.
join
(
dir
,
filename
),
(
<
AppLocal
>
app
.
local
)
.
path
);
let
children
=
this
.
appsService
.
findChildren
(
app
);
let
children
=
this
.
appsService
.
findChildren
(
app
);
for
(
let
child
of
children
)
{
for
(
let
child
of
children
)
{
if
(
child
.
isInstalled
())
{
if
(
child
.
isInstalled
())
{
await
this
.
installService
.
uninstall
(
child
,
false
);
await
this
.
installService
.
uninstall
(
child
,
false
);
this
.
installService
.
add
(
child
,
new
InstallConfig
(
child
,
path
.
dirname
((
app
.
local
.
path
))));
this
.
installService
.
add
(
child
,
new
InstallConfig
(
child
,
path
.
dirname
((
(
<
AppLocal
>
app
.
local
)
.
path
))));
await
this
.
installService
.
getComplete
(
child
);
await
this
.
installService
.
getComplete
(
child
);
console
.
log
(
"
282828
"
)
console
.
log
(
"
282828
"
)
}
}
...
@@ -103,7 +104,7 @@ export class LobbyComponent implements OnInit {
...
@@ -103,7 +104,7 @@ export class LobbyComponent implements OnInit {
}
}
get
grouped_apps
()
{
get
grouped_apps
()
{
let
contains
=
[
"
game
"
,
"
music
"
,
"
book
"
].
map
((
value
)
=>
Category
[
value
]);
let
contains
=
[
"
game
"
,
"
music
"
,
"
book
"
].
map
((
value
)
=>
Category
[
value
]);
let
result
=
{};
let
result
=
{};
for
(
let
app
of
this
.
apps
.
values
())
{
for
(
let
app
of
this
.
apps
.
values
())
{
if
(
contains
.
includes
(
app
.
category
))
{
if
(
contains
.
includes
(
app
.
category
))
{
...
...
app/login.service.ts
View file @
14834cc8
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
Http
}
from
"
@angular/http
"
;
import
{
Http
}
from
"
@angular/http
"
;
interface
User
{
export
interface
User
{
admin
:
boolean
;
admin
:
boolean
;
avatar_url
:
string
;
avatar_url
:
string
;
email
:
string
;
email
:
string
;
...
@@ -16,20 +16,27 @@ interface User {
...
@@ -16,20 +16,27 @@ interface User {
@
Injectable
()
@
Injectable
()
export
class
LoginService
{
export
class
LoginService
{
user
:
User
=
JSON
.
parse
(
localStorage
.
getItem
(
'
login
'
));
user
:
User
;
logging_out
;
logged_in
=
false
;
logging_out
=
false
;
constructor
(
private
http
:
Http
)
{
constructor
(
private
http
:
Http
)
{
let
data
=
localStorage
.
getItem
(
'
login
'
);
if
(
data
)
{
this
.
user
=
JSON
.
parse
(
data
);
this
.
logged_in
=
true
;
}
}
}
login
(
user
)
{
login
(
user
)
{
this
.
user
=
user
;
this
.
user
=
user
;
this
.
logged_in
=
true
;
localStorage
.
setItem
(
'
login
'
,
JSON
.
stringify
(
user
));
localStorage
.
setItem
(
'
login
'
,
JSON
.
stringify
(
user
));
}
}
logout
()
{
logout
()
{
this
.
logging_out
=
true
;
this
.
logging_out
=
true
;
this
.
user
=
null
;
this
.
logged_in
=
false
;
localStorage
.
removeItem
(
'
login
'
);
localStorage
.
removeItem
(
'
login
'
);
}
}
...
...
app/mycard.component.html
View file @
14834cc8
<nav
class=
"navbar navbar-dark bg-inverse"
[class.darwin]=
"platform == 'darwin'"
>
<nav
class=
"navbar navbar-dark bg-inverse"
[class.darwin]=
"platform == 'darwin'"
>
<a
class=
"navbar-brand"
href=
"#"
>
MyCard
</a>
<a
class=
"navbar-brand"
href=
"#"
>
MyCard
</a>
<ul
class=
"nav navbar-nav"
>
<ul
class=
"nav navbar-nav"
>
<li
*ngIf=
"!loginService.
user
"
class=
"nav-item active"
>
<li
*ngIf=
"!loginService.
logged_in
"
class=
"nav-item active"
>
<a
class=
"nav-link"
href=
"#"
>
登录
<span
class=
"sr-only"
>
(current)
</span></a>
<a
class=
"nav-link"
href=
"#"
>
登录
<span
class=
"sr-only"
>
(current)
</span></a>
</li>
</li>
<!--
<!--
...
@@ -9,15 +9,15 @@
...
@@ -9,15 +9,15 @@
<a (click)="changeFouce('store')" class="nav-link" href="#">商店</a>
<a (click)="changeFouce('store')" class="nav-link" href="#">商店</a>
</li>
</li>
-->
-->
<li
*ngIf=
"loginService.
user
"
[ngClass]=
"{active: currentPage === 'lobby'}"
class=
"nav-item"
>
<li
*ngIf=
"loginService.
logged_in
"
[ngClass]=
"{active: currentPage === 'lobby'}"
class=
"nav-item"
>
<a
(click)=
"currentPage='lobby'"
class=
"nav-link"
href=
"#"
>
{{'library'| translate}}
<span
class=
"sr-only"
>
(current)
</span></a>
<a
(click)=
"currentPage='lobby'"
class=
"nav-link"
href=
"#"
>
{{'library'| translate}}
<span
class=
"sr-only"
>
(current)
</span></a>
</li>
</li>
<li
*ngIf=
"loginService.
user
"
[ngClass]=
"{active: currentPage === 'community'}"
class=
"nav-item"
>
<li
*ngIf=
"loginService.
logged_in
"
[ngClass]=
"{active: currentPage === 'community'}"
class=
"nav-item"
>
<a
(click)=
"currentPage='community'"
class=
"nav-link"
href=
"#"
>
{{'community'| translate}}
</a>
<a
(click)=
"currentPage='community'"
class=
"nav-link"
href=
"#"
>
{{'community'| translate}}
</a>
</li>
</li>
</ul>
</ul>
<div
class=
"navbar-right"
>
<div
class=
"navbar-right"
>
<div
id=
"user"
*ngIf=
"loginService.
user
"
>
<div
id=
"user"
*ngIf=
"loginService.
logged_in
"
>
<a
href=
"#"
class=
"profile"
><img
id=
"avatar"
[src]=
"loginService.user.avatar_url"
alt=
"image"
></a>
<a
href=
"#"
class=
"profile"
><img
id=
"avatar"
[src]=
"loginService.user.avatar_url"
alt=
"image"
></a>
<a
href=
"#"
class=
"profile item"
id=
"username"
>
{{loginService.user.username}}
</a>
<a
href=
"#"
class=
"profile item"
id=
"username"
>
{{loginService.user.username}}
</a>
<a
href=
"#"
(click)=
"loginService.logout()"
class=
"item"
>
切换账号
</a>
<a
href=
"#"
(click)=
"loginService.logout()"
class=
"item"
>
切换账号
</a>
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
</div>
</div>
</div>
</div>
</nav>
</nav>
<login
class=
"page"
*ngIf=
"!loginService.user"
></login>
<login
class=
"page"
*ngIf=
"!loginService.logged_in"
></login>
<store
class=
"page"
*ngIf=
"loginService.user"
[hidden]=
"currentPage != 'store'"
></store>
<store
class=
"page"
*ngIf=
"loginService.logged_in"
[hidden]=
"currentPage != 'store'"
></store>
<lobby
class=
"page"
*ngIf=
"loginService.user"
[hidden]=
"currentPage != 'lobby'"
></lobby>
<lobby
class=
"page"
*ngIf=
"loginService.logged_in"
[hidden]=
"currentPage != 'lobby'"
></lobby>
<webview
id=
"community"
class=
"page"
*ngIf=
"loginService.user"
[hidden]=
"currentPage != 'community'"
src=
"https://ygobbs.com"
></webview>
<webview
id=
"community"
class=
"page"
*ngIf=
"loginService.logged_in"
[hidden]=
"currentPage != 'community'"
src=
"https://ygobbs.com"
></webview>
\ No newline at end of file
\ No newline at end of file
app/settings.sevices.ts
View file @
14834cc8
...
@@ -6,6 +6,10 @@ import {Injectable} from "@angular/core";
...
@@ -6,6 +6,10 @@ import {Injectable} from "@angular/core";
import
{
remote
}
from
"
electron
"
;
import
{
remote
}
from
"
electron
"
;
import
*
as
path
from
"
path
"
;
import
*
as
path
from
"
path
"
;
interface
Library
{
"
default
"
:
boolean
,
path
:
string
}
@
Injectable
()
@
Injectable
()
export
class
SettingsService
{
export
class
SettingsService
{
...
@@ -16,7 +20,7 @@ export class SettingsService {
...
@@ -16,7 +20,7 @@ export class SettingsService {
path
:
path
.
join
(
remote
.
app
.
getPath
(
"
appData
"
),
"
library
"
)
path
:
path
.
join
(
remote
.
app
.
getPath
(
"
appData
"
),
"
library
"
)
},
},
];
];
libraries
:
{
"
default
"
:
boolean
,
path
:
string
}
[];
libraries
:
Library
[];
getLibraries
()
{
getLibraries
()
{
...
@@ -33,11 +37,16 @@ export class SettingsService {
...
@@ -33,11 +37,16 @@ export class SettingsService {
return
this
.
libraries
;
return
this
.
libraries
;
}
}
getDefaultLibrary
()
{
getDefaultLibrary
()
:
Library
{
if
(
!
this
.
libraries
)
{
if
(
!
this
.
libraries
)
{
this
.
getLibraries
()
this
.
getLibraries
()
}
}
return
this
.
libraries
.
find
((
item
)
=>
item
.
default
===
true
);
let
result
=
this
.
libraries
.
find
((
item
)
=>
item
.
default
===
true
);
if
(
result
)
{
return
result
}
else
{
throw
(
'
no default library found
'
)
}
}
}
static
SETTING_LOCALE
=
"
locale
"
;
static
SETTING_LOCALE
=
"
locale
"
;
...
...
app/ygopro.component.ts
View file @
14834cc8
...
@@ -15,6 +15,7 @@ import {App} from "./app";
...
@@ -15,6 +15,7 @@ import {App} from "./app";
import
{
Http
,
Headers
,
URLSearchParams
}
from
"
@angular/http
"
;
import
{
Http
,
Headers
,
URLSearchParams
}
from
"
@angular/http
"
;
import
"
rxjs/Rx
"
;
import
"
rxjs/Rx
"
;
import
{
ISubscription
}
from
"
rxjs/Subscription
"
;
import
{
ISubscription
}
from
"
rxjs/Subscription
"
;
import
{
AppLocal
}
from
"
./app-local
"
;
declare
var
$
;
declare
var
$
;
...
@@ -45,8 +46,8 @@ interface SystemConf {
...
@@ -45,8 +46,8 @@ interface SystemConf {
}
}
interface
Server
{
interface
Server
{
id
?
:
string
id
:
string
url
?
:
string
url
:
string
address
:
string
address
:
string
port
:
number
port
:
number
}
}
...
@@ -76,7 +77,7 @@ export class YGOProComponent implements OnInit {
...
@@ -76,7 +77,7 @@ export class YGOProComponent implements OnInit {
decks
:
string
[]
=
[];
decks
:
string
[]
=
[];
current_deck
:
string
;
current_deck
:
string
;
system_conf
=
path
.
join
(
this
.
app
.
local
.
path
,
'
system.conf
'
);
system_conf
=
path
.
join
(
(
<
AppLocal
>
this
.
app
.
local
)
.
path
,
'
system.conf
'
);
numfont
=
{
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]};
numfont
=
{
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]};
textfont
=
{
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]};
textfont
=
{
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]};
...
@@ -115,10 +116,10 @@ export class YGOProComponent implements OnInit {
...
@@ -115,10 +116,10 @@ export class YGOProComponent implements OnInit {
let
modal
=
$
(
'
#game-list-modal
'
);
let
modal
=
$
(
'
#game-list-modal
'
);
modal
.
on
(
'
show.bs.modal
'
,
(
event
)
=>
{
modal
.
on
(
'
show.bs.modal
'
,
(
event
)
=>
{
this
.
connections
=
this
.
servers
.
map
((
server
)
=>
{
this
.
connections
=
this
.
servers
.
map
((
server
)
=>
{
let
connection
=
new
WebSocket
(
server
.
url
);
let
connection
=
new
WebSocket
(
server
.
url
);
connection
.
onclose
=
()
=>
{
connection
.
onclose
=
()
=>
{
this
.
rooms
=
this
.
rooms
.
filter
(
room
=>
room
.
server
!=
server
)
this
.
rooms
=
this
.
rooms
.
filter
(
room
=>
room
.
server
!=
server
)
};
};
connection
.
onmessage
=
(
event
)
=>
{
connection
.
onmessage
=
(
event
)
=>
{
let
message
=
JSON
.
parse
(
event
.
data
);
let
message
=
JSON
.
parse
(
event
.
data
);
...
@@ -131,10 +132,10 @@ export class YGOProComponent implements OnInit {
...
@@ -131,10 +132,10 @@ export class YGOProComponent implements OnInit {
this
.
rooms
.
push
(
Object
.
assign
({
server
:
server
},
this
.
default_options
,
message
.
data
));
this
.
rooms
.
push
(
Object
.
assign
({
server
:
server
},
this
.
default_options
,
message
.
data
));
break
;
break
;
case
'
update
'
:
case
'
update
'
:
Object
.
assign
(
this
.
rooms
.
find
(
room
=>
room
.
server
==
server
&&
room
.
id
==
message
.
data
.
id
),
this
.
default_options
,
message
.
data
);
Object
.
assign
(
this
.
rooms
.
find
(
room
=>
room
.
server
==
server
&&
room
.
id
==
message
.
data
.
id
),
this
.
default_options
,
message
.
data
);
break
;
break
;
case
'
delete
'
:
case
'
delete
'
:
this
.
rooms
.
splice
(
this
.
rooms
.
findIndex
(
room
=>
room
.
server
==
server
&&
room
.
id
==
message
.
data
),
1
);
this
.
rooms
.
splice
(
this
.
rooms
.
findIndex
(
room
=>
room
.
server
==
server
&&
room
.
id
==
message
.
data
),
1
);
}
}
this
.
ref
.
detectChanges
()
this
.
ref
.
detectChanges
()
};
};
...
@@ -159,20 +160,20 @@ export class YGOProComponent implements OnInit {
...
@@ -159,20 +160,20 @@ export class YGOProComponent implements OnInit {
};
};
get_decks
():
Promise
<
string
[]
>
{
get_decks
():
Promise
<
string
[]
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readdir
(
path
.
join
(
this
.
app
.
local
.
path
,
'
deck
'
),
(
error
,
files
)
=>
{
fs
.
readdir
(
path
.
join
(
(
<
AppLocal
>
this
.
app
.
local
).
path
,
'
deck
'
),
(
error
,
files
)
=>
{
if
(
error
)
{
if
(
error
)
{
resolve
([])
resolve
([])
}
else
{
}
else
{
resolve
(
files
.
filter
(
file
=>
path
.
extname
(
file
)
==
"
.ydk
"
).
map
(
file
=>
path
.
basename
(
file
,
'
.ydk
'
)));
resolve
(
files
.
filter
(
file
=>
path
.
extname
(
file
)
==
"
.ydk
"
).
map
(
file
=>
path
.
basename
(
file
,
'
.ydk
'
)));
}
}
})
})
})
})
}
}
async
get_font
(
files
:
string
[]):
Promise
<
string
>
{
async
get_font
(
files
:
string
[]):
Promise
<
string
|
undefined
>
{
for
(
let
file
in
files
)
{
for
(
let
file
in
files
)
{
let
found
=
await
new
Promise
((
resolve
)
=>
fs
.
access
(
file
,
fs
.
constants
.
R_OK
,
error
=>
resolve
(
!
error
)));
let
found
=
await
new
Promise
((
resolve
)
=>
fs
.
access
(
file
,
fs
.
constants
.
R_OK
,
error
=>
resolve
(
!
error
)));
if
(
found
)
{
if
(
found
)
{
return
file
;
return
file
;
}
}
...
@@ -180,7 +181,7 @@ export class YGOProComponent implements OnInit {
...
@@ -180,7 +181,7 @@ export class YGOProComponent implements OnInit {
}
}
async
delete_deck
(
deck
)
{
async
delete_deck
(
deck
)
{
await
new
Promise
(
resolve
=>
fs
.
unlink
(
path
.
join
(
this
.
app
.
local
.
path
,
'
deck
'
,
deck
+
'
.ydk
'
),
resolve
));
await
new
Promise
(
resolve
=>
fs
.
unlink
(
path
.
join
(
(
<
AppLocal
>
this
.
app
.
local
)
.
path
,
'
deck
'
,
deck
+
'
.ydk
'
),
resolve
));
return
this
.
refresh
()
return
this
.
refresh
()
}
}
...
@@ -201,7 +202,7 @@ export class YGOProComponent implements OnInit {
...
@@ -201,7 +202,7 @@ export class YGOProComponent implements OnInit {
};
};
load_system_conf
():
Promise
<
SystemConf
>
{
load_system_conf
():
Promise
<
SystemConf
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readFile
(
this
.
system_conf
,
{
encoding
:
'
utf-8
'
},
(
error
,
data
)
=>
{
fs
.
readFile
(
this
.
system_conf
,
{
encoding
:
'
utf-8
'
},
(
error
,
data
)
=>
{
if
(
error
)
return
reject
(
error
);
if
(
error
)
return
reject
(
error
);
resolve
(
ini
.
parse
(
data
));
resolve
(
ini
.
parse
(
data
));
...
@@ -210,7 +211,7 @@ export class YGOProComponent implements OnInit {
...
@@ -210,7 +211,7 @@ export class YGOProComponent implements OnInit {
};
};
save_system_conf
(
data
:
SystemConf
)
{
save_system_conf
(
data
:
SystemConf
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
writeFile
(
this
.
system_conf
,
ini
.
stringify
(
data
,
<
EncodeOptions
>
{
whitespace
:
true
}),
(
error
)
=>
{
fs
.
writeFile
(
this
.
system_conf
,
ini
.
stringify
(
data
,
<
EncodeOptions
>
{
whitespace
:
true
}),
(
error
)
=>
{
if
(
error
)
return
reject
(
error
);
if
(
error
)
return
reject
(
error
);
resolve
(
data
);
resolve
(
data
);
...
@@ -245,13 +246,13 @@ export class YGOProComponent implements OnInit {
...
@@ -245,13 +246,13 @@ export class YGOProComponent implements OnInit {
start_game
(
args
)
{
start_game
(
args
)
{
let
win
=
remote
.
getCurrentWindow
();
let
win
=
remote
.
getCurrentWindow
();
win
.
minimize
();
win
.
minimize
();
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
child
=
child_process
.
spawn
(
path
.
join
(
this
.
app
.
local
.
path
,
this
.
app
.
actions
.
get
(
'
main
'
).
execute
),
args
,
{
cwd
:
this
.
app
.
local
.
path
});
let
child
=
child_process
.
spawn
(
path
.
join
(
(
<
AppLocal
>
this
.
app
.
local
).
path
,
(
<
any
>
this
.
app
.
actions
.
get
(
'
main
'
)).
execute
),
args
,
{
cwd
:
(
<
AppLocal
>
this
.
app
.
local
)
.
path
});
child
.
on
(
'
error
'
,
(
error
)
=>
{
child
.
on
(
'
error
'
,
(
error
)
=>
{
reject
(
error
);
reject
(
error
);
win
.
restore
()
win
.
restore
()
});
});
child
.
on
(
'
exit
'
,
(
code
,
signal
)
=>
{
child
.
on
(
'
exit
'
,
(
code
,
signal
)
=>
{
// error 触发之后还可能会触发exit,但是Promise只承认首次状态转移,因此这里无需重复判断是否已经error过。
// error 触发之后还可能会触发exit,但是Promise只承认首次状态转移,因此这里无需重复判断是否已经error过。
resolve
();
resolve
();
win
.
restore
()
win
.
restore
()
...
@@ -315,22 +316,22 @@ export class YGOProComponent implements OnInit {
...
@@ -315,22 +316,22 @@ export class YGOProComponent implements OnInit {
this
.
matching
=
this
.
http
.
post
(
'
https://mycard.moe/ygopro/match
'
,
null
,
{
this
.
matching
=
this
.
http
.
post
(
'
https://mycard.moe/ygopro/match
'
,
null
,
{
headers
:
headers
,
headers
:
headers
,
search
:
search
search
:
search
}).
map
(
response
=>
response
.
json
())
}).
map
(
response
=>
response
.
json
())
.
subscribe
((
data
)
=>
{
.
subscribe
((
data
)
=>
{
this
.
join
(
data
[
'
password
'
],
{
this
.
join
(
data
[
'
password
'
],
{
address
:
data
[
'
address
'
],
address
:
data
[
'
address
'
],
port
:
data
[
'
port
'
]
port
:
data
[
'
port
'
]
});
});
},
(
error
)
=>
{
},
(
error
)
=>
{
alert
(
`匹配失败\n
${
error
}
`
)
alert
(
`匹配失败\n
${
error
}
`
)
},
()
=>
{
},
()
=>
{
this
.
matching
=
null
;
this
.
matching
=
null
;
this
.
matching_arena
=
null
;
this
.
matching_arena
=
null
;
});
});
}
}
cancel_match
()
{
cancel_match
()
{
this
.
matching
.
unsubscribe
();
(
<
ISubscription
>
this
.
matching
)
.
unsubscribe
();
this
.
matching
=
null
;
this
.
matching
=
null
;
this
.
matching_arena
=
null
;
this
.
matching_arena
=
null
;
}
}
...
...
tsconfig.json
View file @
14834cc8
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
"emitDecoratorMetadata"
:
true
,
"emitDecoratorMetadata"
:
true
,
"experimentalDecorators"
:
true
,
"experimentalDecorators"
:
true
,
"removeComments"
:
false
,
"removeComments"
:
false
,
"noImplicitAny"
:
false
"noImplicitAny"
:
false
,
"strictNullChecks"
:
true
,
"skipLibCheck"
:
true
}
}
}
}
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