refactor(android): Batch A - Delegate checkStatus() to NotificationStatusChecker
Refactored checkStatus() to delegate to NotificationStatusChecker service. Changes: - Added statusChecker service instance to plugin - Initialize statusChecker in load() method - Replaced 53 lines of status checking logic with 3-line delegation - checkStatus() now calls NotificationStatusChecker.getComprehensiveStatus() This is the first method in Batch A (pure delegation, read-only). Verification: - Service method exists and returns JSObject ✅ - Error handling preserved ✅ - No behavior change (delegation only) ✅ Reduction: ~50 lines removed from plugin class
This commit is contained in:
@@ -88,6 +88,9 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
private val PERMISSION_REQUEST_CODE = 1001
|
||||
|
||||
// Service instances for delegation
|
||||
private var statusChecker: NotificationStatusChecker? = null
|
||||
|
||||
override fun load() {
|
||||
super.load()
|
||||
try {
|
||||
@@ -96,7 +99,8 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
return
|
||||
}
|
||||
db = DailyNotificationDatabase.getDatabase(context)
|
||||
Log.i(TAG, "Daily Notification Plugin loaded successfully")
|
||||
statusChecker = NotificationStatusChecker(context)
|
||||
Log.i(TAG, "Daily Notification Plugin loaded successfully")
|
||||
|
||||
// Phase 1: Perform app launch recovery (cold start only)
|
||||
// Runs asynchronously, non-blocking, with timeout
|
||||
@@ -1113,53 +1117,17 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
|
||||
@PluginMethod
|
||||
fun checkStatus(call: PluginCall) {
|
||||
// Comprehensive status check
|
||||
// Comprehensive status check - delegate to NotificationStatusChecker
|
||||
try {
|
||||
if (context == null) {
|
||||
return call.reject("Context not available")
|
||||
}
|
||||
|
||||
var postNotificationsGranted = false
|
||||
var channelEnabled = false
|
||||
var exactAlarmsGranted = false
|
||||
var channelImportance = 0
|
||||
val channelId = "daily_notification_channel"
|
||||
|
||||
// Check POST_NOTIFICATIONS permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
postNotificationsGranted = context.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
postNotificationsGranted = NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||
}
|
||||
|
||||
// Check exact alarms permission
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
exactAlarmsGranted = alarmManager.canScheduleExactAlarms()
|
||||
} else {
|
||||
exactAlarmsGranted = true // Always available on older Android versions
|
||||
}
|
||||
|
||||
// Check channel status
|
||||
channelEnabled = NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager?
|
||||
val channel = notificationManager?.getNotificationChannel(channelId)
|
||||
channelImportance = channel?.importance ?: android.app.NotificationManager.IMPORTANCE_DEFAULT
|
||||
channelEnabled = channel?.importance != android.app.NotificationManager.IMPORTANCE_NONE
|
||||
}
|
||||
|
||||
val canScheduleNow = postNotificationsGranted && channelEnabled && exactAlarmsGranted
|
||||
|
||||
val result = JSObject().apply {
|
||||
put("canScheduleNow", canScheduleNow)
|
||||
put("postNotificationsGranted", postNotificationsGranted)
|
||||
put("channelEnabled", channelEnabled)
|
||||
put("exactAlarmsGranted", exactAlarmsGranted)
|
||||
put("channelImportance", channelImportance)
|
||||
put("channelId", channelId)
|
||||
if (statusChecker == null) {
|
||||
statusChecker = NotificationStatusChecker(context)
|
||||
}
|
||||
|
||||
val result = statusChecker!!.getComprehensiveStatus()
|
||||
call.resolve(result)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to check status", e)
|
||||
|
||||
80
scripts/export-review-archive.sh
Executable file
80
scripts/export-review-archive.sh
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
# Export Review Archive Script
|
||||
#
|
||||
# Purpose: Generate a clean tarball for external review, excluding build artifacts,
|
||||
# caches, and unnecessary files.
|
||||
#
|
||||
# Usage: ./scripts/export-review-archive.sh [output-name]
|
||||
# Default output: daily-notification-plugin-review-YYYYMMDD.tar.gz
|
||||
#
|
||||
# Author: Matthew Raymer
|
||||
# Date: 2025-12-23
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Generate output filename
|
||||
if [ $# -ge 1 ]; then
|
||||
OUTPUT_NAME="$1"
|
||||
else
|
||||
OUTPUT_NAME="daily-notification-plugin-review-$(date +%Y%m%d).tar.gz"
|
||||
fi
|
||||
|
||||
# Ensure output is in parent directory (not inside project)
|
||||
OUTPUT_PATH="$(cd "$PROJECT_ROOT/.." && pwd)/$OUTPUT_NAME"
|
||||
|
||||
echo "📦 Creating review archive: $OUTPUT_NAME"
|
||||
echo " Output: $OUTPUT_PATH"
|
||||
echo ""
|
||||
|
||||
# Create archive excluding build artifacts, caches, and unnecessary files
|
||||
tar -czf "$OUTPUT_PATH" \
|
||||
--exclude='.git' \
|
||||
--exclude='node_modules' \
|
||||
--exclude='dist' \
|
||||
--exclude='build' \
|
||||
--exclude='.gradle' \
|
||||
--exclude='android/.gradle' \
|
||||
--exclude='android/build' \
|
||||
--exclude='android/app/build' \
|
||||
--exclude='ios/Pods' \
|
||||
--exclude='ios/DerivedData' \
|
||||
--exclude='ios/*.xcworkspace/xcuserdata' \
|
||||
--exclude='ios/*.xcodeproj/xcuserdata' \
|
||||
--exclude='*.tar.gz' \
|
||||
--exclude='*.zip' \
|
||||
--exclude='.DS_Store' \
|
||||
--exclude='*.swp' \
|
||||
--exclude='*.swo' \
|
||||
--exclude='*~' \
|
||||
--exclude='.idea' \
|
||||
--exclude='.vscode' \
|
||||
--exclude='packages/*/dist' \
|
||||
--exclude='packages/*/build' \
|
||||
--exclude='packages/*/node_modules' \
|
||||
--exclude='coverage' \
|
||||
--exclude='.nyc_output' \
|
||||
--exclude='*.log' \
|
||||
-C "$(dirname "$PROJECT_ROOT")" \
|
||||
"$(basename "$PROJECT_ROOT")"
|
||||
|
||||
# Verify archive was created
|
||||
if [ -f "$OUTPUT_PATH" ]; then
|
||||
SIZE=$(du -h "$OUTPUT_PATH" | cut -f1)
|
||||
echo "✅ Archive created successfully"
|
||||
echo " Size: $SIZE"
|
||||
echo " Path: $OUTPUT_PATH"
|
||||
echo ""
|
||||
echo "📋 Archive contents preview:"
|
||||
tar -tzf "$OUTPUT_PATH" | head -20
|
||||
echo " ... (showing first 20 entries)"
|
||||
echo ""
|
||||
echo "To extract: tar -xzf $OUTPUT_NAME"
|
||||
else
|
||||
echo "❌ Failed to create archive"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user