mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-17 22:04:56 +01:00
Fix E2E unlock dialog and log publish errors
Since the material_ui bump the app supplied no framework MaterialLocalizations, so crdt_sync_flutter's E2ePassphraseButton showDialog crashed and the phone stayed locked. Nothing synced and the PC fallback rang on 2026-11-16. The app now provides the localization delegates. Publish failures now reach logcat in release builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
This commit is contained in:
parent
dec4ecc0cb
commit
7a3b767075
@ -37,7 +37,10 @@ object HeadlessRingStart {
|
||||
|
||||
/** Starts the engine unless one is already running. Main thread only. */
|
||||
fun start(context: Context) {
|
||||
if (engine != null) return
|
||||
if (engine != null) {
|
||||
Log.w(TAG, "headless ring_started engine already running; start ignored")
|
||||
return
|
||||
}
|
||||
try {
|
||||
val app = context.applicationContext
|
||||
val created = FlutterEngine(app)
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
// Framework material, for its MaterialLocalizations delegate only: material_ui
|
||||
// ships its own MaterialLocalizations type, so crdt_sync_flutter's dialogs
|
||||
// (framework `showDialog`) found none and threw a null check.
|
||||
// ignore: deprecated_member_use, the only source of the framework delegate.
|
||||
import 'package:flutter/material.dart' as fw show DefaultMaterialLocalizations;
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import 'package:wake_alarm_sync/screens/home_screen.dart';
|
||||
@ -67,6 +72,10 @@ class WakeAlarmSyncApp extends StatelessWidget {
|
||||
title: kAppName,
|
||||
theme: buildAppTheme(),
|
||||
navigatorKey: navigatorKey,
|
||||
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
|
||||
fw.DefaultMaterialLocalizations.delegate,
|
||||
DefaultWidgetsLocalizations.delegate,
|
||||
],
|
||||
// AlarmActivity sets its initial route to kRingRoute, so the ring screen
|
||||
// is what comes up over the lockscreen; the launcher still gets home.
|
||||
routes: <String, WidgetBuilder>{
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/foundation.dart' show debugPrint;
|
||||
import 'package:wake_alarm_sync/services/alarm_sync_service.dart';
|
||||
import 'package:wake_alarm_sync/services/enforcement_bridge.dart';
|
||||
import 'package:wake_alarm_sync/services/enforcement_sync.dart';
|
||||
@ -60,7 +61,10 @@ class RingStartRecorder {
|
||||
if (await RingStartedStore.publishedOn(entry['date'])) return true;
|
||||
final settings = await SyncSettings.load();
|
||||
final hasFirebase = await loadAccount() != null;
|
||||
if (!settings.isConfigured && !hasFirebase) return false;
|
||||
if (!settings.isConfigured && !hasFirebase) {
|
||||
_log('ring_started not published: no sync backend');
|
||||
return false;
|
||||
}
|
||||
final service = await _open();
|
||||
// Only the enforcement fields: the ring is no time to restage tags
|
||||
// and history, and the push carries the whole log regardless.
|
||||
@ -79,5 +83,9 @@ class RingStartRecorder {
|
||||
}
|
||||
}
|
||||
|
||||
void _log(String message) => developer.log(message, name: 'WakeAlarmRing');
|
||||
// developer.log is invisible in a release build; logcat needs debugPrint.
|
||||
void _log(String message) {
|
||||
debugPrint('WakeAlarmRing: $message');
|
||||
developer.log(message, name: 'WakeAlarmRing');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/foundation.dart' show debugPrint;
|
||||
import 'package:wake_alarm_sync/services/alarm_sync_service.dart';
|
||||
import 'package:wake_alarm_sync/services/firebase_backend.dart';
|
||||
import 'package:wake_alarm_sync/services/settings_sync.dart';
|
||||
@ -32,6 +33,8 @@ class SessionPublisher {
|
||||
await applySyncedSettings(service);
|
||||
return 'Session synced to PC ✓';
|
||||
} on Exception catch (e, stack) {
|
||||
// developer.log is invisible in a release build; logcat needs print.
|
||||
debugPrint('WakeAlarmSession: session publish failed: $e');
|
||||
developer.log(
|
||||
'session publish failed: $e',
|
||||
name: 'WakeAlarmSession',
|
||||
|
||||
28
phone_app/test/e2e_dialog_localizations_test.dart
Normal file
28
phone_app/test/e2e_dialog_localizations_test.dart
Normal file
@ -0,0 +1,28 @@
|
||||
// ignore: deprecated_member_use, the dialog under test is framework material.
|
||||
import 'package:flutter/material.dart' as fw show AlertDialog;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:wake_alarm_sync/main.dart';
|
||||
import 'package:wake_alarm_sync/screens/settings_screen.dart';
|
||||
|
||||
/// crdt_sync_flutter's passphrase dialog uses the framework's material
|
||||
/// `showDialog`, which needs the framework's MaterialLocalizations. The
|
||||
/// app's MaterialApp comes from material_ui and does not supply them.
|
||||
void main() {
|
||||
testWidgets('the settings lock icon opens the passphrase dialog', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(const WakeAlarmSyncApp());
|
||||
navigatorKey.currentState!.push(
|
||||
MaterialPageRoute<void>(builder: (_) => const SettingsScreen()),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(const Key('settings-e2e')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(fw.AlertDialog), findsOneWidget);
|
||||
expect(find.byType(EditableText), findsOneWidget);
|
||||
});
|
||||
}
|
||||
28
phone_app/test/services/session_publisher_log_test.dart
Normal file
28
phone_app/test/services/session_publisher_log_test.dart
Normal file
@ -0,0 +1,28 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wake_alarm_sync/services/session_publisher.dart';
|
||||
|
||||
import '../fake_secure_storage.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test('a failed publish reaches debugPrint, not only developer.log', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
installFakeSecureStorage(initial: {'github_token': 'tok'});
|
||||
final lines = <String>[];
|
||||
final saved = debugPrint;
|
||||
debugPrint = (message, {wrapWidth}) => lines.add('$message');
|
||||
addTearDown(() => debugPrint = saved);
|
||||
|
||||
final status = await SessionPublisher(
|
||||
open: () async => throw Exception('boom'),
|
||||
).publish();
|
||||
|
||||
expect(status, 'Session kept locally (sync failed)');
|
||||
expect(
|
||||
lines.join('\n'),
|
||||
contains('session publish failed: Exception: boom'),
|
||||
);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user