From 813928bdd3354735b8011bfaf59445823140b4ed Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 10 Nov 2023 12:52:24 +1300 Subject: [PATCH] =?UTF-8?q?Add=20permissions=20checks=20to=20SettingsPage?= =?UTF-8?q?=20-=201.172=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to #177 --- SettingsPage.tsx | 7 +++++++ android/app/build.gradle | 4 ++-- package-lock.json | 20 ++++++++++++++++++-- package.json | 3 ++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/SettingsPage.tsx b/SettingsPage.tsx index e71000b..d33da07 100644 --- a/SettingsPage.tsx +++ b/SettingsPage.tsx @@ -20,6 +20,7 @@ import { darkOptions, lightOptions, themeOptions } from "./options"; import Settings, { settingsUpdated } from "./settings"; import { toast } from "./toast"; import { useTheme } from "./use-theme"; +import { check, PERMISSIONS, RESULTS, request } from "react-native-permissions"; const twelveHours = [ "dd/LL/yyyy", @@ -126,6 +127,9 @@ export default function SettingsPage() { case "alarm": if (value) toast("Timers will now run after each set."); else toast("Stopped timers running after each set."); + const canNotify = await check(PERMISSIONS.ANDROID.POST_NOTIFICATIONS); + if (canNotify === RESULTS.DENIED || canNotify === RESULTS.BLOCKED) + await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS); if (value && !ignoring) NativeModules.SettingsModule.ignoreBattery(); return; case "vibrate": @@ -290,6 +294,9 @@ export default function SettingsPage() { }, [reset, update]); const exportDatabase = useCallback(async () => { + const result = await check(PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE); + if (result === RESULTS.DENIED || result === RESULTS.BLOCKED) + await request(PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE); const path = Dirs.DatabaseDir + "/massive.db"; await FileSystem.cpExternal(path, "massive.db", "downloads"); toast("Database exported. Check downloads."); diff --git a/android/app/build.gradle b/android/app/build.gradle index 698bde1..61193ca 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -85,8 +85,8 @@ android { applicationId "com.massive" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 36197 - versionName "1.171" + versionCode 36198 + versionName "1.172" } signingConfigs { release { diff --git a/package-lock.json b/package-lock.json index b1ca507..e6df9fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "massive", - "version": "1.169", + "version": "1.171", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "massive", - "version": "1.169", + "version": "1.171", "license": "GPL-3.0-only", "dependencies": { "@babel/plugin-proposal-class-properties": "^7.18.6", @@ -37,6 +37,7 @@ "react-native-linear-gradient": "^2.7.3", "react-native-pager-view": "^6.2.0", "react-native-paper": "^5.9.1", + "react-native-permissions": "^3.10.1", "react-native-reanimated": "^3.3.0", "react-native-reorderable-list": "^0.4.0", "react-native-safe-area-context": "^4.7.1", @@ -9896,6 +9897,21 @@ "color-string": "^1.6.0" } }, + "node_modules/react-native-permissions": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.10.1.tgz", + "integrity": "sha512-Gc5BxxpjZn4QNUDiVeHOO0vXh3AH7ToolmwTJozqC6DsxV7NAf3ttap+8BSmzDR8WxuAM3Cror+YNiBhHJx7/w==", + "peerDependencies": { + "react": ">=16.13.1", + "react-native": ">=0.63.3", + "react-native-windows": ">=0.62.0" + }, + "peerDependenciesMeta": { + "react-native-windows": { + "optional": true + } + } + }, "node_modules/react-native-reanimated": { "version": "3.3.0", "license": "MIT", diff --git a/package.json b/package.json index 96f83e3..bfb13ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "massive", - "version": "1.171", + "version": "1.172", "private": true, "license": "GPL-3.0-only", "scripts": { @@ -40,6 +40,7 @@ "react-native-linear-gradient": "^2.7.3", "react-native-pager-view": "^6.2.0", "react-native-paper": "^5.9.1", + "react-native-permissions": "^3.10.1", "react-native-reanimated": "^3.3.0", "react-native-reorderable-list": "^0.4.0", "react-native-safe-area-context": "^4.7.1",