Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: prompt user to enable notifications if notifications are explicitly disabled.

ammarahm-ed82a80269d3c3
diff --git a/apps/mobile/app/components/sheets/reminder/index.tsx b/apps/mobile/app/components/sheets/reminder/index.tsx
index 3051f9ac4..1138aa8a4 100644
--- a/apps/mobile/app/components/sheets/reminder/index.tsx
+++ b/apps/mobile/app/components/sheets/reminder/index.tsx
@@ -47,6 +47,7 @@ import { useRelationStore } from "../../../stores/use-relation-store";
import { ReminderTime } from "../../ui/reminder-time";
import Paragraph from "../../ui/typography/paragraph";
import { NoteType } from "../../../utils/types";
+import { Dialog } from "../../dialog";
type ReminderSheetProps = {
actionSheetRef: RefObject<ActionSheet>;
@@ -161,7 +162,7 @@ export default function ReminderSheet({
async function saveReminder() {
try {
- if (!(await Notifications.checkAndRequestPermissions()))
+ if (!(await Notifications.checkAndRequestPermissions(true)))
throw new Error(
"App does not have permission to schedule notifications"
);
@@ -232,6 +233,7 @@ export default function ReminderSheet({
paddingHorizontal: 12
}}
>
+ <Dialog context="local"/>
<ScrollView
onScrollEndDrag={() => actionSheetRef.current?.handleChildScrollEnd()}
style={{
diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts
index d7b30d1b2..cf5a6be08 100644
--- a/apps/mobile/app/services/notifications.ts
+++ b/apps/mobile/app/services/notifications.ts
@@ -45,6 +45,7 @@ import ReminderNotify from "../components/sheets/reminder-notify";
import { sleep } from "../utils/time";
import { useRelationStore } from "../stores/use-relation-store";
import { useReminderStore } from "../stores/use-reminder-store";
+import { presentDialog } from "../components/dialog/functions";
export type Reminder = {
id: string;
@@ -477,7 +478,30 @@ async function displayNotification({
}
}
-async function checkAndRequestPermissions() {
+function openSettingsDialog(context: any) {
+ return new Promise((resolve) => {
+ presentDialog({
+ title: "Notifications disabled",
+ paragraph: `Reminders cannot be set because notifications have been disabled from app settings. If you want to keep receiving reminder notifications, enable notifications for Notesnook from app settings.`,
+ positiveText: Platform.OS === "ios" ? undefined : "Open settings",
+ negativeText: Platform.OS === "ios" ? "Close" : "Cancel",
+ positivePress:
+ Platform.OS === "ios"
+ ? undefined
+ : () => {
+ resolve(true);
+ },
+ onClose: () => {
+ resolve(false);
+ },
+ context: context
+ });
+ });
+}
+
+async function checkAndRequestPermissions(
+ promptUser?: boolean
+): Promise<boolean> {
let permissionStatus = await notifee.getNotificationSettings();
if (Platform.OS === "android") {
if (
@@ -497,11 +521,22 @@ async function checkAndRequestPermissions() {
permissionStatus.android.alarm === 1
)
return true;
+
+ if (promptUser) {
+ if (await openSettingsDialog("local")) {
+ await notifee.openNotificationSettings();
+ return false;
+ }
+ }
+
return false;
} else {
permissionStatus = await notifee.requestPermission();
if (permissionStatus.authorizationStatus === AuthorizationStatus.AUTHORIZED)
return true;
+ if (promptUser) {
+ await openSettingsDialog("local");
+ }
return false;
}
}