mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-29 14:06:47 +00:00
Merge branch 'sentry-fix'
This commit is contained in:
commit
dbc2a7b12b
@ -7,9 +7,11 @@
|
||||
additional functionality it is fine to subclass or reimplement
|
||||
FlutterApplication and put your custom class here. -->
|
||||
<application
|
||||
android:name="io.flutter.app.FlutterApplication"
|
||||
android:label="InvenTree"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
@ -17,13 +19,20 @@
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- until Flutter renders its first frame. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
||||
android:resource="@drawable/launch_background" />
|
||||
|
||||
<!-- Theme to apply as soon as Flutter begins rendering frames -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
<!-- This keeps the window background of the activity showing
|
||||
until Flutter renders its first frame. It can be removed if
|
||||
there is no splash screen (such as the default splash screen
|
||||
defined in @style/LaunchTheme). -->
|
||||
<meta-data
|
||||
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
|
||||
android:value="true" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
@ -1,13 +1,6 @@
|
||||
package inventree.inventree_app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import io.flutter.app.FlutterActivity;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
GeneratedPluginRegistrant.registerWith(this);
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,8 @@
|
||||
Flutter draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- You can name this style whatever you'd like -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@ -143,7 +143,7 @@ class InvenTreeAPI {
|
||||
// Connection status flag - set once connection has been validated
|
||||
bool _connected = false;
|
||||
|
||||
bool _connecting = true;
|
||||
bool _connecting = false;
|
||||
|
||||
bool isConnected() {
|
||||
return profile != null && _connected && baseUrl.isNotEmpty && _token.isNotEmpty;
|
||||
|
134
lib/main.dart
134
lib/main.dart
@ -1,21 +1,20 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/widget/home.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:device_info/device_info.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
|
||||
import 'dsn.dart';
|
||||
|
||||
import 'package:sentry/sentry.dart';
|
||||
|
||||
// Use the secret app key
|
||||
final SentryClient _sentry = SentryClient(
|
||||
SentryOptions(
|
||||
dsn: SENTRY_DSN_KEY,
|
||||
));
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
bool isInDebugMode() {
|
||||
bool inDebugMode = false;
|
||||
@ -26,33 +25,122 @@ bool isInDebugMode() {
|
||||
}
|
||||
|
||||
Future<void> _reportError(dynamic error, dynamic stackTrace) async {
|
||||
// Print the exception to the console.
|
||||
|
||||
print('Caught error: $error');
|
||||
|
||||
// Errors thrown in development mode are unlikely to be interesting. You can
|
||||
// check if you are running in dev mode using an assertion and omit sending
|
||||
// the report.
|
||||
if (isInDebugMode()) {
|
||||
// Print the full stacktrace in debug mode.
|
||||
print(stackTrace);
|
||||
print('In dev mode. Not sending report to Sentry.io.');
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
await _sentry.captureException(
|
||||
error,
|
||||
stackTrace: stackTrace
|
||||
);
|
||||
} catch (e) {
|
||||
print("Sending error report to sentry.io failed: ${e}");
|
||||
print("Original error: ${error}");
|
||||
}
|
||||
}
|
||||
|
||||
print('Reporting to Sentry.io...');
|
||||
|
||||
// Extract device information
|
||||
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
|
||||
Map<String, dynamic> device_info = {};
|
||||
|
||||
// Extract some platform information
|
||||
if (Platform.isIOS) {
|
||||
final iosDeviceInfo = await deviceInfo.iosInfo;
|
||||
|
||||
device_info = {
|
||||
'name': iosDeviceInfo.name,
|
||||
'model': iosDeviceInfo.model,
|
||||
'systemName': iosDeviceInfo.systemName,
|
||||
'systemVersion': iosDeviceInfo.systemVersion,
|
||||
'localizedModel': iosDeviceInfo.localizedModel,
|
||||
'utsname': iosDeviceInfo.utsname.sysname,
|
||||
'identifierForVendor': iosDeviceInfo.identifierForVendor,
|
||||
'isPhysicalDevice': iosDeviceInfo.isPhysicalDevice,
|
||||
};
|
||||
|
||||
} else if (Platform.isAndroid) {
|
||||
final androidDeviceInfo = await deviceInfo.androidInfo;
|
||||
|
||||
device_info = {
|
||||
'type': androidDeviceInfo.type,
|
||||
'model': androidDeviceInfo.model,
|
||||
'device': androidDeviceInfo.device,
|
||||
'id': androidDeviceInfo.id,
|
||||
'androidId': androidDeviceInfo.androidId,
|
||||
'brand': androidDeviceInfo.brand,
|
||||
'display': androidDeviceInfo.display,
|
||||
'hardware': androidDeviceInfo.hardware,
|
||||
'manufacturer': androidDeviceInfo.manufacturer,
|
||||
'product': androidDeviceInfo.product,
|
||||
'version': androidDeviceInfo.version.release,
|
||||
'supported32BitAbis': androidDeviceInfo.supported32BitAbis,
|
||||
'supported64BitAbis': androidDeviceInfo.supported64BitAbis,
|
||||
'supportedAbis': androidDeviceInfo.supportedAbis,
|
||||
'isPhysicalDevice': androidDeviceInfo.isPhysicalDevice,
|
||||
};
|
||||
}
|
||||
|
||||
// Add app info
|
||||
final package_info = await PackageInfo.fromPlatform();
|
||||
|
||||
Map<String, dynamic> app_version_info = {
|
||||
"name": package_info.appName,
|
||||
"build": package_info.buildNumber,
|
||||
"version": package_info.version,
|
||||
"package": package_info.packageName,
|
||||
};
|
||||
|
||||
// Add server info (anonymized)
|
||||
Map<String, dynamic> server_info = {
|
||||
"version": InvenTreeAPI().version,
|
||||
};
|
||||
|
||||
Sentry.configureScope((scope) {
|
||||
scope.setExtra("server", server_info);
|
||||
scope.setExtra("app", app_version_info);
|
||||
scope.setExtra("device", device_info);
|
||||
});
|
||||
|
||||
Sentry.captureException(error, stackTrace: stackTrace).catchError((error) {
|
||||
print("Error uploading information to Sentry.io:");
|
||||
print(error);
|
||||
}).then((response) {
|
||||
print("Uploaded information to Sentry.io : ${response.toString()}");
|
||||
});
|
||||
}
|
||||
|
||||
void main() async {
|
||||
|
||||
|
||||
await Sentry.init((options) {
|
||||
options.dsn = SENTRY_DSN_KEY;
|
||||
},
|
||||
//appRunner: () => runApp(InvenTreeApp())
|
||||
);
|
||||
|
||||
await runZonedGuarded<Future<void>>(() async {
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
runZoned<Future<void>>(() async {
|
||||
runApp(InvenTreeApp());
|
||||
}, onError: _reportError
|
||||
);
|
||||
// This captures errors reported by the Flutter framework.
|
||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||
if (isInDebugMode()) {
|
||||
// In development mode simply print to console.
|
||||
FlutterError.dumpErrorToConsole(details);
|
||||
} else {
|
||||
// In production mode report to the application zone to report to
|
||||
// Sentry.
|
||||
Zone.current.handleUncaughtError(details.exception, details.stack);
|
||||
}
|
||||
};
|
||||
|
||||
runApp(InvenTreeApp());
|
||||
|
||||
}, (Object error, StackTrace stackTrace) {
|
||||
_reportError(error, stackTrace);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
class InvenTreeApp extends StatelessWidget {
|
||||
|
@ -30,21 +30,21 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(I18N.of(context).address),
|
||||
subtitle: Text(InvenTreeAPI().baseUrl.isNotEmpty ? InvenTreeAPI().baseUrl : "Not connected"),
|
||||
subtitle: Text(InvenTreeAPI().baseUrl.isNotEmpty ? InvenTreeAPI().baseUrl : I18N.of(context).notConnected),
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(I18N.of(context).version),
|
||||
subtitle: Text(InvenTreeAPI().version.isNotEmpty ? InvenTreeAPI().version : "Not connected"),
|
||||
subtitle: Text(InvenTreeAPI().version.isNotEmpty ? InvenTreeAPI().version : I18N.of(context).notConnected),
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(I18N.of(context).serverInstance),
|
||||
subtitle: Text(InvenTreeAPI().instance.isNotEmpty ? InvenTreeAPI().instance : "Not connected"),
|
||||
subtitle: Text(InvenTreeAPI().instance.isNotEmpty ? InvenTreeAPI().instance : I18N.of(context).notConnected),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
@ -421,12 +421,19 @@ packages:
|
||||
source: hosted
|
||||
version: "2.4.9"
|
||||
sentry:
|
||||
dependency: "direct main"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sentry
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.4"
|
||||
sentry_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sentry_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.4"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -35,7 +35,7 @@ dependencies:
|
||||
device_info: ^1.0.0 # Information about the device
|
||||
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
||||
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
||||
sentry: ^4.0.4 # Error reporting
|
||||
sentry_flutter: ^4.0.4 # Error reporting
|
||||
flutter_typeahead: ^1.8.1 # Auto-complete input field
|
||||
image_picker: ^0.6.6 # Select or take photos
|
||||
url_launcher: ^5.7.10 # Open link in system browser
|
||||
|
Loading…
x
Reference in New Issue
Block a user