From e0d48afbe22987624214b18ed613b0c31e6eb901 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sun, 12 Nov 2023 00:00:28 +0530 Subject: [PATCH] fix: Fixed issue on Android where only one selected file would be uploaded instead of all --- packages/mobile/src/Lib/MobileDevice.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/mobile/src/Lib/MobileDevice.ts b/packages/mobile/src/Lib/MobileDevice.ts index 2c4f49141..ea57201c1 100644 --- a/packages/mobile/src/Lib/MobileDevice.ts +++ b/packages/mobile/src/Lib/MobileDevice.ts @@ -50,7 +50,7 @@ import { Database } from './Database/Database' import { isLegacyIdentifier } from './Database/LegacyIdentifier' import { LegacyKeyValueStore } from './Database/LegacyKeyValueStore' import Keychain from './Keychain' -import notifee, { AuthorizationStatus, Notification } from '@notifee/react-native' +import notifee, { AuthorizationStatus, Notification, NotificationSettings } from '@notifee/react-native' export type BiometricsType = 'Fingerprint' | 'Face ID' | 'Biometrics' | 'Touch ID' @@ -72,6 +72,8 @@ export class MobileDevice implements MobileDeviceInterface { private keyValueStore = new LegacyKeyValueStore() private databases = new Map() + private notificationSettings: NotificationSettings | undefined + constructor( private stateObserverService?: AppStateObserverService, private androidBackHandlerService?: AndroidBackHandlerService, @@ -89,12 +91,23 @@ export class MobileDevice implements MobileDeviceInterface { id: 'files', name: 'File Upload/Download', }) + + const didAskForPermission = await this.keyValueStore.getValue('didAskForNotificationPermission') + + if (!didAskForPermission) { + this.notificationSettings = await notifee.requestPermission() + await this.keyValueStore.set('didAskForNotificationPermission', 'true') + } + + this.notificationSettings = await notifee.getNotificationSettings() } async canDisplayNotifications(): Promise { - const settings = await notifee.requestPermission() + if (!this.notificationSettings) { + return false + } - return settings.authorizationStatus >= AuthorizationStatus.AUTHORIZED + return this.notificationSettings.authorizationStatus >= AuthorizationStatus.AUTHORIZED } async displayNotification(options: Notification): Promise {