mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-14 02:14:52 +08:00
The async calls in CodePush for ReactWindows can all be executed on any background thread, so adding .ConfigureAwait(false) can improve performance and reduce the likelihood of deadlock. The blocking calls in `InitializeUpdateAfterRestart()` were hanging, but now that .ConfigureAwait(false) is used pervasively, it is no longer a problem. Fixes #550
54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Windows.Storage;
|
|
using Windows.Storage.Streams;
|
|
using Windows.System.Profile;
|
|
|
|
namespace CodePush.ReactNative
|
|
{
|
|
internal class CodePushUtils
|
|
{
|
|
internal async static Task<JObject> GetJObjectFromFileAsync(StorageFile file)
|
|
{
|
|
string jsonString = await FileIO.ReadTextAsync(file).AsTask().ConfigureAwait(false);
|
|
if (jsonString.Length == 0)
|
|
{
|
|
return new JObject();
|
|
}
|
|
|
|
try
|
|
{
|
|
return JObject.Parse(jsonString);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
internal static void Log(string message)
|
|
{
|
|
Debug.WriteLine("[CodePush] " + message, CodePushConstants.ReactNativeLogCategory);
|
|
}
|
|
|
|
internal static void LogBundleUrl(string path)
|
|
{
|
|
Log("Loading JS bundle from \"" + path + "\"");
|
|
}
|
|
|
|
internal static string GetDeviceId()
|
|
{
|
|
HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
|
|
IBuffer hardwareId = token.Id;
|
|
var dataReader = DataReader.FromBuffer(hardwareId);
|
|
|
|
var bytes = new byte[hardwareId.Length];
|
|
dataReader.ReadBytes(bytes);
|
|
|
|
return BitConverter.ToString(bytes);
|
|
}
|
|
}
|
|
}
|