Caching initialization attempt, bool.Parse in WASM
This commit is contained in:
Родитель
9780c611b9
Коммит
cc87a487a8
|
@ -12,17 +12,17 @@ namespace Windows.Phone.Devices.Notification
|
|||
public partial class VibrationDevice
|
||||
{
|
||||
private const string Permission = "android.permission.VIBRATE";
|
||||
|
||||
private readonly Vibrator _vibrator;
|
||||
|
||||
private static VibrationDevice _instance;
|
||||
private static bool _initializationAttempted;
|
||||
|
||||
private readonly Vibrator _vibrator;
|
||||
|
||||
private VibrationDevice(Vibrator vibrator) =>
|
||||
_vibrator = vibrator;
|
||||
|
||||
public static VibrationDevice GetDefault()
|
||||
{
|
||||
if (_instance == null)
|
||||
if (!_initializationAttempted && _instance == null)
|
||||
{
|
||||
if (ContextCompat.CheckSelfPermission(Application.Context, Permission) == Android.Content.PM.Permission.Denied)
|
||||
{
|
||||
|
@ -32,7 +32,8 @@ namespace Windows.Phone.Devices.Notification
|
|||
if (vibrator != null && vibrator.HasVibrator)
|
||||
{
|
||||
_instance = new VibrationDevice(vibrator);
|
||||
}
|
||||
}
|
||||
_initializationAttempted = true;
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Windows.Phone.Devices.Notification
|
|||
{
|
||||
private const string JsType = "Windows.Phone.Devices.Notification.VibrationDevice";
|
||||
private static VibrationDevice _instance = null;
|
||||
private static bool _initializationAttempted = false;
|
||||
|
||||
private VibrationDevice()
|
||||
{
|
||||
|
@ -16,14 +17,15 @@ namespace Windows.Phone.Devices.Notification
|
|||
|
||||
public static VibrationDevice GetDefault()
|
||||
{
|
||||
if (_instance == null)
|
||||
if (!_initializationAttempted && _instance == null)
|
||||
{
|
||||
var command = $"{JsType}.initialize()";
|
||||
var initialized = Uno.Foundation.WebAssemblyRuntime.InvokeJS(command);
|
||||
if (initialized.Equals("true", StringComparison.InvariantCultureIgnoreCase))
|
||||
if (bool.Parse(initialized) == true)
|
||||
{
|
||||
_instance = new VibrationDevice();
|
||||
_instance = new VibrationDevice();
|
||||
}
|
||||
_initializationAttempted = true;
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче