Compare commits

...

2 Commits

Author SHA1 Message Date
67c9ff699c feat: sentry 异常捕获 2024-03-23 14:15:51 +08:00
74f31a818c Merge branch 'main' into feature-sentry 2024-03-23 00:41:12 +08:00
10 changed files with 95 additions and 8 deletions

View File

@ -45,6 +45,13 @@ PODS:
- Flutter
- screen_brightness_ios (0.1.0):
- Flutter
- Sentry/HybridSDK (8.19.0):
- SentryPrivate (= 8.19.0)
- sentry_flutter (0.0.1):
- Flutter
- FlutterMacOS
- Sentry/HybridSDK (= 8.19.0)
- SentryPrivate (8.19.0)
- share_plus (0.0.1):
- Flutter
- sqflite (0.0.3):
@ -86,6 +93,7 @@ DEPENDENCIES:
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- saver_gallery (from `.symlinks/plugins/saver_gallery/ios`)
- screen_brightness_ios (from `.symlinks/plugins/screen_brightness_ios/ios`)
- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- status_bar_control (from `.symlinks/plugins/status_bar_control/ios`)
@ -101,6 +109,8 @@ SPEC REPOS:
- FMDB
- GT3Captcha-iOS
- ReachabilitySwift
- Sentry
- SentryPrivate
- Toast
EXTERNAL SOURCES:
@ -142,6 +152,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/saver_gallery/ios"
screen_brightness_ios:
:path: ".symlinks/plugins/screen_brightness_ios/ios"
sentry_flutter:
:path: ".symlinks/plugins/sentry_flutter/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
sqflite:
@ -184,6 +196,9 @@ SPEC CHECKSUMS:
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
saver_gallery: 2b4e584106fde2407ab51560f3851564963e6b78
screen_brightness_ios: 715ca807df953bf676d339f11464e438143ee625
Sentry: 1ebcaef678a27c8ac515f974cb5425dd1bbdec2f
sentry_flutter: ecdfbedee55337205561cfa782ee02d31ec83e1f
SentryPrivate: 765c9b4ebe9ac1a5fcdc067c5a1cfbf3f10e1677
share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
status_bar_control: 7c84146799e6a076315cc1550f78ef53aae3e446

View File

@ -25,6 +25,9 @@ import 'package:media_kit/media_kit.dart'; // Provides [Player], [Media], [Playl
import 'package:pilipala/utils/recommend_filter.dart';
import 'package:catcher_2/catcher_2.dart';
import './services/loggeer.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'services/sentry.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
@ -55,14 +58,36 @@ void main() async {
[FileHandler(await getLogsPath())],
);
Catcher2(
debugConfig: debugConfig,
releaseConfig: releaseConfig,
runAppFunction: () {
runApp(const MyApp());
},
// Catcher2(
// debugConfig: debugConfig,
// releaseConfig: releaseConfig,
// runAppFunction: () {
// runApp(const MyApp());
// },
// );
await SentryService.sentryInit(
() => runApp(
SentryScreenshotWidget(
child: SentryUserInteractionWidget(
child: DefaultAssetBundle(
bundle: SentryAssetBundle(),
child: const MyApp(),
),
),
),
),
);
// try {
// int? test;
// test! + 3;
// } catch (exception, stackTrace) {
// debugPrint('111');
// await Sentry.captureException(exception, stackTrace: '$stackTrace');
// debugPrint('222');
// }
// 小白条、导航栏沉浸
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
@ -195,6 +220,7 @@ class MyApp extends StatelessWidget {
navigatorObservers: [
VideoDetailPage.routeObserver,
SearchPage.routeObserver,
SentryNavigatorObserver(),
],
);
}),

26
lib/services/sentry.dart Normal file
View File

@ -0,0 +1,26 @@
import 'package:sentry_flutter/sentry_flutter.dart';
class SentryService {
static sentryInit(AppRunner appRunner) async {
return await SentryFlutter.init(
(options) => options
..dsn =
'https://cb0ce70fcda1c903072a6c73cc2d89e2@o4506669621182464.ingest.sentry.io/4506669624459264'
..debug = true // 调试模式下启用
..attachThreads = true // 附带线程信息
..sendDefaultPii = true
..reportPackages = false // 禁用报告包信息
..tracesSampleRate = 0.1 // 要发送的事件百分比
..attachScreenshot = false // 屏幕截图
..attachViewHierarchy = true // 包含视图结构
..reportSilentFlutterErrors = true // 报告静默的 Flutter 错误
..enableAutoPerformanceTracing = true // 自动性能跟踪
..considerInAppFramesByDefault = false // 不考虑应用内帧
..enableWindowMetricBreadcrumbs = true // 启用窗口度量面包屑
..screenshotQuality = SentryScreenshotQuality.low // 屏幕截图质量
..maxRequestBodySize = MaxRequestBodySize.small // 请求体大小
..maxResponseBodySize = MaxResponseBodySize.small, // 响应体大小
appRunner: appRunner,
);
}
}

View File

@ -10,6 +10,7 @@
#include <flutter_volume_controller/flutter_volume_controller_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
#include <media_kit_video/media_kit_video_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
@ -25,6 +26,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) media_kit_video_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKitVideoPlugin");
media_kit_video_plugin_register_with_registrar(media_kit_video_registrar);
g_autoptr(FlPluginRegistrar) sentry_flutter_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SentryFlutterPlugin");
sentry_flutter_plugin_register_with_registrar(sentry_flutter_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

View File

@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_volume_controller
media_kit_libs_linux
media_kit_video
sentry_flutter
url_launcher_linux
)

View File

@ -16,6 +16,7 @@ import media_kit_video
import package_info_plus
import path_provider_foundation
import screen_brightness_macos
import sentry_flutter
import share_plus
import sqflite
import url_launcher_macos
@ -33,6 +34,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenBrightnessMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenBrightnessMacosPlugin"))
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))

View File

@ -1267,10 +1267,18 @@ packages:
dependency: transitive
description:
name: sentry
sha256: "5686ed515bb620dc52b4ae99a6586fe720d443591183cf1f620ec5d1f0eec100"
sha256: a7946f4a90b0feb47214981d881b98149e05f6c576da9f2a2f33945bf561de25
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.15.0"
version: "7.16.0"
sentry_flutter:
dependency: "direct main"
description:
name: sentry_flutter
sha256: "6db7fa1b076faf2f5dd77d8cc9ef206171f32a290cc638842d78e5d62b441a27"
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.16.0"
share_plus:
dependency: "direct main"
description:

View File

@ -142,6 +142,7 @@ dependencies:
path: 1.8.3
# 电池优化
disable_battery_optimization: ^1.1.1
sentry_flutter: ^7.16.0
dev_dependencies:
flutter_test:

View File

@ -13,6 +13,7 @@
#include <media_kit_video/media_kit_video_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <screen_brightness_windows/screen_brightness_windows_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>
@ -31,6 +32,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
ScreenBrightnessWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin"));
SentryFlutterPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SentryFlutterPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(

View File

@ -10,6 +10,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
media_kit_video
permission_handler_windows
screen_brightness_windows
sentry_flutter
share_plus
url_launcher_windows
)