fix: unable to get the device info in test mode (#4359)

This commit is contained in:
Lucas.Xu 2024-01-11 13:26:25 +07:00 committed by GitHub
parent 6e41359fc5
commit dd8b9dd43e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -109,7 +109,7 @@ class FlowyRunner {
// there's a flag named _enable in memory_leak_detector.dart. If it's false, the task will be ignored.
MemoryLeakDetectorTask(),
const DebugTask(),
const DeviceOrApplicationInfoTask(),
// localization
const InitLocalizationTask(),
// init the app window
@ -122,6 +122,9 @@ class FlowyRunner {
// init the app widget
// ignore in test mode
if (!mode.isUnitTest) ...[
// The DeviceOrApplicationInfoTask should be placed before the AppWidgetTask to fetch the app information.
// It is unable to get the device information from the test environment.
const DeviceOrApplicationInfoTask(),
const HotKeyTask(),
if (isSupabaseEnabled) InitSupabaseTask(),
if (isAppFlowyCloudEnabled) InitAppFlowyCloudTask(),

View File

@ -14,20 +14,17 @@ class DeviceOrApplicationInfoTask extends LaunchTask {
@override
Future<void> initialize(LaunchContext context) async {
// Can't get the device info from test environment
if (!context.env.isTest) {
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
if (Platform.isAndroid) {
final androidInfo = await deviceInfoPlugin.androidInfo;
androidSDKVersion = androidInfo.version.sdkInt;
}
if (Platform.isAndroid) {
final androidInfo = await deviceInfoPlugin.androidInfo;
androidSDKVersion = androidInfo.version.sdkInt;
}
if (Platform.isAndroid || Platform.isIOS) {
applicationVersion = packageInfo.version;
buildNumber = packageInfo.buildNumber;
}
if (Platform.isAndroid || Platform.isIOS) {
applicationVersion = packageInfo.version;
buildNumber = packageInfo.buildNumber;
}
}