Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.k9i.ccpocket

import android.content.ComponentName
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.provider.Settings
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

private const val APP_ICON_CHANNEL = "ccpocket/app_icon"
private const val APP_SETTINGS_CHANNEL = "ccpocket/app_settings"

class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
Expand All @@ -30,6 +35,22 @@ class MainActivity : FlutterActivity() {
else -> result.notImplemented()
}
}
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
APP_SETTINGS_CHANNEL,
).setMethodCallHandler { call, result ->
when (call.method) {
"openNotificationSettings" -> {
try {
openNotificationSettings()
result.success(true)
} catch (error: Exception) {
result.error("settings_unavailable", error.message, null)
}
}
else -> result.notImplemented()
}
}
}

private fun getCurrentIcon(): String? {
Expand Down Expand Up @@ -74,4 +95,18 @@ class MainActivity : FlutterActivity() {
)
}
}

private fun openNotificationSettings() {
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
}
} else {
Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse("package:$packageName"),
)
}
startActivity(intent)
}
}
7 changes: 7 additions & 0 deletions apps/mobile/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Firebase Messaging 25.1.2 fixes FCM registration failures caused by reused
// Firebase installation IDs. Remove this override once FlutterFire pins a
// Firebase Android BoM version 34.18.0 or newer.
rootProject.extra["FlutterFire"] = mapOf(
"FirebaseSDKVersion" to "34.18.0",
)

