Skip to content

Commit

Permalink
fix: 截图权限申请
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebartin committed Jun 1, 2024
1 parent 22db16f commit c4448ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions NIKKE/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- 结束应用失败;
- 爬塔战斗结束后卡住;
- 特拦队伍识别;
- 截图权限申请问题;

新增功能:

Expand Down
33 changes: 27 additions & 6 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function getDisplaySize(doNotForcePortrait) {
const img = captureScreen();
return [img.width, img.height];
} catch (e) {
if (!e.message.includes('No screen capture permission')) {
const errorStr = e.toString();
if (!errorStr.includes('No screen capture permission') &&
!errorStr.includes('ScreenCapturer is not available')) {
throw e;
}
}
Expand Down Expand Up @@ -551,7 +553,25 @@ function enterPwd(pwd) {
}

function requestScreenCaptureAuto(ensureImg) {
let testImg;
try {
testImg = captureScreen();
if (!ensureImg || ensureImg(testImg))
return;
log(`截图异常,截图大小:${testImg.width}x${testImg.height}`);
if (!images.stopScreenCapturer) {
exit();
}
images.stopScreenCapturer();
} catch (e) {
const errorStr = e.toString();
if (!errorStr.includes('No screen capture permission') &&
!errorStr.includes('ScreenCapturer is not available')) {
throw e;
}
}
let hasPermission = false;
const [w, h] = getDisplaySize();
let confirmRequest = () => {
//安卓版本高于Android 9
if (hasPermission || device.sdkInt <= 28) {
Expand All @@ -574,13 +594,15 @@ function requestScreenCaptureAuto(ensureImg) {
log('找到取消按钮');
const cancelBounds = cancel.get(0).bounds();
t = new android.graphics.Rect(
device.width - cancelBounds.right,
w - cancelBounds.right,
cancelBounds.top,
device.width - cancelBounds.left,
w - cancelBounds.left,
cancelBounds.bottom
);
}
if (t.top < t.bottom && (device.height == 0 || t.bottom <= device.height)) {
if (t)
log(t);
if (t && t.top < t.bottom && (h == 0 || t.top <= h + 200)) {
target = { bounds: t };
break;
}
Expand All @@ -589,7 +611,6 @@ function requestScreenCaptureAuto(ensureImg) {
console.error('处理截图权限弹窗失败');
return;
}
log(`点击区域:${target.bounds}`);
for (let i = 0; i < 10; ++i) {
if (hasPermission)
return;
Expand All @@ -612,7 +633,7 @@ function requestScreenCaptureAuto(ensureImg) {
hasPermission = true;
return;
}
const testImg = captureScreen();
testImg = captureScreen();
if (ensureImg(testImg)) {
hasPermission = true;
return;
Expand Down

0 comments on commit c4448ac

Please sign in to comment.