From 615459efb4a4defaf0f386e59b84f6de5f3b30dd Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Wed, 17 Apr 2024 22:04:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=8D=9313=E6=9D=83=E9=99=90=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=9E=8B=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_modules/@types/noname-typings/index.d.ts | 2 + .../@types/noname-typings/windowEx.d.ts | 2 + noname/init/cordova.js | 38 ++++++++++++------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/node_modules/@types/noname-typings/index.d.ts b/node_modules/@types/noname-typings/index.d.ts index 387ebd5ce..c89de0bb4 100644 --- a/node_modules/@types/noname-typings/index.d.ts +++ b/node_modules/@types/noname-typings/index.d.ts @@ -9,6 +9,8 @@ /// /// /// +/// +/// /// /// /// diff --git a/node_modules/@types/noname-typings/windowEx.d.ts b/node_modules/@types/noname-typings/windowEx.d.ts index fca9c3721..f089f6478 100644 --- a/node_modules/@types/noname-typings/windowEx.d.ts +++ b/node_modules/@types/noname-typings/windowEx.d.ts @@ -70,4 +70,6 @@ declare interface Window { initReadWriteFunction?(game: Game): Promise; bannedKeyWords: string[]; + + device: Device; } diff --git a/noname/init/cordova.js b/noname/init/cordova.js index 73e8904b2..97da9302a 100644 --- a/noname/init/cordova.js +++ b/noname/init/cordova.js @@ -1,10 +1,10 @@ -// @ts-nocheck import { get } from "../get/index.js"; import { lib } from "../library/index.js"; import { game } from "../game/index.js"; import { _status } from "../status/index.js"; import { ui } from "../ui/index.js"; import { nonameInitialized } from "../util/index.js"; +import { checkVersion } from "../library/update.js"; export async function cordovaReady() { if (lib.device == "android") { @@ -49,18 +49,30 @@ export async function cordovaReady() { if ("cordova" in window && "plugins" in window.cordova && "permissions" in window.cordova.plugins) { const permissions = cordova.plugins.permissions; const requests = ["WRITE_EXTERNAL_STORAGE", "READ_EXTERNAL_STORAGE"]; - requests.forEach((request) => { - permissions.checkPermission( - permissions[request], - (status) => { - if (!status.hasPermission) { - permissions.requestPermission( - permissions[request], - lib.other.ignore, - lib.other.ignore - ); - } - }, + if (typeof device == 'object') { + // 安卓13或以上 + if (checkVersion(device.version, "13") >= 0) { + requests.length = 0; + requests.push('READ_MEDIA_IMAGES', 'READ_MEDIA_VIDEO', 'READ_MEDIA_AUDIO'); + } + } + Promise.all(requests.map(request => { + return new Promise((resolve, reject) => { + permissions.checkPermission(permissions[request], status => { + resolve({ + request: request, + hasPermission: status.hasPermission + }); + }, lib.other.ignore); + }); + })).then(shouldRequestPermissions => { + return shouldRequestPermissions + .filter(({ hasPermission }) => !hasPermission) + .map(({ request }) => permissions[request]); + }).then(willRequestPermissions => { + permissions.requestPermissions( + willRequestPermissions, + lib.other.ignore, lib.other.ignore ); });