mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-14 11:18:54 +01:00
Make Lock support running in unit tests
This commit is contained in:
parent
715bfaa0ee
commit
310fa424d6
2 changed files with 10 additions and 0 deletions
|
@ -1,10 +1,13 @@
|
||||||
import 'package:nc_photos/platform/k.dart' as platform_k;
|
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;
|
import 'package:nc_photos_plugin/nc_photos_plugin.dart' as plugin;
|
||||||
|
|
||||||
class Lock {
|
class Lock {
|
||||||
static Future<T> synchronized<T>(int lockId, Future<T> Function() fn) async {
|
static Future<T> synchronized<T>(int lockId, Future<T> Function() fn) async {
|
||||||
if (platform_k.isAndroid) {
|
if (platform_k.isAndroid) {
|
||||||
return _synchronizedAndroid(lockId, fn);
|
return _synchronizedAndroid(lockId, fn);
|
||||||
|
} else if (platform_k.isDesktop) {
|
||||||
|
return _synchronizedDesktop(lockId, fn);
|
||||||
} else {
|
} else {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
@ -21,4 +24,9 @@ class Lock {
|
||||||
await plugin.Lock.unlock(lockId);
|
await plugin.Lock.unlock(lockId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is mainly used to run test cases
|
||||||
|
static Future<T> _synchronizedDesktop<T>(
|
||||||
|
int lockId, Future<T> Function() fn) =>
|
||||||
|
web.Lock.synchronized(lockId, fn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,3 +6,5 @@ const isWeb = kIsWeb;
|
||||||
// Platform n/a on web, need checking kIsWeb first
|
// Platform n/a on web, need checking kIsWeb first
|
||||||
final isMobile = !kIsWeb && (Platform.isAndroid || Platform.isIOS);
|
final isMobile = !kIsWeb && (Platform.isAndroid || Platform.isIOS);
|
||||||
final isAndroid = !kIsWeb && Platform.isAndroid;
|
final isAndroid = !kIsWeb && Platform.isAndroid;
|
||||||
|
final isDesktop =
|
||||||
|
!kIsWeb && (Platform.isLinux || Platform.isMacOS || Platform.isWindows);
|
||||||
|
|
Loading…
Reference in a new issue