| 1 | | | import '_impl/xplat/_platform.dart' |
| 2 | | | if (dart.library.io) '_impl/native/_platform.dart' |
| 3 | | | if (dart.library.html) '_impl/web/_platform.dart' |
| 4 | | | if (dart.library.js) '_impl/web/_platform.dart' |
| 5 | | | if (dart.library.js_interop) '_impl/web/_platform.dart' as impl; |
| 6 | | | import 'converters/converter.dart'; |
| 7 | | | |
| 8 | | 2 | String get threadId => impl.threadId; |
| 9 | | | |
| 10 | | | class Squadron { |
| 11 | | 0 | Squadron._(); |
| 12 | | | |
| 13 | | | /// Gets the current platform type. |
| 14 | | 36 | static final platformType = impl.getPlatformType(); |
| 15 | | | |
| 16 | | | /// Parse [url] and returns the corresponding [Uri]. |
| 17 | | | /// |
| 18 | | | /// On Web platforms, a leading '~' character will be replaced with the |
| 19 | | | /// current page's root URL. E.g. '~/workers' from '/path/to/index.html' |
| 20 | | | /// will return '/path/to/workers'. |
| 21 | | 0 | static Uri uri(String url) => impl.mapUrl(url); |
| 22 | | | |
| 23 | | | static bool disableBrowserCache = false; |
| 24 | | | |
| 25 | | 8 | static final identical = impl.isSameInstance; |
| 26 | | 30 | static final _platformConverter = impl.getPlatformConverter(); |
| 27 | | 30 | static Converter _converter = _platformConverter; |
| 28 | | | |
| 29 | | | /// Gets the current converter. |
| 30 | | 20 | static Converter get converter => _converter; |
| 31 | | | |
| 32 | | | /// Sets the current converter. If [value] is `null`, the default converter |
| 33 | | | /// will be restored. If the converter was updated, handlers registered with |
| 34 | | | /// [onConverterChanged] will be notified of the change. |
| 35 | | 1 | static set converter(Converter? value) { |
| 36 | | 1 | value ??= _platformConverter; |
| 37 | | 2 | if (_converter != value) { |
| 38 | | | _converter = value; |
| 39 | | 3 | for (var handler in _converterChangeHandlers.values) { |
| 40 | | | try { |
| 41 | | 1 | handler(); |
| 42 | | | } catch (_) { |
| 43 | | | // ignore |
| 44 | | | } |
| 45 | | | } |
| 46 | | | } |
| 47 | | | } |
| 48 | | | |
| 49 | | 3 | static final _converterChangeHandlers = <Object, void Function()>{}; |
| 50 | | | |
| 51 | | | /// Registers a callback that will be called whenever `converter` is changed. |
| 52 | | | /// Returns an object that can be used to unregister the callback by passing |
| 53 | | | /// it to [unregisterConverterChanged]. |
| 54 | | 1 | static Object onConverterChanged(void Function() handler) { |
| 55 | | 1 | final key = Object(); |
| 56 | | 2 | _converterChangeHandlers[key] = handler; |
| 57 | | | return key; |
| 58 | | | } |
| 59 | | | |
| 60 | | | /// Unregisters a callback that was registered with [onConverterChanged]. |
| 61 | | 1 | static void unregisterConverterChanged(Object key) { |
| 62 | | 2 | _converterChangeHandlers.remove(key); |
| 63 | | | } |
| 64 | | | } |