Skip to content

Commit 01a0228

Browse files
committed
Skip notification permission prompt when env flag is set
1 parent 47ff5ca commit 01a0228

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

apps/mobile/src/services/notifications.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { setNotificationHandler } from "expo-notifications/build/NotificationsHa
1515
import scheduleNotificationAsync from "expo-notifications/build/scheduleNotificationAsync";
1616
import setNotificationChannelAsync from "expo-notifications/build/setNotificationChannelAsync";
1717
import { Platform } from "react-native";
18+
import { readEnvFlag } from "../utils/env";
1819
import {
1920
buildReminderScheduleRequests,
2021
enabledReminderMinutes,
@@ -25,9 +26,14 @@ import {
2526
const MANAGED_NOTIFICATION_SOURCE = "eclipse-timer";
2627
const ANDROID_CHANNEL_ID = "eclipse-alerts";
2728
const MAX_SCHEDULED_NOTIFICATIONS_PER_SYNC = 60;
29+
const SKIP_PERMISSION_PROMPT_FLAG = "EXPO_PUBLIC_SKIP_NOTIFICATION_PERMISSION_PROMPT";
2830

2931
let hasConfiguredHandler = false;
3032

33+
export function shouldSkipNotificationPermissionPrompt() {
34+
return readEnvFlag(SKIP_PERMISSION_PROMPT_FLAG);
35+
}
36+
3137
export type NotificationSchedulingSettings = {
3238
vibrationEnabled: boolean;
3339
soundEnabled: boolean;
@@ -130,6 +136,7 @@ export function configureNotificationPresentationHandler() {
130136
export async function ensureNotificationPermissionAsync() {
131137
const current = await getPermissionsAsync();
132138
if (current.granted || current.status === "granted") return true;
139+
if (shouldSkipNotificationPermissionPrompt()) return false;
133140

134141
const requested = await requestPermissionsAsync({
135142
ios: {

apps/mobile/src/utils/env.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function envFlagEnabled(value: string | undefined) {
2+
if (typeof value !== "string") return false;
3+
4+
const normalized = value.trim().toLowerCase();
5+
return normalized === "1" || normalized === "true" || normalized === "yes";
6+
}
7+
8+
export function readEnvFlag(name: string) {
9+
return envFlagEnabled(process.env[name]);
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { envFlagEnabled } from "../src/utils/env";
4+
5+
describe("envFlagEnabled", () => {
6+
it("returns true for true-like values", () => {
7+
expect(envFlagEnabled("true")).toBe(true);
8+
expect(envFlagEnabled("1")).toBe(true);
9+
expect(envFlagEnabled("yes")).toBe(true);
10+
});
11+
12+
it("returns false for false-like values", () => {
13+
expect(envFlagEnabled(undefined)).toBe(false);
14+
expect(envFlagEnabled("false")).toBe(false);
15+
expect(envFlagEnabled("0")).toBe(false);
16+
});
17+
});

0 commit comments

Comments
 (0)