Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/mobile/src/services/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { setNotificationHandler } from "expo-notifications/build/NotificationsHa
import scheduleNotificationAsync from "expo-notifications/build/scheduleNotificationAsync";
import setNotificationChannelAsync from "expo-notifications/build/setNotificationChannelAsync";
import { Platform } from "react-native";
import { readEnvFlag } from "../utils/env";
import {
buildReminderScheduleRequests,
enabledReminderMinutes,
Expand All @@ -25,9 +26,14 @@ import {
const MANAGED_NOTIFICATION_SOURCE = "eclipse-timer";
const ANDROID_CHANNEL_ID = "eclipse-alerts";
const MAX_SCHEDULED_NOTIFICATIONS_PER_SYNC = 60;
const SKIP_PERMISSION_PROMPT_FLAG = "EXPO_PUBLIC_SKIP_NOTIFICATION_PERMISSION_PROMPT";

let hasConfiguredHandler = false;

export function shouldSkipNotificationPermissionPrompt() {
return readEnvFlag(SKIP_PERMISSION_PROMPT_FLAG);
}

export type NotificationSchedulingSettings = {
vibrationEnabled: boolean;
soundEnabled: boolean;
Expand Down Expand Up @@ -130,6 +136,7 @@ export function configureNotificationPresentationHandler() {
export async function ensureNotificationPermissionAsync() {
const current = await getPermissionsAsync();
if (current.granted || current.status === "granted") return true;
if (shouldSkipNotificationPermissionPrompt()) return false;

const requested = await requestPermissionsAsync({
ios: {
Expand Down
10 changes: 10 additions & 0 deletions apps/mobile/src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function envFlagEnabled(value: string | undefined) {
if (typeof value !== "string") return false;

const normalized = value.trim().toLowerCase();
return normalized === "1" || normalized === "true" || normalized === "yes";
}

export function readEnvFlag(name: string) {
return envFlagEnabled(process.env[name]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Read Expo public env var with static property access

readEnvFlag uses process.env[name], but shouldSkipNotificationPermissionPrompt depends on this value to bypass requestPermissionsAsync; in Expo bundles, EXPO_PUBLIC_* values are only injected for direct/static process.env.EXPO_PUBLIC_... accesses, so this computed lookup resolves to undefined at runtime and the skip flag never takes effect during screenshot automation.

Useful? React with 👍 / 👎.

}
17 changes: 17 additions & 0 deletions apps/mobile/tests/notifications-permission.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from "vitest";

import { envFlagEnabled } from "../src/utils/env";

describe("envFlagEnabled", () => {
it("returns true for true-like values", () => {
expect(envFlagEnabled("true")).toBe(true);
expect(envFlagEnabled("1")).toBe(true);
expect(envFlagEnabled("yes")).toBe(true);
});

it("returns false for false-like values", () => {
expect(envFlagEnabled(undefined)).toBe(false);
expect(envFlagEnabled("false")).toBe(false);
expect(envFlagEnabled("0")).toBe(false);
});
});