allprojects {
repositories {
google()
Expand Down
40 changes: 33 additions & 7 deletions apps/mobile/lib/features/claude_session/claude_session_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import '../../services/notification_service.dart';
import '../../theme/app_theme.dart';
import '../../utils/diff_parser.dart';
import '../../utils/network_endpoint.dart';
import '../../utils/platform_helper.dart';
import '../../utils/terminal_launcher.dart';
import '../session_list/workspace_shell_screen.dart';
import '../session_link/widgets/session_unavailable_view.dart';
Expand Down Expand Up @@ -673,7 +674,10 @@ class _ChatScreenBody extends HookWidget {
effects,
sessionId: sessionId,
isBackground: isBackgroundRef.value,
localNotificationsAllowed:
!isAndroidPlatform || settingsCubit.state.fcmEnabled,
remoteNotificationsReady: settingsCubit.state.fcmReady,
privacyMode: settingsCubit.state.fcmPrivacy,
approval: chatSessionCubit.state.approval,
l: l,
collapseToolResults: collapseToolResults,
Expand Down Expand Up @@ -1491,7 +1495,9 @@ void _executeSideEffects(
Set<ChatSideEffect> effects, {
required String sessionId,
required bool isBackground,
required bool localNotificationsAllowed,
required bool remoteNotificationsReady,
required bool privacyMode,
required ApprovalState approval,
required AppLocalizations l,
required ValueNotifier<int> collapseToolResults,
Expand All @@ -1500,8 +1506,13 @@ void _executeSideEffects(
}) {
final useLocalNotification = shouldUseLocalNotificationFallback(
isBackground: isBackground,
localNotificationsAllowed: localNotificationsAllowed,
remoteNotificationsReady: remoteNotificationsReady,
);
final payload = sessionNotificationPayload(
sessionId: sessionId,
provider: 'claude',
);
for (final effect in effects) {
switch (effect) {
case ChatSideEffect.heavyHaptic:
Expand All @@ -1523,8 +1534,13 @@ void _executeSideEffects(
NotificationService.instance.showApprovalNotification(
permission,
l: l,
id: 1,
payload: sessionId,
privacyMode: privacyMode,
id: sessionNotificationId(
sessionId: sessionId,
provider: 'claude',
eventType: SessionNotificationEvent.approval,
),
payload: payload,
);
}
}
Expand All @@ -1535,17 +1551,27 @@ void _executeSideEffects(
NotificationService.instance.showApprovalNotification(
permission,
l: l,
id: 2,
payload: sessionId,
privacyMode: privacyMode,
id: sessionNotificationId(
sessionId: sessionId,
provider: 'claude',
eventType: SessionNotificationEvent.question,
),
payload: payload,
);
}
}
case ChatSideEffect.notifySessionComplete:
if (useLocalNotification) {
NotificationService.instance.showSessionCompleteNotification(
body: 'Session done',
id: 3,
payload: sessionId,
l: l,
privacyMode: privacyMode,
id: sessionNotificationId(
sessionId: sessionId,
provider: 'claude',
eventType: SessionNotificationEvent.complete,
),
payload: payload,
);
}
}
Expand Down
40 changes: 33 additions & 7 deletions apps/mobile/lib/features/codex_session/codex_session_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import '../../widgets/session_name_title.dart';
import '../../widgets/workspace_pane_chrome.dart';
import '../../utils/diff_parser.dart';
import '../../utils/network_endpoint.dart';
import '../../utils/platform_helper.dart';
import '../../utils/terminal_launcher.dart';
import '../settings/state/settings_cubit.dart';
import '../../widgets/new_session_sheet.dart'
Expand Down Expand Up @@ -743,7 +744,10 @@ class _CodexChatBody extends HookWidget {
effects,
sessionId: sessionId,
isBackground: isBackgroundRef.value,
localNotificationsAllowed:
!isAndroidPlatform || settingsCubit.state.fcmEnabled,
remoteNotificationsReady: settingsCubit.state.fcmReady,
privacyMode: settingsCubit.state.fcmPrivacy,
approval: chatSessionCubit.state.approval,
l: l,
collapseToolResults: collapseToolResults,
Expand Down Expand Up @@ -1657,7 +1661,9 @@ void _executeSideEffects(
Set<ChatSideEffect> effects, {
required String sessionId,
required bool isBackground,
required bool localNotificationsAllowed,
required bool remoteNotificationsReady,
required bool privacyMode,
required ApprovalState approval,
required AppLocalizations l,
required TextEditingController planFeedbackController,
Expand All @@ -1666,8 +1672,13 @@ void _executeSideEffects(
}) {
final useLocalNotification = shouldUseLocalNotificationFallback(
isBackground: isBackground,
localNotificationsAllowed: localNotificationsAllowed,
remoteNotificationsReady: remoteNotificationsReady,
);
final payload = sessionNotificationPayload(
sessionId: sessionId,
provider: 'codex',
);
for (final effect in effects) {
switch (effect) {
case ChatSideEffect.heavyHaptic:
Expand All @@ -1689,8 +1700,13 @@ void _executeSideEffects(
NotificationService.instance.showApprovalNotification(
permission,
l: l,
id: 1,
payload: sessionId,
privacyMode: privacyMode,
id: sessionNotificationId(
sessionId: sessionId,
provider: 'codex',
eventType: SessionNotificationEvent.approval,
),
payload: payload,
);
}
}
Expand All @@ -1701,17 +1717,27 @@ void _executeSideEffects(
NotificationService.instance.showApprovalNotification(
permission,
l: l,
id: 2,
payload: sessionId,
privacyMode: privacyMode,
id: sessionNotificationId(
sessionId: sessionId,
provider: 'codex',
eventType: SessionNotificationEvent.question,
),
payload: payload,
);
}
}
case ChatSideEffect.notifySessionComplete:
if (useLocalNotification) {
NotificationService.instance.showSessionCompleteNotification(
body: 'Codex session done',
id: 3,
payload: sessionId,
l: l,
privacyMode: privacyMode,
id: sessionNotificationId(
sessionId: sessionId,
provider: 'codex',
eventType: SessionNotificationEvent.complete,
),
payload: payload,
);
}
}
Expand Down
46 changes: 43 additions & 3 deletions apps/mobile/lib/features/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import '../../services/bridge_service.dart';
import '../../services/in_app_review_service.dart';
import '../../services/machine_manager_service.dart';
import '../../services/platform_environment_service.dart';
import '../../services/platform_settings_service.dart';
import '../../services/prompt_history_service.dart';
import '../../services/revenuecat_service.dart';
import '../../services/support_banner_service.dart';
Expand Down Expand Up @@ -63,7 +64,8 @@ class SettingsScreen extends StatefulWidget {
State<SettingsScreen> createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {
class _SettingsScreenState extends State<SettingsScreen>
with WidgetsBindingObserver {
final _scrollController = ScrollController();
final _connectionSectionKey = GlobalKey();
final _supportSectionKey = GlobalKey();
Expand Down Expand Up @@ -150,6 +152,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
unawaited(_loadPlatformEnvironment());
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
Expand All @@ -159,6 +162,17 @@ class _SettingsScreenState extends State<SettingsScreen> {
});
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state != AppLifecycleState.resumed || !mounted || !isAndroidPlatform) {
return;
}
final settings = context.read<SettingsCubit>();
if (settings.state.fcmStatusKey == FcmStatusKey.permissionDenied) {
unawaited(settings.retryFcmPermission());
}
}

Future<void> _loadPlatformEnvironment() async {
final environment = PlatformEnvironmentService.instance;
final isIOSAppOnMac = await environment.isIOSAppOnMac();
Expand Down Expand Up @@ -186,6 +200,7 @@ class _SettingsScreenState extends State<SettingsScreen> {

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_connectionHighlightTimer?.cancel();
_supportHighlightTimer?.cancel();
_scrollController.dispose();
Expand Down Expand Up @@ -706,6 +721,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
state: state,
onChanged: (enabled) =>
context.read<SettingsCubit>().toggleFcm(enabled),
onOpenSettings: isAndroidPlatform
? () => unawaited(
PlatformSettingsService.openNotificationSettings(),
)
: null,
),
if (state.fcmEnabled) ...[
Divider(
Expand Down Expand Up @@ -1570,13 +1590,19 @@ class _BridgeUpdateSetupStep extends StatelessWidget {
class _PushNotificationTile extends StatelessWidget {
final SettingsState state;
final ValueChanged<bool> onChanged;
final VoidCallback? onOpenSettings;

const _PushNotificationTile({required this.state, required this.onChanged});
const _PushNotificationTile({
required this.state,
required this.onChanged,
this.onOpenSettings,
});

static String? _resolveFcmStatus(AppLocalizations l, FcmStatusKey? key) {
if (key == null) return null;
return switch (key) {
FcmStatusKey.unavailable => l.pushNotificationsUnavailable,
FcmStatusKey.permissionDenied => l.fcmPermissionDenied,
FcmStatusKey.bridgeNotInitialized => l.fcmBridgeNotInitialized,
FcmStatusKey.tokenFailed => l.fcmTokenFailed,
FcmStatusKey.registrationFailed => l.fcmRegistrationFailed,
Expand All @@ -1595,11 +1621,25 @@ class _PushNotificationTile extends StatelessWidget {
: l.pushNotificationsUnavailable;
final subtitle = _resolveFcmStatus(l, state.fcmStatusKey) ?? baseSubtitle;

final permissionDenied =
state.fcmStatusKey == FcmStatusKey.permissionDenied;

return SwitchListTile(
value: state.fcmEnabled,
onChanged: state.fcmSyncInProgress ? null : onChanged,
title: Text(l.pushNotifications),
subtitle: Text(subtitle),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(subtitle),
if (permissionDenied && onOpenSettings != null)
TextButton(
key: const ValueKey('open_notification_settings_button'),
onPressed: onOpenSettings,
child: Text(l.openNotificationSettings),
),
],
),
secondary: state.fcmSyncInProgress
? const SizedBox(
width: 20,
Expand Down
Loading