Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
57620c77
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
57620c77
编写于
9月 23, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): automator screenshot
上级
1a737a99
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
packages/uni-app-plus/lib/uni.automator.js
packages/uni-app-plus/lib/uni.automator.js
+1
-1
未找到文件。
packages/uni-app-plus/lib/uni.automator.js
浏览文件 @
57620c77
"
use strict
"
;
var
t
=
require
(
"
fs
"
),
e
=
require
(
"
debug
"
),
s
=
require
(
"
licia/sleep
"
),
i
=
require
(
"
postcss-selector-parser
"
),
a
=
require
(
"
fs-extra
"
),
r
=
require
(
"
licia/dateFormat
"
),
o
=
require
(
"
path
"
),
n
=
require
(
"
util
"
),
l
=
require
(
"
jimp
"
);
function
c
(
t
){
return
t
&&
"
object
"
==
typeof
t
&&
"
default
"
in
t
?
t
:{
default
:
t
}}
var
d
=
c
(
t
),
u
=
c
(
e
),
h
=
c
(
s
),
p
=
c
(
i
),
y
=
c
(
a
),
m
=
c
(
r
),
f
=
c
(
l
);
function
v
(
t
){
t
.
walk
((
t
=>
{
if
(
"
tag
"
===
t
.
type
){
const
e
=
t
.
value
;
t
.
value
=
"
page
"
===
e
?
"
body
"
:
"
uni-
"
+
e
}}))}
u
.
default
(
"
automator:devtool
"
);
const
M
=
[
"
Page.getElement
"
,
"
Page.getElements
"
,
"
Element.getElement
"
,
"
Element.getElements
"
];
const
$
=
/^win/
.
test
(
process
.
platform
);
function
g
(
t
){
try
{
return
require
(
t
)}
catch
(
e
){
return
require
(
require
.
resolve
(
t
,{
paths
:[
process
.
cwd
()]}))}}
const
w
=
u
.
default
(
"
automator:launcher
"
),
P
=
n
.
promisify
(
d
.
default
.
readdir
),
A
=
n
.
promisify
(
d
.
default
.
stat
);
async
function
E
(
t
){
const
e
=
await
P
(
t
);
return
(
await
Promise
.
all
(
e
.
map
((
async
e
=>
{
const
s
=
o
.
resolve
(
t
,
e
);
return
(
await
A
(
s
)).
isDirectory
()?
E
(
s
):
s
})))).
reduce
(((
t
,
e
)
=>
t
.
concat
(
e
)),[])}
class
H
{
constructor
(
t
){
this
.
isX
=!
1
,
"
true
"
===
process
.
env
.
UNI_APP_X
&&
(
this
.
isX
=!
0
),
this
.
id
=
t
.
id
,
this
.
app
=
t
.
executablePath
,
this
.
appid
=
t
.
appid
||
process
.
env
.
UNI_APP_ID
||
"
HBuilder
"
,
this
.
package
=
t
.
package
||
(
this
.
isX
?
"
io.dcloud.uniappx
"
:
"
io.dcloud.HBuilder
"
),
this
.
activity
=
t
.
activity
||
(
this
.
isX
?
"
io.dcloud.uniapp.UniAppActivity
"
:
"
io.dcloud.PandoraEntry
"
)}
shouldPush
(){
return
this
.
exists
(
this
.
FILE_APP_SERVICE
).
then
((()
=>
(
w
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
exists`
),
!
1
))).
catch
((()
=>
(
w
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
not exists`
),
!
0
)))}
push
(
t
){
return
E
(
t
).
then
((
e
=>
{
const
s
=
e
.
map
((
e
=>
{
const
s
=
(
t
=>
$
?
t
.
replace
(
/
\\
/g
,
"
/
"
):
t
)(
o
.
join
(
this
.
DIR_WWW
,
o
.
relative
(
t
,
e
)));
return
w
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
push
${
e
}
${
s
}
`
),
this
.
pushFile
(
e
,
s
)}));
return
Promise
.
all
(
s
)})).
then
((
t
=>!
0
))}
get
FILE_APP_SERVICE
(){
return
`
${
this
.
DIR_WWW
}
/app-service.js`
}}
const
S
=
u
.
default
(
"
automator:simctl
"
);
function
_
(
t
){
const
e
=
parseInt
(
t
);
return
e
>
9
?
String
(
e
):
"
0
"
+
e
}
class
x
extends
H
{
constructor
(){
super
(...
arguments
),
this
.
bundleVersion
=
""
}
async
init
(){
const
t
=
g
(
"
node-simctl
"
).
Simctl
;
this
.
tool
=
new
t
({
udid
:
this
.
id
});
try
{
await
this
.
tool
.
bootDevice
()}
catch
(
t
){}
await
this
.
initSDCard
(),
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
`
)}
async
initSDCard
(){
const
t
=
await
this
.
tool
.
appInfo
(
this
.
package
);
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
appInfo
${
t
}
`
);
const
e
=
t
.
match
(
/DataContainer
\s
+=
\s
+"
(
.*
)
"/
);
if
(
!
e
)
return
Promise
.
resolve
(
""
);
const
s
=
t
.
match
(
/CFBundleVersion
\s
+=
\s
+
(
.*
)
;/
);
if
(
!
s
)
return
Promise
.
resolve
(
""
);
this
.
sdcard
=
e
[
1
].
replace
(
"
file:
"
,
""
),
this
.
bundleVersion
=
s
[
1
],
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
sdcard
}
`
)}
async
version
(){
return
Promise
.
resolve
(
this
.
bundleVersion
)}
formatVersion
(
t
){
const
e
=
t
.
split
(
"
.
"
);
return
3
!==
e
.
length
?
t
:
e
[
0
]
+
_
(
e
[
1
])
+
_
(
e
[
2
])}
async
install
(){
return
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
`
),
await
this
.
tool
.
installApp
(
this
.
app
),
await
this
.
tool
.
grantPermission
(
this
.
package
,
"
all
"
),
await
this
.
initSDCard
(),
Promise
.
resolve
(
!
0
)}
async
start
(){
try
{
await
this
.
tool
.
terminateApp
(
this
.
package
)}
catch
(
t
){}
try
{
await
this
.
tool
.
launchApp
(
this
.
package
)}
catch
(
t
){
console
.
error
(
t
)}
return
Promise
.
resolve
(
!
0
)}
async
exit
(){
return
await
this
.
tool
.
terminateApp
(
this
.
package
),
await
this
.
tool
.
shutdownDevice
(),
Promise
.
resolve
(
!
0
)}
async
captureScreenshot
(){
return
Promise
.
resolve
(
await
this
.
tool
.
getScreenshot
())}
exists
(
t
){
return
y
.
default
.
existsSync
(
t
)?
Promise
.
resolve
(
!
0
):
Promise
.
reject
(
Error
(
`
${
t
}
not exists`
))}
pushFile
(
t
,
e
){
return
Promise
.
resolve
(
y
.
default
.
copySync
(
t
,
e
))}
get
DIR_WWW
(){
return
`
${
this
.
sdcard
}
/Documents/Pandora/apps/
${
this
.
appid
}
/www/`
}}
const
D
=
g
(
"
adbkit
"
),
b
=
u
.
default
(
"
automator:adb
"
);
class
I
extends
H
{
async
init
(){
if
(
this
.
tool
=
D
.
createClient
(),
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
await
this
.
tool
.
version
()}
`
),
!
this
.
id
){
const
t
=
await
this
.
tool
.
listDevices
();
if
(
!
t
.
length
)
throw
Error
(
"
Device not found
"
);
this
.
id
=
t
[
0
].
id
}
this
.
sdcard
=
(
await
this
.
shell
(
this
.
COMMAND_EXTERNAL
)).
trim
(),
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
${
this
.
sdcard
}
`
)}
root
(){
return
this
.
tool
.
root
(
this
.
id
).
then
((()
=>
{
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
this
.
sdcard
}
`
)})).
catch
((
t
=>
{
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
t
}
`
)}))}
version
(){
return
this
.
shell
(
this
.
COMMAND_VERSION
).
then
((
t
=>
{
const
e
=
t
.
match
(
/versionName=
(
.*
)
/
);
return
e
&&
e
.
length
>
1
?
e
[
1
]:
""
}))}
formatVersion
(
t
){
return
t
}
async
install
(){
let
t
=!
0
;
try
{
const
e
=
(
await
this
.
tool
.
getProperties
(
this
.
id
))[
"
ro.build.version.release
"
].
split
(
"
.
"
)[
0
];
parseInt
(
e
)
<
6
&&
(
t
=!
1
)}
catch
(
t
){}
if
(
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
permission=
${
t
}
`
),
t
){
const
t
=
g
(
"
adbkit/lib/adb/command.js
"
),
e
=
t
.
prototype
.
_send
;
t
.
prototype
.
_send
=
function
(
t
){
return
0
===
t
.
indexOf
(
"
shell:pm install -r
"
)
&&
(
t
=
t
.
replace
(
"
shell:pm install -r
"
,
"
shell:pm install -r -g
"
),
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
t
}
`
)),
e
.
call
(
this
,
t
)}}
return
this
.
tool
.
install
(
this
.
id
,
this
.
app
).
then
((()
=>
{
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
installed`
),
this
.
init
()}))}
start
(){
return
this
.
exit
().
then
((()
=>
this
.
shell
(
this
.
COMMAND_START
)))}
exit
(){
return
this
.
shell
(
this
.
COMMAND_STOP
)}
captureScreenshot
(
t
){
return
this
.
tool
.
screencap
(
this
.
id
).
then
((
e
=>
new
Promise
(((
s
,
i
)
=>
{
const
a
=
[];
e
.
on
(
"
data
"
,(
function
(
t
){
a
.
push
(
t
)})),
e
.
on
(
"
end
"
,(
function
(){
var
e
,
r
;
(
null
===
(
e
=
t
.
area
)
||
void
0
===
e
?
void
0
:
e
.
x
)
&&
(
null
===
(
r
=
t
.
area
)
||
void
0
===
r
?
void
0
:
r
.
y
)?
f
.
default
.
read
(
Buffer
.
concat
(
a
)).
then
((
e
=>
{
var
a
,
r
,
o
,
n
;
const
l
=
t
.
area
.
x
,
c
=
t
.
area
.
y
;
let
d
=
e
.
bitmap
.
width
-
l
;(
null
===
(
a
=
t
.
area
)
||
void
0
===
a
?
void
0
:
a
.
width
)
&&
(
d
=
Math
.
min
(
d
,
null
===
(
r
=
t
.
area
)
||
void
0
===
r
?
void
0
:
r
.
width
));
let
u
=
e
.
bitmap
.
height
-
c
;(
null
===
(
o
=
t
.
area
)
||
void
0
===
o
?
void
0
:
o
.
height
)
&&
(
u
=
Math
.
min
(
u
,
null
===
(
n
=
t
.
area
)
||
void
0
===
n
?
void
0
:
n
.
height
)),
e
.
crop
(
l
,
c
,
d
,
u
).
getBase64Async
(
f
.
default
.
MIME_PNG
).
then
((
t
=>
{
s
(
t
.
replace
(
"
data:image/png;base64,
"
,
""
))})).
catch
((
t
=>
{
i
(
t
)}))})).
catch
((
t
=>
{
i
(
t
)})):
s
(
Buffer
.
concat
(
a
).
toString
(
"
base64
"
))}))}))))}
exists
(
t
){
return
this
.
tool
.
stat
(
this
.
id
,
t
)}
pushFile
(
t
,
e
){
return
this
.
tool
.
push
(
this
.
id
,
t
,
e
)}
shell
(
t
){
return
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
SEND ►
${
t
}
`
),
this
.
tool
.
shell
(
this
.
id
,
t
).
then
(
D
.
util
.
readAll
).
then
((
t
=>
{
const
e
=
t
.
toString
();
return
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
◀ RECV
${
e
}
`
),
e
}))}
get
DIR_WWW
(){
return
`/storage/emulated/0/Android/data/
${
this
.
package
}
/apps/
${
this
.
appid
}
/www`
}
get
COMMAND_EXTERNAL
(){
return
"
echo $EXTERNAL_STORAGE
"
}
get
COMMAND_VERSION
(){
return
`dumpsys package
${
this
.
package
}
`
}
get
COMMAND_STOP
(){
return
`am force-stop
${
this
.
package
}
`
}
get
COMMAND_START
(){
return
`am start -n
${
this
.
package
}
/
${
this
.
activity
}
--es appid
${
this
.
appid
}
--ez needUpdateApp false --ez reload true --ez externalStorage true`
}}
const
C
=
u
.
default
(
"
automator:devtool
"
);
let
N
,
R
=!
1
;
const
O
=
{
android
:
/android_version=
(
.*
)
/
,
ios
:
/iphone_version=
(
.*
)
/
};
const
k
=
{
"
Tool.close
"
:{
reflect
:
async
()
=>
{}},
"
App.exit
"
:{
reflect
:
async
()
=>
N
.
exit
()},
"
App.enableLog
"
:{
reflect
:()
=>
Promise
.
resolve
()},
"
App.captureScreenshotWithADB
"
:{
reflect
:
async
(
t
,
e
)
=>
{
const
s
=
await
N
.
captureScreenshot
(
e
);
return
C
(
`App.captureScreenshot
${
s
.
length
}
`
),{
data
:
s
}}}};
!
function
(
t
){
M
.
forEach
((
e
=>
{
t
[
e
]
=
function
(
t
){
return
{
reflect
:
async
(
e
,
s
)
=>
e
(
t
,
s
,
!
1
),
params
:
t
=>
(
t
.
selector
&&
(
t
.
selector
=
p
.
default
(
v
).
processSync
(
t
.
selector
)),
t
)}}(
e
)}))}(
k
);
const
V
=
{
devtools
:{
name
:
"
App
"
,
paths
:[],
required
:[
"
manifest.json
"
,
"
app-service.js
"
],
validate
:
async
function
(
t
,
e
){
t
.
platform
=
(
t
.
platform
||
process
.
env
.
UNI_OS_NAME
).
toLocaleLowerCase
(),
Object
.
assign
(
t
,
t
[
t
.
platform
]),
N
=
function
(
t
,
e
){
return
"
ios
"
===
t
?
new
x
(
e
):
new
I
(
e
)}(
t
.
platform
,
t
),
await
N
.
init
();
const
s
=
await
N
.
version
();
if
(
s
){
if
(
t
.
version
){
const
e
=
N
.
formatVersion
(
function
(
t
,
e
){
if
(
t
.
endsWith
(
"
.txt
"
))
try
{
const
s
=
d
.
default
.
readFileSync
(
t
).
toString
().
match
(
O
[
e
]);
if
(
s
)
return
s
[
1
]}
catch
(
t
){
console
.
error
(
t
)}
return
t
}(
t
.
version
,
t
.
platform
));
C
(
`version:
${
s
}
`
),
C
(
`newVersion:
${
e
}
`
),
e
!==
s
&&
(
R
=!
0
)}}
else
R
=!
0
;
if
(
R
){
if
(
!
t
.
executablePath
)
throw
Error
(
`app-plus->
${
t
.
platform
}
->executablePath is not provided`
);
if
(
!
d
.
default
.
existsSync
(
t
.
executablePath
))
throw
Error
(
`
${
t
.
executablePath
}
not exists`
)}
return
t
},
create
:
async
function
(
t
,
e
,
s
){
R
&&
await
N
.
install
(),(
R
||
s
.
compiled
||
await
N
.
shouldPush
())
&&
(
await
N
.
push
(
t
),
await
h
.
default
(
1
e3
)),
await
N
.
start
()}},
adapter
:
k
};
module
.
exports
=
V
;
"
use strict
"
;
var
t
=
require
(
"
fs
"
),
e
=
require
(
"
debug
"
),
s
=
require
(
"
licia/sleep
"
),
i
=
require
(
"
postcss-selector-parser
"
),
a
=
require
(
"
fs-extra
"
),
r
=
require
(
"
licia/dateFormat
"
),
o
=
require
(
"
path
"
),
n
=
require
(
"
util
"
),
l
=
require
(
"
jimp
"
);
function
c
(
t
){
return
t
&&
"
object
"
==
typeof
t
&&
"
default
"
in
t
?
t
:{
default
:
t
}}
var
d
=
c
(
t
),
u
=
c
(
e
),
h
=
c
(
s
),
p
=
c
(
i
),
y
=
c
(
a
),
m
=
c
(
r
),
f
=
c
(
l
);
function
v
(
t
){
t
.
walk
((
t
=>
{
if
(
"
tag
"
===
t
.
type
){
const
e
=
t
.
value
;
t
.
value
=
"
page
"
===
e
?
"
body
"
:
"
uni-
"
+
e
}}))}
u
.
default
(
"
automator:devtool
"
);
const
M
=
[
"
Page.getElement
"
,
"
Page.getElements
"
,
"
Element.getElement
"
,
"
Element.getElements
"
];
const
$
=
/^win/
.
test
(
process
.
platform
);
function
g
(
t
){
try
{
return
require
(
t
)}
catch
(
e
){
return
require
(
require
.
resolve
(
t
,{
paths
:[
process
.
cwd
()]}))}}
const
w
=
u
.
default
(
"
automator:launcher
"
),
P
=
n
.
promisify
(
d
.
default
.
readdir
),
A
=
n
.
promisify
(
d
.
default
.
stat
);
async
function
E
(
t
){
const
e
=
await
P
(
t
);
return
(
await
Promise
.
all
(
e
.
map
((
async
e
=>
{
const
s
=
o
.
resolve
(
t
,
e
);
return
(
await
A
(
s
)).
isDirectory
()?
E
(
s
):
s
})))).
reduce
(((
t
,
e
)
=>
t
.
concat
(
e
)),[])}
class
H
{
constructor
(
t
){
this
.
isX
=!
1
,
"
true
"
===
process
.
env
.
UNI_APP_X
&&
(
this
.
isX
=!
0
),
this
.
id
=
t
.
id
,
this
.
app
=
t
.
executablePath
,
this
.
appid
=
t
.
appid
||
process
.
env
.
UNI_APP_ID
||
"
HBuilder
"
,
this
.
package
=
t
.
package
||
(
this
.
isX
?
"
io.dcloud.uniappx
"
:
"
io.dcloud.HBuilder
"
),
this
.
activity
=
t
.
activity
||
(
this
.
isX
?
"
io.dcloud.uniapp.UniAppActivity
"
:
"
io.dcloud.PandoraEntry
"
)}
shouldPush
(){
return
this
.
exists
(
this
.
FILE_APP_SERVICE
).
then
((()
=>
(
w
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
exists`
),
!
1
))).
catch
((()
=>
(
w
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
this
.
FILE_APP_SERVICE
}
not exists`
),
!
0
)))}
push
(
t
){
return
E
(
t
).
then
((
e
=>
{
const
s
=
e
.
map
((
e
=>
{
const
s
=
(
t
=>
$
?
t
.
replace
(
/
\\
/g
,
"
/
"
):
t
)(
o
.
join
(
this
.
DIR_WWW
,
o
.
relative
(
t
,
e
)));
return
w
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
push
${
e
}
${
s
}
`
),
this
.
pushFile
(
e
,
s
)}));
return
Promise
.
all
(
s
)})).
then
((
t
=>!
0
))}
get
FILE_APP_SERVICE
(){
return
`
${
this
.
DIR_WWW
}
/app-service.js`
}}
const
S
=
u
.
default
(
"
automator:simctl
"
);
function
_
(
t
){
const
e
=
parseInt
(
t
);
return
e
>
9
?
String
(
e
):
"
0
"
+
e
}
class
x
extends
H
{
constructor
(){
super
(...
arguments
),
this
.
bundleVersion
=
""
}
async
init
(){
const
t
=
g
(
"
node-simctl
"
).
Simctl
;
this
.
tool
=
new
t
({
udid
:
this
.
id
});
try
{
await
this
.
tool
.
bootDevice
()}
catch
(
t
){}
await
this
.
initSDCard
(),
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
`
)}
async
initSDCard
(){
const
t
=
await
this
.
tool
.
appInfo
(
this
.
package
);
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
appInfo
${
t
}
`
);
const
e
=
t
.
match
(
/DataContainer
\s
+=
\s
+"
(
.*
)
"/
);
if
(
!
e
)
return
Promise
.
resolve
(
""
);
const
s
=
t
.
match
(
/CFBundleVersion
\s
+=
\s
+
(
.*
)
;/
);
if
(
!
s
)
return
Promise
.
resolve
(
""
);
this
.
sdcard
=
e
[
1
].
replace
(
"
file:
"
,
""
),
this
.
bundleVersion
=
s
[
1
],
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
sdcard
}
`
)}
async
version
(){
return
Promise
.
resolve
(
this
.
bundleVersion
)}
formatVersion
(
t
){
const
e
=
t
.
split
(
"
.
"
);
return
3
!==
e
.
length
?
t
:
e
[
0
]
+
_
(
e
[
1
])
+
_
(
e
[
2
])}
async
install
(){
return
S
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
`
),
await
this
.
tool
.
installApp
(
this
.
app
),
await
this
.
tool
.
grantPermission
(
this
.
package
,
"
all
"
),
await
this
.
initSDCard
(),
Promise
.
resolve
(
!
0
)}
async
start
(){
try
{
await
this
.
tool
.
terminateApp
(
this
.
package
)}
catch
(
t
){}
try
{
await
this
.
tool
.
launchApp
(
this
.
package
)}
catch
(
t
){
console
.
error
(
t
)}
return
Promise
.
resolve
(
!
0
)}
async
exit
(){
return
await
this
.
tool
.
terminateApp
(
this
.
package
),
await
this
.
tool
.
shutdownDevice
(),
Promise
.
resolve
(
!
0
)}
async
captureScreenshot
(){
return
Promise
.
resolve
(
await
this
.
tool
.
getScreenshot
())}
exists
(
t
){
return
y
.
default
.
existsSync
(
t
)?
Promise
.
resolve
(
!
0
):
Promise
.
reject
(
Error
(
`
${
t
}
not exists`
))}
pushFile
(
t
,
e
){
return
Promise
.
resolve
(
y
.
default
.
copySync
(
t
,
e
))}
get
DIR_WWW
(){
return
`
${
this
.
sdcard
}
/Documents/Pandora/apps/
${
this
.
appid
}
/www/`
}}
const
D
=
g
(
"
adbkit
"
),
b
=
u
.
default
(
"
automator:adb
"
);
class
I
extends
H
{
async
init
(){
if
(
this
.
tool
=
D
.
createClient
(),
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
await
this
.
tool
.
version
()}
`
),
!
this
.
id
){
const
t
=
await
this
.
tool
.
listDevices
();
if
(
!
t
.
length
)
throw
Error
(
"
Device not found
"
);
this
.
id
=
t
[
0
].
id
}
this
.
sdcard
=
(
await
this
.
shell
(
this
.
COMMAND_EXTERNAL
)).
trim
(),
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
init
${
this
.
id
}
${
this
.
sdcard
}
`
)}
root
(){
return
this
.
tool
.
root
(
this
.
id
).
then
((()
=>
{
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
this
.
sdcard
}
`
)})).
catch
((
t
=>
{
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
root
${
this
.
id
}
${
t
}
`
)}))}
version
(){
return
this
.
shell
(
this
.
COMMAND_VERSION
).
then
((
t
=>
{
const
e
=
t
.
match
(
/versionName=
(
.*
)
/
);
return
e
&&
e
.
length
>
1
?
e
[
1
]:
""
}))}
formatVersion
(
t
){
return
t
}
async
install
(){
let
t
=!
0
;
try
{
const
e
=
(
await
this
.
tool
.
getProperties
(
this
.
id
))[
"
ro.build.version.release
"
].
split
(
"
.
"
)[
0
];
parseInt
(
e
)
<
6
&&
(
t
=!
1
)}
catch
(
t
){}
if
(
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
install
${
this
.
app
}
permission=
${
t
}
`
),
t
){
const
t
=
g
(
"
adbkit/lib/adb/command.js
"
),
e
=
t
.
prototype
.
_send
;
t
.
prototype
.
_send
=
function
(
t
){
return
0
===
t
.
indexOf
(
"
shell:pm install -r
"
)
&&
(
t
=
t
.
replace
(
"
shell:pm install -r
"
,
"
shell:pm install -r -g
"
),
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
${
t
}
`
)),
e
.
call
(
this
,
t
)}}
return
this
.
tool
.
install
(
this
.
id
,
this
.
app
).
then
((()
=>
{
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
installed`
),
this
.
init
()}))}
start
(){
return
this
.
exit
().
then
((()
=>
this
.
shell
(
this
.
COMMAND_START
)))}
exit
(){
return
this
.
shell
(
this
.
COMMAND_STOP
)}
captureScreenshot
(
t
){
return
this
.
tool
.
screencap
(
this
.
id
).
then
((
e
=>
new
Promise
(((
s
,
i
)
=>
{
const
a
=
[];
e
.
on
(
"
data
"
,(
function
(
t
){
a
.
push
(
t
)})),
e
.
on
(
"
end
"
,(
function
(){
var
e
,
r
;
void
0
!==
(
null
===
(
e
=
t
.
area
)
||
void
0
===
e
?
void
0
:
e
.
x
)
&&
void
0
!==
(
null
===
(
r
=
t
.
area
)
||
void
0
===
r
?
void
0
:
r
.
y
)?
f
.
default
.
read
(
Buffer
.
concat
(
a
)).
then
((
e
=>
{
var
a
,
r
,
o
,
n
;
const
l
=
t
.
area
.
x
,
c
=
t
.
area
.
y
;
let
d
=
e
.
bitmap
.
width
-
l
;(
null
===
(
a
=
t
.
area
)
||
void
0
===
a
?
void
0
:
a
.
width
)
&&
(
d
=
Math
.
min
(
d
,
null
===
(
r
=
t
.
area
)
||
void
0
===
r
?
void
0
:
r
.
width
));
let
u
=
e
.
bitmap
.
height
-
c
;(
null
===
(
o
=
t
.
area
)
||
void
0
===
o
?
void
0
:
o
.
height
)
&&
(
u
=
Math
.
min
(
u
,
null
===
(
n
=
t
.
area
)
||
void
0
===
n
?
void
0
:
n
.
height
)),
e
.
crop
(
l
,
c
,
d
,
u
).
getBase64Async
(
f
.
default
.
MIME_PNG
).
then
((
t
=>
{
s
(
t
.
replace
(
"
data:image/png;base64,
"
,
""
))})).
catch
((
t
=>
{
i
(
t
)}))})).
catch
((
t
=>
{
i
(
t
)})):
s
(
Buffer
.
concat
(
a
).
toString
(
"
base64
"
))}))}))))}
exists
(
t
){
return
this
.
tool
.
stat
(
this
.
id
,
t
)}
pushFile
(
t
,
e
){
return
this
.
tool
.
push
(
this
.
id
,
t
,
e
)}
shell
(
t
){
return
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
SEND ►
${
t
}
`
),
this
.
tool
.
shell
(
this
.
id
,
t
).
then
(
D
.
util
.
readAll
).
then
((
t
=>
{
const
e
=
t
.
toString
();
return
b
(
`
${
m
.
default
(
"
yyyy-mm-dd HH:MM:ss:l
"
)}
◀ RECV
${
e
}
`
),
e
}))}
get
DIR_WWW
(){
return
`/storage/emulated/0/Android/data/
${
this
.
package
}
/apps/
${
this
.
appid
}
/www`
}
get
COMMAND_EXTERNAL
(){
return
"
echo $EXTERNAL_STORAGE
"
}
get
COMMAND_VERSION
(){
return
`dumpsys package
${
this
.
package
}
`
}
get
COMMAND_STOP
(){
return
`am force-stop
${
this
.
package
}
`
}
get
COMMAND_START
(){
return
`am start -n
${
this
.
package
}
/
${
this
.
activity
}
--es appid
${
this
.
appid
}
--ez needUpdateApp false --ez reload true --ez externalStorage true`
}}
const
C
=
u
.
default
(
"
automator:devtool
"
);
let
N
,
R
=!
1
;
const
O
=
{
android
:
/android_version=
(
.*
)
/
,
ios
:
/iphone_version=
(
.*
)
/
};
const
k
=
{
"
Tool.close
"
:{
reflect
:
async
()
=>
{}},
"
App.exit
"
:{
reflect
:
async
()
=>
N
.
exit
()},
"
App.enableLog
"
:{
reflect
:()
=>
Promise
.
resolve
()},
"
App.captureScreenshotWithADB
"
:{
reflect
:
async
(
t
,
e
)
=>
{
const
s
=
await
N
.
captureScreenshot
(
e
);
return
C
(
`App.captureScreenshot
${
s
.
length
}
`
),{
data
:
s
}}}};
!
function
(
t
){
M
.
forEach
((
e
=>
{
t
[
e
]
=
function
(
t
){
return
{
reflect
:
async
(
e
,
s
)
=>
e
(
t
,
s
,
!
1
),
params
:
t
=>
(
t
.
selector
&&
(
t
.
selector
=
p
.
default
(
v
).
processSync
(
t
.
selector
)),
t
)}}(
e
)}))}(
k
);
const
V
=
{
devtools
:{
name
:
"
App
"
,
paths
:[],
required
:[
"
manifest.json
"
,
"
app-service.js
"
],
validate
:
async
function
(
t
,
e
){
t
.
platform
=
(
t
.
platform
||
process
.
env
.
UNI_OS_NAME
).
toLocaleLowerCase
(),
Object
.
assign
(
t
,
t
[
t
.
platform
]),
N
=
function
(
t
,
e
){
return
"
ios
"
===
t
?
new
x
(
e
):
new
I
(
e
)}(
t
.
platform
,
t
),
await
N
.
init
();
const
s
=
await
N
.
version
();
if
(
s
){
if
(
t
.
version
){
const
e
=
N
.
formatVersion
(
function
(
t
,
e
){
if
(
t
.
endsWith
(
"
.txt
"
))
try
{
const
s
=
d
.
default
.
readFileSync
(
t
).
toString
().
match
(
O
[
e
]);
if
(
s
)
return
s
[
1
]}
catch
(
t
){
console
.
error
(
t
)}
return
t
}(
t
.
version
,
t
.
platform
));
C
(
`version:
${
s
}
`
),
C
(
`newVersion:
${
e
}
`
),
e
!==
s
&&
(
R
=!
0
)}}
else
R
=!
0
;
if
(
R
){
if
(
!
t
.
executablePath
)
throw
Error
(
`app-plus->
${
t
.
platform
}
->executablePath is not provided`
);
if
(
!
d
.
default
.
existsSync
(
t
.
executablePath
))
throw
Error
(
`
${
t
.
executablePath
}
not exists`
)}
return
t
},
create
:
async
function
(
t
,
e
,
s
){
R
&&
await
N
.
install
(),(
R
||
s
.
compiled
||
await
N
.
shouldPush
())
&&
(
await
N
.
push
(
t
),
await
h
.
default
(
1
e3
)),
await
N
.
start
()}},
adapter
:
k
};
module
.
exports
=
V
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录