Skip to content

Commit

Permalink
feat: add sentry sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Feb 22, 2024
1 parent edf195d commit 330dc94
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
6 changes: 6 additions & 0 deletions PrivacyPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ Especially, your password only stored in memory and is never written to disk.
Your data is only transferred to the server specified by you. We do not collect any data from you by default.

Note that the server provider may share your data with third parties. Please refer to the privacy policy of the server provider.

## Sentry SDK

We use Sentry SDK to collect crash reports and usage statistics. Sentry SDK is disabled by default. Please refer to the [Sentry Privacy Policy](https://sentry.io/privacy/) for more information.

Please note that for `dev` and `alpha` builds (versions that contain these words in the version number), Sentry SDK is force enabled. These builds are primarily used by our developers and testers for debugging and feature testing. If you are using these builds, please be aware that crash reports and usage statistics will be collected automatically.
1 change: 1 addition & 0 deletions lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class DotEnvValue {
static String host = dotenv.env['HOST'] ?? '';
static String port = dotenv.env['PORT'] ?? '';
static String tls = dotenv.env['TLS'] ?? '';
static String enableSentry = dotenv.env['ENABLE_SENTRY'] ?? '';
}

const wellKnownAccountPlatforms = ['steam'];
34 changes: 24 additions & 10 deletions lib/init.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
part of 'main.dart';

Future<MyApp> init() async {
// dotenv
await dotenv.load(fileName: '.env');

// dao
WidgetsFlutterBinding.ensureInitialized();
final packageInfo = await PackageInfo.fromPlatform();

// https://github.com/hivedb/hive/issues/1044
final path = PlatformHelper.isWeb()
final dataPath = PlatformHelper.isWeb()
? null
: (await getApplicationSupportDirectory()).path;
await Hive.initFlutter(path);

// dotenv
var enableSentry = false;
if (File(path.join(dataPath ?? '', '.enable_sentry')).existsSync()) {
enableSentry = true;
}
if (packageInfo.version.contains('dev') ||
packageInfo.version.contains('alpha')) {
enableSentry = true;
}
if (enableSentry) {
await dotenv.load(mergeWith: {
'ENABLE_SENTRY': enableSentry.toString(),
});
} else {
await dotenv.load();
}

// dao
await Hive.initFlutter(dataPath);

// repo
final common = await ClientCommonRepo.init();
Expand All @@ -21,8 +38,6 @@ Future<MyApp> init() async {
// system tray
await _initSystemTray();

WidgetsFlutterBinding.ensureInitialized();

// deep link
if (PlatformHelper.isWindowsApp()) {
registerProtocol('tuihub');
Expand All @@ -38,12 +53,11 @@ Future<MyApp> init() async {
if (kDebugMode) {
Bloc.observer = SimpleBlocObserver();
}
final packageInfo = await PackageInfo.fromPlatform();
final deviceInfo = await _genClientDeviceInfo();
final clientSettingBloc = ClientSettingBloc(common);
final deepLinkBloc = DeepLinkBloc(initialUri);
final mainBloc = MainBloc(api, common, clientSettingBloc, deepLinkBloc,
packageInfo, deviceInfo, path);
packageInfo, deviceInfo, dataPath);

// router
final router = getRouter(mainBloc, api);
Expand Down
20 changes: 19 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:system_tray/system_tray.dart';
import 'package:uni_links/uni_links.dart';
import 'package:uni_links_desktop/uni_links_desktop.dart';
import 'package:universal_io/io.dart';

import 'bloc/chesed/chesed_bloc.dart';
import 'bloc/client_setting/client_setting_bloc.dart';
Expand All @@ -29,6 +32,7 @@ import 'bloc/tiphereth/tiphereth_bloc.dart';
import 'bloc/yesod/yesod_bloc.dart';
import 'common/bloc_observer.dart';
import 'common/platform.dart';
import 'consts.dart';
import 'l10n/l10n.dart';
import 'model/common_model.dart';
import 'repo/grpc/api_helper.dart';
Expand All @@ -45,7 +49,21 @@ void main(List<String> args) async {

final app = await init();

runApp(app);
if (DotEnvValue.enableSentry.isNotEmpty &&
DotEnvValue.enableSentry == true.toString()) {
await SentryFlutter.init(
(options) {
options.dsn =
'https://[email protected]/5885';
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1.0;
},
appRunner: () => runApp(app),
);
} else {
runApp(app);
}

if (PlatformHelper.isWindowsApp()) {
doWhenWindowReady(() {
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 9.9.9+1 # Used in debug mode, the real version is generated by git tag
version: 9.9.9-debug+1 # Used in debug mode, the real version is generated by git tag

environment:
sdk: '>=3.0.0 <4.0.0'
Expand All @@ -32,6 +32,7 @@ dependencies:
sdk: flutter
flutter_localizations:
sdk: flutter
sentry_flutter: ^7.16.1

# state management
bloc: ^8.1.3
Expand Down

0 comments on commit 330dc94

Please sign in to comment.