安卓13权限兼容,增加类型文件
This commit is contained in:
parent
4ef4af98af
commit
615459efb4
|
@ -9,6 +9,8 @@
|
||||||
/// <reference path="./type.d.ts" />
|
/// <reference path="./type.d.ts" />
|
||||||
/// <reference path="./MapEx.d.ts" />
|
/// <reference path="./MapEx.d.ts" />
|
||||||
/// <reference types="@types/cordova" />
|
/// <reference types="@types/cordova" />
|
||||||
|
/// <reference path="./cordova-plugin-android-permissions.d.ts" />
|
||||||
|
/// <reference path="./cordova-plugin-device.d.ts" />
|
||||||
/// <reference path="./cordova-plugin-dialogs.d.ts" />
|
/// <reference path="./cordova-plugin-dialogs.d.ts" />
|
||||||
/// <reference path="./cordova-plugin-file.d.ts" />
|
/// <reference path="./cordova-plugin-file.d.ts" />
|
||||||
/// <reference path="./cordova-plugin-file-transfer.d.ts" />
|
/// <reference path="./cordova-plugin-file-transfer.d.ts" />
|
||||||
|
|
|
@ -70,4 +70,6 @@ declare interface Window {
|
||||||
initReadWriteFunction?(game: Game): Promise<void>;
|
initReadWriteFunction?(game: Game): Promise<void>;
|
||||||
|
|
||||||
bannedKeyWords: string[];
|
bannedKeyWords: string[];
|
||||||
|
|
||||||
|
device: Device;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// @ts-nocheck
|
|
||||||
import { get } from "../get/index.js";
|
import { get } from "../get/index.js";
|
||||||
import { lib } from "../library/index.js";
|
import { lib } from "../library/index.js";
|
||||||
import { game } from "../game/index.js";
|
import { game } from "../game/index.js";
|
||||||
import { _status } from "../status/index.js";
|
import { _status } from "../status/index.js";
|
||||||
import { ui } from "../ui/index.js";
|
import { ui } from "../ui/index.js";
|
||||||
import { nonameInitialized } from "../util/index.js";
|
import { nonameInitialized } from "../util/index.js";
|
||||||
|
import { checkVersion } from "../library/update.js";
|
||||||
|
|
||||||
export async function cordovaReady() {
|
export async function cordovaReady() {
|
||||||
if (lib.device == "android") {
|
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) {
|
if ("cordova" in window && "plugins" in window.cordova && "permissions" in window.cordova.plugins) {
|
||||||
const permissions = cordova.plugins.permissions;
|
const permissions = cordova.plugins.permissions;
|
||||||
const requests = ["WRITE_EXTERNAL_STORAGE", "READ_EXTERNAL_STORAGE"];
|
const requests = ["WRITE_EXTERNAL_STORAGE", "READ_EXTERNAL_STORAGE"];
|
||||||
requests.forEach((request) => {
|
if (typeof device == 'object') {
|
||||||
permissions.checkPermission(
|
// 安卓13或以上
|
||||||
permissions[request],
|
if (checkVersion(device.version, "13") >= 0) {
|
||||||
(status) => {
|
requests.length = 0;
|
||||||
if (!status.hasPermission) {
|
requests.push('READ_MEDIA_IMAGES', 'READ_MEDIA_VIDEO', 'READ_MEDIA_AUDIO');
|
||||||
permissions.requestPermission(
|
}
|
||||||
permissions[request],
|
}
|
||||||
lib.other.ignore,
|
Promise.all(requests.map(request => {
|
||||||
lib.other.ignore
|
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
|
lib.other.ignore
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue