Skip to content

Commit 1ccc674

Browse files
authored
Merge pull request #228 from Wolfteam/feature/remove_appcenter
feature/remove_appcenter
2 parents 9e512a5 + 5703e9d commit 1ccc674

42 files changed

Lines changed: 633 additions & 693 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.fvm/fvm_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"flutterSdkVersion": "3.22.2"
2+
"flutterSdkVersion": "3.22.3"
33
}

.fvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"flutter": "3.22.2",
2+
"flutter": "3.22.3",
33
"flavors": {}
44
}

android/app/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ dependencies {
104104
implementation 'androidx.annotation:annotation:1.1.0'
105105
implementation "com.jakewharton.threetenabp:threetenabp:1.2.3"
106106

107-
def appCenterSdkVersion = '4.4.5'
108-
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
109-
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
110-
111107
// Required by the notifications plugin
112108
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
113109
implementation 'androidx.window:window:1.0.0'

android/app/src/main/kotlin/com/miraisoft/shiori/MainActivity.kt

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package com.miraisoft.shiori
22

33
import android.util.Log
44
import androidx.annotation.NonNull
5-
import com.microsoft.appcenter.AppCenter
6-
import com.microsoft.appcenter.analytics.Analytics
7-
import com.microsoft.appcenter.crashes.Crashes
85
import io.flutter.embedding.android.FlutterActivity
96
import io.flutter.embedding.engine.FlutterEngine
107
import io.flutter.plugin.common.MethodCall
@@ -25,49 +22,6 @@ class MainActivity : FlutterActivity() {
2522
Log.d("onMethodCall", "[$methodChannelName] ${call.method}")
2623
try {
2724
when (call.method) {
28-
"start" -> {
29-
if (activity.application == null) {
30-
val error = "Fail to resolve Application on registration"
31-
Log.e(call.method, error)
32-
result.error(call.method, error, Exception(error))
33-
return
34-
}
35-
36-
val appSecret = call.argument<String>("secret")
37-
if (appSecret == null || appSecret.isEmpty()) {
38-
val error = "App secret is not set"
39-
Log.e(call.method, error)
40-
result.error(call.method, error, Exception(error))
41-
return
42-
}
43-
44-
AppCenter.start(activity.application, appSecret, Analytics::class.java, Crashes::class.java)
45-
}
46-
"trackEvent" -> {
47-
val name = call.argument<String>("name")
48-
val properties = call.argument<Map<String, String>>("properties")
49-
Analytics.trackEvent(name, properties)
50-
}
51-
"getInstallId" -> {
52-
result.success(AppCenter.getInstallId().get()?.toString())
53-
return
54-
}
55-
"isCrashesEnabled" -> {
56-
result.success(Crashes.isEnabled().get())
57-
return
58-
}
59-
"configureCrashes" -> {
60-
val value = call.arguments as Boolean
61-
Crashes.setEnabled(value).get()
62-
}
63-
"isAnalyticsEnabled" -> {
64-
result.success(Analytics.isEnabled().get())
65-
return
66-
}
67-
"configureAnalytics" -> {
68-
val value = call.arguments as Boolean
69-
Analytics.setEnabled(value).get()
70-
}
7125
else -> {
7226
result.notImplemented()
7327
}

ios/Podfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,3 @@ post_install do |installer|
3939
flutter_additional_ios_build_settings(target)
4040
end
4141
end
42-
43-
pod 'AppCenter'

ios/Podfile.lock

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
PODS:
2-
- AppCenter (5.0.4):
3-
- AppCenter/Analytics (= 5.0.4)
4-
- AppCenter/Crashes (= 5.0.4)
5-
- AppCenter/Analytics (5.0.4):
6-
- AppCenter/Core
7-
- AppCenter/Core (5.0.4)
8-
- AppCenter/Crashes (5.0.4):
9-
- AppCenter/Core
102
- device_info_plus (0.0.1):
113
- Flutter
124
- devicelocale (0.0.1):
@@ -74,15 +66,15 @@ PODS:
7466
- FlutterMacOS
7567
- permission_handler_apple (9.3.0):
7668
- Flutter
77-
- purchases_flutter (6.29.3):
69+
- purchases_flutter (6.30.1):
7870
- Flutter
79-
- PurchasesHybridCommon (= 10.8.0)
80-
- PurchasesHybridCommon (10.8.0):
81-
- RevenueCat (= 4.42.0)
71+
- PurchasesHybridCommon (= 11.1.0)
72+
- PurchasesHybridCommon (11.1.0):
73+
- RevenueCat (= 4.43.2)
8274
- rate_my_app (2.2.0):
8375
- Flutter
8476
- FlutterMacOS
85-
- RevenueCat (4.42.0)
77+
- RevenueCat (4.43.2)
8678
- SDWebImage (5.18.3):
8779
- SDWebImage/Core (= 5.18.3)
8880
- SDWebImage/Core (5.18.3)
@@ -101,7 +93,6 @@ PODS:
10193
- Flutter
10294

10395
DEPENDENCIES:
104-
- AppCenter
10596
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
10697
- devicelocale (from `.symlinks/plugins/devicelocale/ios`)
10798
- file_picker (from `.symlinks/plugins/file_picker/ios`)
@@ -126,7 +117,6 @@ DEPENDENCIES:
126117

127118
SPEC REPOS:
128119
trunk:
129-
- AppCenter
130120
- DKImagePickerController
131121
- DKPhotoGallery
132122
- OrderedSet
@@ -181,7 +171,6 @@ EXTERNAL SOURCES:
181171
:path: ".symlinks/plugins/wakelock_plus/ios"
182172

183173
SPEC CHECKSUMS:
184-
AppCenter: 85c92db0759d2792a65eb61d6842d2e86611a49a
185174
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
186175
devicelocale: 35ba84dc7f45f527c3001535d8c8d104edd5d926
187176
DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac
@@ -199,10 +188,10 @@ SPEC CHECKSUMS:
199188
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
200189
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
201190
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
202-
purchases_flutter: 71bcb09c0ef69612abe998ab895277421e85e968
203-
PurchasesHybridCommon: dff07d838f74ac859a6ce20f0fbee527ba61e035
191+
purchases_flutter: a7dba78a5da88e0672a881372d2a34478e723537
192+
PurchasesHybridCommon: 4022d5944cb30ec44ba5159e42aa161fe0e30175
204193
rate_my_app: cd3e1c44d12f387482698ffaf6ea9bd669a69b94
205-
RevenueCat: 39f2fbf5eda66f0f87bb72329406f45488f6916e
194+
RevenueCat: 3d934653b7e8b09af88fd47e9e84cfaf5d0a89ba
206195
SDWebImage: 96e0c18ef14010b7485210e92fac888587ebb958
207196
share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad
208197
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
@@ -212,6 +201,6 @@ SPEC CHECKSUMS:
212201
url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586
213202
wakelock_plus: 78ec7c5b202cab7761af8e2b2b3d0671be6c4ae1
214203

215-
PODFILE CHECKSUM: a1eaf986c30d5a84309bbcd4434682ef102516a3
204+
PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
216205

217206
COCOAPODS: 1.15.2

ios/Runner/AppDelegate.swift

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import UIKit
22
import Flutter
3-
import AppCenter
4-
import AppCenterAnalytics
5-
import AppCenterCrashes
63

74
@UIApplicationMain
85
@objc class AppDelegate: FlutterAppDelegate {
@@ -29,52 +26,10 @@ import AppCenterCrashes
2926
public func methodChannelHandler(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
3027
debugPrint(call.method)
3128
switch call.method {
32-
case "start":
33-
guard let args: [String: Any] = (call.arguments as? [String: Any]) else {
34-
result(FlutterError(code: "400", message: "Bad arguments", details: "iOS could not recognize flutter arguments in method: (start)") )
35-
return
36-
}
37-
38-
let secret = args["secret"] as! String
39-
AppCenter.start(withAppSecret: secret, services: [
40-
Analytics.self,
41-
Crashes.self,
42-
])
43-
case "trackEvent":
44-
trackEvent(call: call, result: result)
45-
return
46-
case "getInstallId":
47-
result(AppCenter.installId.uuidString)
48-
return
49-
case "isCrashesEnabled":
50-
result(Crashes.enabled)
51-
return
52-
case "configureCrashes":
53-
Crashes.enabled = call.arguments as! Bool
54-
case "isAnalyticsEnabled":
55-
result(Analytics.enabled)
56-
return
57-
case "configureAnalytics":
58-
Analytics.enabled = call.arguments as! Bool
5929
default:
6030
result(FlutterMethodNotImplemented);
6131
return
6232
}
6333
result(nil);
6434
}
65-
66-
private func trackEvent(call: FlutterMethodCall, result: FlutterResult) {
67-
guard let args:[String: Any] = (call.arguments as? [String: Any]) else {
68-
result(FlutterError(code: "400", message: "Bad arguments", details: "iOS could not recognize flutter arguments in method: (trackEvent)") )
69-
return
70-
}
71-
72-
let name = args["name"] as? String
73-
let properties = args["properties"] as? [String: String]
74-
if(name != nil) {
75-
Analytics.trackEvent(name!, withProperties: properties)
76-
}
77-
78-
result(nil)
79-
}
8035
}

lib/application/game_codes/game_codes_bloc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class GameCodesBloc extends Bloc<GameCodesEvent, GameCodesState> {
162162
return true;
163163
}
164164

165-
final isAfter = DateTime.now().isAfter(lastCheckedDate.add(const Duration(hours: 4)));
165+
final isAfter = DateTime.now().isAfter(lastCheckedDate.add(const Duration(hours: 3)));
166166
if (!isAfter) {
167167
return false;
168168
}

lib/application/main/main_bloc.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ class MainBloc extends Bloc<MainEvent, MainState> {
6767
yield s;
6868
}
6969

70-
Future<MainState> _init({
71-
bool languageChanged = false,
72-
bool init = false,
73-
AppResourceUpdateResultType? updateResult,
74-
}) async {
70+
Future<MainState> _init({bool languageChanged = false, bool init = false, AppResourceUpdateResultType? updateResult}) async {
7571
_logger.info(runtimeType, '_init: Initializing all..');
7672
await _genshinService.init(_settingsService.language, noResourcesHaveBeenDownloaded: _settingsService.noResourcesHasBeenDownloaded);
7773

lib/application/splash/splash_bloc.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import 'dart:async';
33
import 'package:bloc/bloc.dart';
44
import 'package:freezed_annotation/freezed_annotation.dart';
55
import 'package:shiori/domain/enums/enums.dart';
6+
import 'package:shiori/domain/extensions/datetime_extensions.dart';
7+
import 'package:shiori/domain/models/dtos.dart';
8+
import 'package:shiori/domain/models/entities.dart';
69
import 'package:shiori/domain/models/models.dart';
10+
import 'package:shiori/domain/services/api_service.dart';
11+
import 'package:shiori/domain/services/data_service.dart';
712
import 'package:shiori/domain/services/device_info_service.dart';
813
import 'package:shiori/domain/services/locale_service.dart';
14+
import 'package:shiori/domain/services/network_service.dart';
915
import 'package:shiori/domain/services/resources_service.dart';
1016
import 'package:shiori/domain/services/settings_service.dart';
1117
import 'package:shiori/domain/services/telemetry_service.dart';
@@ -20,6 +26,9 @@ class SplashBloc extends Bloc<SplashEvent, SplashState> {
2026
final SettingsService _settingsService;
2127
final DeviceInfoService _deviceInfoService;
2228
final TelemetryService _telemetryService;
29+
final DataService _dataService;
30+
final ApiService _apiService;
31+
final NetworkService _networkService;
2332
final LanguageModel _language;
2433

2534
StreamSubscription? _downloadStream;
@@ -29,12 +38,17 @@ class SplashBloc extends Bloc<SplashEvent, SplashState> {
2938
this._settingsService,
3039
this._deviceInfoService,
3140
this._telemetryService,
41+
this._dataService,
42+
this._apiService,
43+
this._networkService,
3244
LocaleService localeService,
3345
) : _language = localeService.getLocaleWithoutLang(),
3446
super(const SplashState.loading());
3547

3648
@override
3749
Stream<SplashState> mapEventToState(SplashEvent event) async* {
50+
await _sendTelemetryData();
51+
3852
if (event is _Init) {
3953
final noResourcesHasBeenDownloaded = _settingsService.noResourcesHasBeenDownloaded;
4054
//This is just to trigger a change in the ui
@@ -209,4 +223,23 @@ class SplashBloc extends Bloc<SplashEvent, SplashState> {
209223
return (type == AppResourceUpdateResultType.unknownError || type == AppResourceUpdateResultType.apiIsUnavailable) &&
210224
_settingsService.noResourcesHasBeenDownloaded;
211225
}
226+
227+
Future<void> _sendTelemetryData() async {
228+
final bool isNetworkAvailable = await _networkService.isInternetAvailable();
229+
if (!isNetworkAvailable) {
230+
return;
231+
}
232+
final List<Telemetry> telemetryData = _dataService.telemetry.getAll();
233+
final bool send = telemetryData.isNotEmpty && telemetryData.length > 5;
234+
if (!send) {
235+
return;
236+
}
237+
238+
final logs = telemetryData.map((t) => SaveAppLogRequestDto(timestamp: t.createdAt.ticks, message: t.message)).toList();
239+
final request = SaveAppLogsRequestDto(logs: logs);
240+
await Future.wait([
241+
_apiService.sendTelemetryData(request),
242+
_dataService.telemetry.deleteByIds(telemetryData.map((t) => t.id).toList()),
243+
]);
244+
}
212245
}

0 commit comments

Comments
 (0)