From 310fa424d692abaade0e84885f1cc97a27c7e88d Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Fri, 8 Jul 2022 16:38:09 +0800 Subject: [PATCH] Make Lock support running in unit tests --- app/lib/mobile/lock.dart | 8 ++++++++ app/lib/platform/k.dart | 2 ++ 2 files changed, 10 insertions(+) diff --git a/app/lib/mobile/lock.dart b/app/lib/mobile/lock.dart index e8352e59..ab509fe1 100644 --- a/app/lib/mobile/lock.dart +++ b/app/lib/mobile/lock.dart @@ -1,10 +1,13 @@ import 'package:nc_photos/platform/k.dart' as platform_k; +import 'package:nc_photos/web/lock.dart' as web; import 'package:nc_photos_plugin/nc_photos_plugin.dart' as plugin; class Lock { static Future synchronized(int lockId, Future Function() fn) async { if (platform_k.isAndroid) { return _synchronizedAndroid(lockId, fn); + } else if (platform_k.isDesktop) { + return _synchronizedDesktop(lockId, fn); } else { throw UnimplementedError(); } @@ -21,4 +24,9 @@ class Lock { await plugin.Lock.unlock(lockId); } } + + // this is mainly used to run test cases + static Future _synchronizedDesktop( + int lockId, Future Function() fn) => + web.Lock.synchronized(lockId, fn); } diff --git a/app/lib/platform/k.dart b/app/lib/platform/k.dart index 5069861e..f0deb7c1 100644 --- a/app/lib/platform/k.dart +++ b/app/lib/platform/k.dart @@ -6,3 +6,5 @@ const isWeb = kIsWeb; // Platform n/a on web, need checking kIsWeb first final isMobile = !kIsWeb && (Platform.isAndroid || Platform.isIOS); final isAndroid = !kIsWeb && Platform.isAndroid; +final isDesktop = + !kIsWeb && (Platform.isLinux || Platform.isMacOS || Platform.isWindows);