From b3d5bcaa7ec64bd62d0fb551c8dc439b7b0ffd4a Mon Sep 17 00:00:00 2001 From: Krille Date: Thu, 21 Dec 2023 13:57:10 +0100 Subject: [PATCH] feat: Switch to firebase messaging package --- .github/workflows/integrate.yaml | 2 +- .github/workflows/main_deploy.yaml | 2 +- .github/workflows/release.yaml | 4 +- android/app/build.gradle | 5 +- android/app/src/main/AndroidManifest.xml | 7 - .../chat/fluffy/fluffychat/FcmPushService.kt | 36 ---- .../chat/fluffy/fluffychat/MainActivity.kt | 2 - android/build.gradle | 2 +- firebase.json | 1 + lib/main.dart | 4 + lib/utils/background_push.dart | 26 +-- lib/utils/client_manager.dart | 39 +++-- lib/utils/init_with_restore.dart | 6 +- lib/utils/push_helper.dart | 12 +- macos/Runner.xcodeproj/project.pbxproj | 4 + macos/Runner/GoogleService-Info.plist | 30 ++++ pubspec.lock | 9 +- pubspec.yaml | 7 +- scripts/build-ios.sh | 2 +- scripts/build-macos.sh | 2 +- scripts/enable-android-google-services.patch | 161 ------------------ scripts/enable-google-services.sh | 6 + scripts/release-ios-testflight.sh | 2 +- 23 files changed, 114 insertions(+), 257 deletions(-) delete mode 100644 android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt create mode 100644 firebase.json create mode 100644 macos/Runner/GoogleService-Info.plist delete mode 100644 scripts/enable-android-google-services.patch create mode 100755 scripts/enable-google-services.sh diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index c480cd89c..68799109e 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -23,7 +23,7 @@ jobs: run: dart run license_checker check-licenses -c licenses.yaml --problematic - run: flutter analyze - name: Apply google services patch - run: git apply ./scripts/enable-android-google-services.patch + run: ./scripts/enable-google-services.sh - run: flutter analyze - run: flutter test diff --git a/.github/workflows/main_deploy.yaml b/.github/workflows/main_deploy.yaml index 93a0b5140..dbcd84c56 100644 --- a/.github/workflows/main_deploy.yaml +++ b/.github/workflows/main_deploy.yaml @@ -57,7 +57,7 @@ jobs: - name: Install Fastlane run: gem install fastlane -NV - name: Apply Google Services Patch - run: git apply ./scripts/enable-android-google-services.patch + run: ./scripts/enable-google-services.sh - name: Remove Emoji Font run: | rm -rf fonts/NotoEmoji diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 466070664..e0dec416e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -80,7 +80,7 @@ jobs: flutter-version: ${{ env.FLUTTER_VERSION }} cache: true - name: Apply Google Services Patch - run: git apply ./scripts/enable-android-google-services.patch + run: ./scripts/enable-google-services.sh - name: Remove Emoji Font run: | rm -rf fonts/NotoEmoji @@ -148,7 +148,7 @@ jobs: - name: Install Fastlane run: gem install fastlane -NV - name: Apply Google Services Patch - run: git apply ./scripts/enable-android-google-services.patch + run: ./scripts/enable-google-services.sh - name: Remove Emoji Font run: | rm -rf fonts/NotoEmoji diff --git a/android/app/build.gradle b/android/app/build.gradle index aa8b76494..065d7c241 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -69,7 +69,7 @@ android { } release { signingConfig signingConfigs.release - } + } } // https://stackoverflow.com/a/77494454/8222484 packagingOptions { @@ -86,8 +86,7 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - //implementation 'com.google.firebase:firebase-messaging:19.0.1' // Workaround for https://github.com/microg/android_packages_apps_GmsCore/issues/313#issuecomment-617651698 implementation 'androidx.multidex:multidex:2.0.1' } -//apply plugin: 'com.google.gms.google-services' +//apply plugin: 'com.google.gms.google-services' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c0595780a..932572018 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -113,13 +113,6 @@ - - - - - - diff --git a/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt b/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt deleted file mode 100644 index d9930f557..000000000 --- a/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt +++ /dev/null @@ -1,36 +0,0 @@ -/*package chat.fluffy.fluffychat - -import com.famedly.fcm_shared_isolate.FcmSharedIsolateService - -import chat.fluffy.fluffychat.MainActivity - -import io.flutter.embedding.android.FlutterActivity -import io.flutter.embedding.engine.FlutterEngine -import io.flutter.view.FlutterMain -import io.flutter.embedding.engine.dart.DartExecutor.DartEntrypoint - -import android.content.Context -import android.os.Bundle -import android.util.Log -import android.view.WindowManager - -class FcmPushService : FcmSharedIsolateService() { - override fun getEngine(): FlutterEngine { - return provideEngine(getApplicationContext()) - } - - companion object { - fun provideEngine(context: Context): FlutterEngine { - var engine = MainActivity.engine - if (engine == null) { - engine = MainActivity.provideEngine(context) - engine.getLocalizationPlugin().sendLocalesToFlutter( - context.getResources().getConfiguration()) - engine.getDartExecutor().executeDartEntrypoint( - DartEntrypoint.createDefault()) - } - return engine - } - } -} -*/ \ No newline at end of file diff --git a/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt b/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt index 1afc46062..894d1571c 100644 --- a/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt +++ b/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt @@ -7,13 +7,11 @@ import android.content.Context import androidx.multidex.MultiDex class MainActivity : FlutterActivity() { - override fun attachBaseContext(base: Context) { super.attachBaseContext(base) MultiDex.install(this) } - override fun provideFlutterEngine(context: Context): FlutterEngine? { return provideEngine(this) } diff --git a/android/build.gradle b/android/build.gradle index a8c597ff1..fd9f0da07 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,7 +8,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - //classpath 'com.google.gms:google-services:4.3.8' + //classpath 'com.google.gms:google-services:4.3.8' } } diff --git a/firebase.json b/firebase.json new file mode 100644 index 000000000..108bb81c9 --- /dev/null +++ b/firebase.json @@ -0,0 +1 @@ +{"flutter":{"platforms":{"android":{"default":{"projectId":"fluffychat-ef3e8","appId":"1:865731724731:android:ec427b3b1dcd4a1e64309e","fileOutput":"android/app/google-services.json"}},"ios":{"default":{"projectId":"fluffychat-ef3e8","appId":"1:865731724731:ios:79fd983ce46cb40c64309e","uploadDebugSymbols":false,"fileOutput":"ios/Runner/GoogleService-Info.plist"}},"macos":{"default":{"projectId":"fluffychat-ef3e8","appId":"1:865731724731:ios:6fb777cf513cdb6264309e","uploadDebugSymbols":false,"fileOutput":"macos/Runner/GoogleService-Info.plist"}},"dart":{"lib/firebase_options.dart":{"projectId":"fluffychat-ef3e8","configurations":{"android":"1:865731724731:android:ec427b3b1dcd4a1e64309e","ios":"1:865731724731:ios:79fd983ce46cb40c64309e","macos":"1:865731724731:ios:6fb777cf513cdb6264309e","web":"1:865731724731:web:d367990bc625c24864309e"}}}}}} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 877f80da3..0c86e3c9c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +//import 'package:firebase_core/firebase_core.dart'; + import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; @@ -21,6 +23,8 @@ void main() async { // widget bindings are initialized already. WidgetsFlutterBinding.ensureInitialized(); + //await Firebase.initializeApp(); + Logs().nativeColors = !PlatformInfos.isIOS; final store = await SharedPreferences.getInstance(); final clients = await ClientManager.getClients(store: store); diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 039dde895..6950744ff 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -38,7 +38,7 @@ import '../config/setting_keys.dart'; import '../widgets/matrix.dart'; import 'platform_infos.dart'; -//import 'package:fcm_shared_isolate/fcm_shared_isolate.dart'; +//import 'package:firebase_messaging/firebase_messaging.dart'; class NoTokenException implements Exception { String get cause => 'Cannot get firebase token'; @@ -63,24 +63,23 @@ class BackgroundPush { final pendingTests = >{}; - final dynamic firebase = null; //FcmSharedIsolate(); + //final firebase = FirebaseMessaging.instance; DateTime? lastReceivedPush; bool upAction = false; - BackgroundPush._(this.client) { - firebase?.setListeners( - onMessage: (message) => pushHelper( - PushNotification.fromJson( - Map.from(message['data'] ?? message), - ), + void onMessage(message) => pushHelper( + PushNotification.fromJson(Map.from(message.data)), client: client, l10n: l10n, activeRoomId: matrix?.activeRoomId, onSelectNotification: goToRoom, - ), - ); + ); + + BackgroundPush._(this.client) { + //FirebaseMessaging.onMessage.listen(onMessage); + //FirebaseMessaging.onBackgroundMessage(pushHelperBackground); if (Platform.isAndroid) { UnifiedPush.initialize( onNewEndpoint: _newUpEndpoint, @@ -132,7 +131,7 @@ class BackgroundPush { bool useDeviceSpecificAppId = false, }) async { if (PlatformInfos.isIOS) { - await firebase?.requestPermission(); + // await firebase.requestPermission(); } else if (PlatformInfos.isAndroid) { _flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< @@ -289,7 +288,7 @@ class BackgroundPush { Logs().v('Setup firebase'); if (_fcmToken?.isEmpty ?? true) { try { - _fcmToken = await firebase?.getToken(); + //_fcmToken = await firebase.getToken(); if (_fcmToken == null) throw ('PushToken is null'); } catch (e, s) { Logs().w('[Push] cannot get token', e, e is String ? null : s); @@ -358,7 +357,8 @@ class BackgroundPush { Logs().i('[Push] UnifiedPush using endpoint $endpoint'); final oldTokens = {}; try { - final fcmToken = await firebase?.getToken(); + String? fcmToken; + //fcmToken = await firebase.getToken(); oldTokens.add(fcmToken); } catch (_) {} await setupPusher( diff --git a/lib/utils/client_manager.dart b/lib/utils/client_manager.dart index 23d9b024e..db23759f8 100644 --- a/lib/utils/client_manager.dart +++ b/lib/utils/client_manager.dart @@ -23,7 +23,7 @@ import 'matrix_sdk_extensions/flutter_matrix_sdk_database_builder.dart'; abstract class ClientManager { static const String clientNamespace = 'im.fluffychat.store.clients'; static Future> getClients({ - bool initialize = true, + bool isBackgroundClient = false, required SharedPreferences store, }) async { if (PlatformInfos.isLinux) { @@ -44,23 +44,26 @@ abstract class ClientManager { await store.setStringList(clientNamespace, clientNames.toList()); } final clients = clientNames.map(createClient).toList(); - if (initialize) { - await Future.wait( - clients.map( - (client) => client.initWithRestore( - onMigration: () { - final l10n = lookupL10n(PlatformDispatcher.instance.locale); - sendInitNotification( - l10n.databaseMigrationTitle, - l10n.databaseMigrationBody, - ); - }, - ).catchError( - (e, s) => Logs().e('Unable to initialize client', e, s), - ), - ), - ); - } + + await Future.wait( + clients.map( + (client) => client + .initWithRestore( + isBackgroundClient: isBackgroundClient, + onMigration: () { + final l10n = lookupL10n(PlatformDispatcher.instance.locale); + sendInitNotification( + l10n.databaseMigrationTitle, + l10n.databaseMigrationBody, + ); + }, + ) + .catchError( + (e, s) => Logs().e('Unable to initialize client', e, s), + ), + ), + ); + if (clients.length > 1 && clients.any((c) => !c.isLogged())) { final loggedOutClients = clients.where((c) => !c.isLogged()).toList(); for (final client in loggedOutClients) { diff --git a/lib/utils/init_with_restore.dart b/lib/utils/init_with_restore.dart index 04ed47db6..cebc58372 100644 --- a/lib/utils/init_with_restore.dart +++ b/lib/utils/init_with_restore.dart @@ -61,7 +61,10 @@ extension InitWithRestoreExtension on Client { ); } - Future initWithRestore({void Function()? onMigration}) async { + Future initWithRestore({ + bool isBackgroundClient = false, + void Function()? onMigration, + }) async { final storageKey = '${AppConfig.applicationName}_session_backup_$clientName'; final storage = PlatformInfos.isMobile || PlatformInfos.isLinux @@ -73,6 +76,7 @@ extension InitWithRestoreExtension on Client { onMigration: onMigration, waitForFirstSync: false, waitUntilLoadCompletedLoaded: false, + isBackgroundClient: isBackgroundClient, ); if (isLogged()) { final accessToken = this.accessToken; diff --git a/lib/utils/push_helper.dart b/lib/utils/push_helper.dart index d30c1ba76..6e986607f 100644 --- a/lib/utils/push_helper.dart +++ b/lib/utils/push_helper.dart @@ -18,6 +18,10 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/voip/callkeep_manager.dart'; +Future pushHelperBackground(message) => pushHelper( + PushNotification.fromJson(message.data), + ); + Future pushHelper( PushNotification notification, { Client? client, @@ -53,7 +57,7 @@ Future pushHelper( l10n.newMessageInFluffyChat, l10n.openAppToReadMessages, NotificationDetails( - iOS: const DarwinNotificationDetails(), + iOS: const DarwinNotificationDetails(sound: 'notification.caf'), android: AndroidNotificationDetails( AppConfig.pushNotificationsChannelId, l10n.incomingMessages, @@ -101,7 +105,7 @@ Future _tryPushHelper( ); client ??= (await ClientManager.getClients( - initialize: false, + isBackgroundClient: true, store: await SharedPreferences.getInstance(), )) .first; @@ -282,7 +286,9 @@ Future _tryPushHelper( priority: Priority.max, groupKey: notificationGroupId, ); - const iOSPlatformChannelSpecifics = DarwinNotificationDetails(); + const iOSPlatformChannelSpecifics = DarwinNotificationDetails( + sound: "notification.caf", + ); final platformChannelSpecifics = NotificationDetails( android: androidPlatformChannelSpecifics, iOS: iOSPlatformChannelSpecifics, diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index 304fc1636..63f1794ad 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + 3AF44CC3D61A8332019AFCDE /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 5AEFA815523969D4ADFBE7E8 /* GoogleService-Info.plist */; }; 9CAF203E1D098383F2EDFFCB /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B3C62FEBAA272B5A33AFFC95 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ @@ -69,6 +70,7 @@ 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; 35E6B919318905352ECC7D69 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; + 5AEFA815523969D4ADFBE7E8 /* GoogleService-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "Runner/GoogleService-Info.plist"; sourceTree = ""; }; 5CDC3DD55F4AC23D2067B292 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; @@ -110,6 +112,7 @@ 33CC10EE2044A3C60003C045 /* Products */, D73912EC22F37F3D000D13A0 /* Frameworks */, F9F203356080D460FB6D4567 /* Pods */, + 5AEFA815523969D4ADFBE7E8 /* GoogleService-Info.plist */, ); sourceTree = ""; }; @@ -255,6 +258,7 @@ files = ( 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + 3AF44CC3D61A8332019AFCDE /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/macos/Runner/GoogleService-Info.plist b/macos/Runner/GoogleService-Info.plist new file mode 100644 index 000000000..9fe83e59a --- /dev/null +++ b/macos/Runner/GoogleService-Info.plist @@ -0,0 +1,30 @@ + + + + + API_KEY + AIzaSyA8ZUBcuny0HjPwF2Q2fvDyQTC5dG2VHlE + GCM_SENDER_ID + 865731724731 + PLIST_VERSION + 1 + BUNDLE_ID + im.fluffychat.fluffychat + PROJECT_ID + fluffychat-ef3e8 + STORAGE_BUCKET + fluffychat-ef3e8.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:865731724731:ios:6fb777cf513cdb6264309e + + \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 8bbddd734..e2e95db5d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1185,10 +1185,11 @@ packages: matrix: dependency: "direct main" description: - name: matrix - sha256: aa9a7c641c5f99e7839c62c0461b279e5e9a3e803d400e57110f158ac28763d9 - url: "https://pub.dev" - source: hosted + path: "." + ref: "krille/background-client" + resolved-ref: "4c81e56a9a75f85d1df88a759050475d2bd977ed" + url: "https://github.com/famedly/matrix-dart-sdk.git" + source: git version: "0.26.0" matrix_api_lite: dependency: transitive diff --git a/pubspec.yaml b/pubspec.yaml index e11691d1e..67f2a5e94 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,8 +25,9 @@ dependencies: emoji_picker_flutter: ^1.6.4 emoji_proposal: ^0.0.1 emojis: ^0.9.9 - #fcm_shared_isolate: ^0.1.0 file_picker: ^6.1.1 + #firebase_core: ^2.24.2 + #firebase_messaging: ^14.7.9 flutter: sdk: flutter flutter_app_badger: ^1.5.0 @@ -165,6 +166,10 @@ dependency_overrides: ref: null-safety # blocked upgrade of package_info_plus for null safety # https://github.com/creativecreatorormaybenot/wakelock/pull/203 + matrix: + git: + url: https://github.com/famedly/matrix-dart-sdk.git + ref: krille/background-client wakelock_windows: git: url: https://github.com/chandrabezzo/wakelock.git diff --git a/scripts/build-ios.sh b/scripts/build-ios.sh index 7fd791b5e..3a592af9f 100755 --- a/scripts/build-ios.sh +++ b/scripts/build-ios.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -git apply ./scripts/enable-android-google-services.patch +./scripts/enable-google-services.sh FLUFFYCHAT_ORIG_GROUP="im.fluffychat" FLUFFYCHAT_ORIG_TEAM="4NXF6Z997G" #FLUFFYCHAT_NEW_GROUP="com.example.fluffychat" diff --git a/scripts/build-macos.sh b/scripts/build-macos.sh index 11d3e4a09..c565b145f 100755 --- a/scripts/build-macos.sh +++ b/scripts/build-macos.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -git apply ./scripts/enable-android-google-services.patch +./scripts/enable-google-services.sh FLUFFYCHAT_ORIG_GROUP="im.fluffychat" FLUFFYCHAT_ORIG_TEAM="4NXF6Z997G" #FLUFFYCHAT_NEW_GROUP="com.example.fluffychat" diff --git a/scripts/enable-android-google-services.patch b/scripts/enable-android-google-services.patch deleted file mode 100644 index 9d12c28d9..000000000 --- a/scripts/enable-android-google-services.patch +++ /dev/null @@ -1,161 +0,0 @@ -diff --git a/android/app/build.gradle b/android/app/build.gradle -index bf972f30..46cebdc6 100644 ---- a/android/app/build.gradle -+++ b/android/app/build.gradle -@@ -70,6 +70,10 @@ - } - release { - signingConfig signingConfigs.release -+ minifyEnabled false -+ shrinkResources false -+ -+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - // https://stackoverflow.com/a/77494454/8222484 -@@ -78,8 +82,11 @@ flutter { - - dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -- //implementation 'com.google.firebase:firebase-messaging:19.0.1' // Workaround for https://github.com/microg/android_packages_apps_GmsCore/issues/313#issuecomment-617651698 -+ implementation 'com.google.firebase:firebase-messaging:19.0.1' // Workaround for https://github.com/microg/android_packages_apps_GmsCore/issues/313#issuecomment-617651698 -+ testImplementation 'junit:junit:4.12' -+ androidTestImplementation 'androidx.test:runner:1.1.1' -+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' - implementation 'androidx.multidex:multidex:2.0.1' - } - --//apply plugin: 'com.google.gms.google-services' -+apply plugin: 'com.google.gms.google-services' -diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro -index d0e0fbc9..0a546da0 100644 ---- a/android/app/proguard-rules.pro -+++ b/android/app/proguard-rules.pro -@@ -1 +1,42 @@ ---keep class net.sqlcipher.** { *; } -\ No newline at end of file -+-optimizationpasses 5 -+## Flutter wrapper -+-keep class net.sqlcipher.** { *; } -+-keep class io.flutter.app.** { *; } -+-keep class io.flutter.plugin.** { *; } -+-keep class io.flutter.util.** { *; } -+-keep class io.flutter.view.** { *; } -+-keep class io.flutter.** { *; } -+-keep class io.flutter.plugins.** { *; } -+-dontwarn io.flutter.embedding.** -+ -+##---------------Begin: proguard configuration for Gson (Needed for flutter_local_notifications) ---------- -+# Gson uses generic type information stored in a class file when working with fields. Proguard -+# removes such information by default, so configure it to keep all of it. -+-keepattributes Signature -+ -+# For using GSON @Expose annotation -+-keepattributes *Annotation* -+ -+# Gson specific classes -+-dontwarn sun.misc.** -+ -+# Application classes that will be serialized/deserialized over Gson -+-keep class com.google.gson.examples.android.model.** { ; } -+ -+# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory, -+# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) -+-keep class * extends com.google.gson.TypeAdapter -+-keep class * implements com.google.gson.TypeAdapterFactory -+-keep class * implements com.google.gson.JsonSerializer -+-keep class * implements com.google.gson.JsonDeserializer -+ -+# Prevent R8 from leaving Data object members always null -+-keepclassmembers,allowobfuscation class * { -+ @com.google.gson.annotations.SerializedName ; -+} -+ -+# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher. -+-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken -+-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken -+ -+##---------------End: proguard configuration for Gson (Needed for flutter_local_notifications) ---------- -\ No newline at end of file -diff --git a/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt b/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt -index d9930f55..510e9845 100644 ---- a/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt -+++ b/android/app/src/main/kotlin/chat/fluffy/fluffychat/FcmPushService.kt -@@ -1,4 +1,4 @@ --/*package chat.fluffy.fluffychat -+package chat.fluffy.fluffychat - - import com.famedly.fcm_shared_isolate.FcmSharedIsolateService - -@@ -33,4 +33,3 @@ class FcmPushService : FcmSharedIsolateService() { - } - } - } --*/ -\ No newline at end of file -diff --git a/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt b/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt -index 1afc4606..894d1571 100644 ---- a/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt -+++ b/android/app/src/main/kotlin/chat/fluffy/fluffychat/MainActivity.kt -@@ -7,13 +7,11 @@ import android.content.Context - import androidx.multidex.MultiDex - - class MainActivity : FlutterActivity() { -- - override fun attachBaseContext(base: Context) { - super.attachBaseContext(base) - MultiDex.install(this) - } - -- - override fun provideFlutterEngine(context: Context): FlutterEngine? { - return provideEngine(this) - } -diff --git a/android/build.gradle b/android/build.gradle -index bd394967..2e9d54de 100644 ---- a/android/build.gradle -+++ b/android/build.gradle -@@ -8,7 +8,7 @@ buildscript { - dependencies { - classpath 'com.android.tools.build:gradle:7.1.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" -- //classpath 'com.google.gms:google-services:4.3.8' -+ classpath 'com.google.gms:google-services:4.3.8' - } - } - -diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart -index 8e67ae92..da4da5c3 100644 ---- a/lib/utils/background_push.dart -+++ b/lib/utils/background_push.dart -@@ -39,7 +39,7 @@ import '../config/setting_keys.dart'; - import '../widgets/matrix.dart'; - import 'platform_infos.dart'; - --//import 'package:fcm_shared_isolate/fcm_shared_isolate.dart'; -+import 'package:fcm_shared_isolate/fcm_shared_isolate.dart'; - - class NoTokenException implements Exception { - String get cause => 'Cannot get firebase token'; -@@ -64,7 +64,7 @@ class BackgroundPush { - - final pendingTests = >{}; - -- final dynamic firebase = null; //FcmSharedIsolate(); -+ final dynamic firebase = FcmSharedIsolate(); - - DateTime? lastReceivedPush; - -diff --git a/pubspec.yaml b/pubspec.yaml -index 193e6ed6..f70e48d4 100644 ---- a/pubspec.yaml -+++ b/pubspec.yaml -@@ -26,7 +26,7 @@ dependencies: - emoji_picker_flutter: ^1.6.4 - emoji_proposal: ^0.0.1 - emojis: ^0.9.9 -- #fcm_shared_isolate: ^0.1.0 -+ fcm_shared_isolate: ^0.1.0 - file_picker: ^6.1.1 - flutter: - sdk: flutter diff --git a/scripts/enable-google-services.sh b/scripts/enable-google-services.sh new file mode 100755 index 000000000..10b032c34 --- /dev/null +++ b/scripts/enable-google-services.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +sed -i 's/#//g' pubspec.yaml +sed -i 's,//,,g' android/build.gradle +sed -i 's,//,,g' android/app/build.gradle +sed -i 's,//,,g' lib/main.dart +sed -i 's,//,,g' lib/utils/background_push.dart \ No newline at end of file diff --git a/scripts/release-ios-testflight.sh b/scripts/release-ios-testflight.sh index e3f1a109a..586a83db3 100755 --- a/scripts/release-ios-testflight.sh +++ b/scripts/release-ios-testflight.sh @@ -1,5 +1,5 @@ #!/bin/sh -ve -git apply ./scripts/enable-android-google-services.patch +./scripts/enable-google-services.sh rm -rf fonts/NotoEmoji yq -i 'del( .flutter.fonts[] | select(.family == "NotoEmoji") )' pubspec.yaml flutter clean