Files
crowd-funder-for-time-pwa/scripts/test-notification-receiver.sh
Jose Olarte III 9902e5fac7 chore: align with daily-notification-plugin 2.0.0 (org.timesafari namespace)
- Update Android manifest, Java imports, and capacitor.plugins.json to use
  org.timesafari.dailynotification (receivers, intent action, plugin classpath)
- Update iOS Info.plist BGTaskSchedulerPermittedIdentifiers to org.timesafari.*
- Bump @timesafari/daily-notification-plugin 1.3.3 → 2.0.0 (package-lock, Podfile.lock)
- Update docs and test-notification-receiver.sh to reference new package/action names
- Lockfile: minor bumps for @expo/cli, @expo/fingerprint, @expo/router-server, babel-preset-expo
2026-03-12 17:20:45 +08:00

105 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# test-notification-receiver.sh
# Author: Matthew Raymer
# Description: Test script to manually trigger the DailyNotificationReceiver
# to verify it's working correctly
# Function to find adb command
find_adb() {
# Check if adb is in PATH
if command -v adb >/dev/null 2>&1; then
echo "adb"
return 0
fi
# Check for ANDROID_HOME
if [ -n "$ANDROID_HOME" ] && [ -x "$ANDROID_HOME/platform-tools/adb" ]; then
echo "$ANDROID_HOME/platform-tools/adb"
return 0
fi
# Check for local.properties
local local_props="android/local.properties"
if [ -f "$local_props" ]; then
local sdk_dir=$(grep "^sdk.dir=" "$local_props" 2>/dev/null | cut -d'=' -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed "s|^file://||")
if [ -n "$sdk_dir" ] && [ -x "$sdk_dir/platform-tools/adb" ]; then
echo "$sdk_dir/platform-tools/adb"
return 0
fi
fi
# Try common macOS locations
local common_locations=(
"$HOME/Library/Android/sdk"
"$HOME/Android/Sdk"
"$HOME/.android/sdk"
)
for sdk_path in "${common_locations[@]}"; do
if [ -x "$sdk_path/platform-tools/adb" ]; then
echo "$sdk_path/platform-tools/adb"
return 0
fi
done
# Not found
return 1
}
# Find adb
ADB_CMD=$(find_adb)
if [ $? -ne 0 ] || [ -z "$ADB_CMD" ]; then
echo "Error: adb command not found!"
echo ""
echo "Please ensure one of the following:"
echo " 1. adb is in your PATH"
echo " 2. ANDROID_HOME is set and points to Android SDK"
echo " 3. Android SDK is installed at:"
echo " - $HOME/Library/Android/sdk (macOS default)"
echo " - $HOME/Android/Sdk"
echo ""
echo "You can find your SDK location in Android Studio:"
echo " Preferences > Appearance & Behavior > System Settings > Android SDK"
exit 1
fi
echo "Testing DailyNotificationReceiver..."
echo "Using adb: $ADB_CMD"
echo ""
# Get the package name
PACKAGE_NAME="app.timesafari.app"
INTENT_ACTION="org.timesafari.daily.NOTIFICATION"
echo "Package: $PACKAGE_NAME"
echo "Intent Action: $INTENT_ACTION"
echo ""
# Check if device is connected
if ! "$ADB_CMD" devices | grep -q $'\tdevice'; then
echo "Error: No Android device/emulator connected!"
echo ""
echo "Please:"
echo " 1. Start an Android emulator in Android Studio, or"
echo " 2. Connect a physical device via USB"
echo ""
echo "Then run: $ADB_CMD devices"
exit 1
fi
# Test 1: Send broadcast intent to trigger receiver (without ID - simulates current bug)
echo "Test 1: Sending broadcast intent to DailyNotificationReceiver (without ID)..."
"$ADB_CMD" shell am broadcast -a "$INTENT_ACTION" -n "$PACKAGE_NAME/org.timesafari.dailynotification.DailyNotificationReceiver"
echo ""
echo "Test 2: Sending broadcast intent WITH ID (to test if receiver works with ID)..."
"$ADB_CMD" shell am broadcast -a "$INTENT_ACTION" -n "$PACKAGE_NAME/org.timesafari.dailynotification.DailyNotificationReceiver" --es "id" "timesafari_daily_reminder"
echo ""
echo "Check logcat for 'DN|RECEIVE_START' to see if receiver was triggered"
echo "Test 1 should show 'missing_id' error"
echo "Test 2 should work correctly (if plugin supports it)"
echo ""
echo "To monitor logs, run:"
echo " $ADB_CMD logcat | grep -E 'DN|RECEIVE_START|DailyNotification'"