diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 3aa703a..db4cb25 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -4,6 +4,10 @@ plugins { id("dev.flutter.flutter-gradle-plugin") } +if (file("google-services.json").exists()) { + apply(plugin = "com.google.gms.google-services") +} + android { namespace = "hu.otthonnaptar.otthon_naptar" compileSdk = flutter.compileSdkVersion diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts index c21f0c5..27ce201 100644 --- a/android/settings.gradle.kts +++ b/android/settings.gradle.kts @@ -21,6 +21,7 @@ plugins { id("dev.flutter.flutter-plugin-loader") version "1.0.0" id("com.android.application") version "9.0.1" apply false id("org.jetbrains.kotlin.android") version "2.3.20" apply false + id("com.google.gms.google-services") version "4.4.4" apply false } include(":app") diff --git a/lib/google_calendar_page.dart b/lib/google_calendar_page.dart index 5e74609..b45b401 100644 --- a/lib/google_calendar_page.dart +++ b/lib/google_calendar_page.dart @@ -30,7 +30,7 @@ class _AccountsPageState extends State { final googleSignIn = GoogleSignIn.instance; List googleCalendars = []; GoogleSignInAccount? signedInAccount; - String runtimeServerClientId = googleCalendarServerClientId; + String? runtimeServerClientId; bool initialized = false; bool loadingCalendars = false; bool syncing = false; @@ -53,16 +53,7 @@ class _AccountsPageState extends State { final configuredClientId = await _loadGoogleServerClientId(); if (!mounted) return; - if (configuredClientId == null || configuredClientId.trim().isEmpty) { - setState(() { - loadingCalendars = false; - statusMessage = - 'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve. A csal\u00e1dtagoknak nem kell client ID-t megadniuk; a JARVIS admin fel\u00fcleten kell egyszer be\u00e1ll\u00edtani a Google Calendar OAuth azonos\u00edt\u00f3t.'; - }); - return; - } - - runtimeServerClientId = configuredClientId.trim(); + runtimeServerClientId = configuredClientId?.trim(); await _initializeGoogle(); } @@ -121,7 +112,10 @@ class _AccountsPageState extends State { if (!mounted) return; setState(() { loadingCalendars = false; - statusMessage = 'Google inicializ\u00e1l\u00e1s nem siker\u00fclt: $error'; + statusMessage = _friendlyGoogleError( + 'Google inicializ\u00e1l\u00e1s nem siker\u00fclt', + error, + ); }); } } @@ -163,17 +157,30 @@ class _AccountsPageState extends State { if (!mounted) return; setState(() { loadingCalendars = false; - statusMessage = 'Google bejelentkez\u00e9s nem siker\u00fclt: $error'; + statusMessage = _friendlyGoogleError( + 'Google bejelentkez\u00e9s nem siker\u00fclt', + error, + ); }); } } + String _friendlyGoogleError(String prefix, Object error) { + final raw = error.toString(); + if (raw.contains('serverClientId must be provided') || + raw.contains('CredentialManager requires a serverClientId')) { + return '$prefix: hi\u00e1nyzik az app Google konfigur\u00e1ci\u00f3ja. ' + 'A bel\u00e9p\u00e9si ablakos m\u0171k\u00f6d\u00e9shez tedd be az android/app/google-services.json f\u00e1jlt, ' + 'amely tartalmaz Web application OAuth client ID-t, majd buildeld \u00fajra az APK-t.'; + } + return '$prefix: $raw'; + } + Future _ensureGoogleInitialized() async { - final clientId = runtimeServerClientId.trim(); - if (clientId.isEmpty) { - throw Exception( - 'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve.', - ); + final clientId = runtimeServerClientId; + if (clientId == null || clientId.isEmpty) { + await googleSignIn.initialize(); + return; } await googleSignIn.initialize(