@srcpush/react-native-code-push 1.0.3-develop.2 → 1.0.3-develop.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CONTRIBUTING.md +20 -9
  2. package/package.json +1 -1
  3. package/windows/CodePush/CodePush.def +0 -3
  4. package/windows/CodePush/CodePush.vcxproj +0 -198
  5. package/windows/CodePush/CodePush.vcxproj.filters +0 -91
  6. package/windows/CodePush/CodePushConfig.cpp +0 -104
  7. package/windows/CodePush/CodePushConfig.h +0 -66
  8. package/windows/CodePush/CodePushConfig.idl +0 -12
  9. package/windows/CodePush/CodePushDownloadHandler.cpp +0 -73
  10. package/windows/CodePush/CodePushDownloadHandler.h +0 -32
  11. package/windows/CodePush/CodePushNativeModule.cpp +0 -937
  12. package/windows/CodePush/CodePushNativeModule.h +0 -247
  13. package/windows/CodePush/CodePushPackage.cpp +0 -456
  14. package/windows/CodePush/CodePushPackage.h +0 -49
  15. package/windows/CodePush/CodePushTelemetryManager.cpp +0 -213
  16. package/windows/CodePush/CodePushTelemetryManager.h +0 -29
  17. package/windows/CodePush/CodePushUpdateUtils.cpp +0 -86
  18. package/windows/CodePush/CodePushUpdateUtils.h +0 -38
  19. package/windows/CodePush/CodePushUtils.cpp +0 -29
  20. package/windows/CodePush/CodePushUtils.h +0 -18
  21. package/windows/CodePush/FileUtils.cpp +0 -131
  22. package/windows/CodePush/FileUtils.h +0 -28
  23. package/windows/CodePush/PropertySheet.props +0 -16
  24. package/windows/CodePush/ReactPackageProvider.cpp +0 -15
  25. package/windows/CodePush/ReactPackageProvider.h +0 -22
  26. package/windows/CodePush/ReactPackageProvider.idl +0 -9
  27. package/windows/CodePush/miniz/LICENSE +0 -22
  28. package/windows/CodePush/miniz/miniz.c +0 -7657
  29. package/windows/CodePush/miniz/miniz.h +0 -1338
  30. package/windows/CodePush/miniz/readme.md +0 -37
  31. package/windows/CodePush/packages.config +0 -4
  32. package/windows/CodePush/pch.cpp +0 -1
  33. package/windows/CodePush/pch.h +0 -4
  34. package/windows-legacy/CodePush/CodePush.csproj +0 -128
  35. package/windows-legacy/CodePush/CodePushUtils.cs +0 -47
  36. package/windows-legacy/CodePush/FileUtils.cs +0 -40
  37. package/windows-legacy/CodePush/Properties/AssemblyInfo.cs +0 -29
  38. package/windows-legacy/CodePush/Properties/CodePush.rd.xml +0 -33
  39. package/windows-legacy/CodePush/UpdateManager.cs +0 -305
  40. package/windows-legacy/CodePush/UpdateUtils.cs +0 -46
  41. package/windows-legacy/CodePush.Net46/Adapters/Http/HttpProgress.cs +0 -28
  42. package/windows-legacy/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +0 -106
  43. package/windows-legacy/CodePush.Net46/CodePush.Net46.csproj +0 -103
  44. package/windows-legacy/CodePush.Net46/CodePushUtils.cs +0 -158
  45. package/windows-legacy/CodePush.Net46/FileUtils.cs +0 -55
  46. package/windows-legacy/CodePush.Net46/Properties/AssemblyInfo.cs +0 -36
  47. package/windows-legacy/CodePush.Net46/UpdateManager.cs +0 -330
  48. package/windows-legacy/CodePush.Net46/UpdateUtils.cs +0 -70
  49. package/windows-legacy/CodePush.Net46/packages.config +0 -5
  50. package/windows-legacy/CodePush.Net46.Test/ApplicationDataContainerTest.cs +0 -105
  51. package/windows-legacy/CodePush.Net46.Test/CodePush.Net46.Test.csproj +0 -137
  52. package/windows-legacy/CodePush.Net46.Test/Properties/AssemblyInfo.cs +0 -36
  53. package/windows-legacy/CodePush.Net46.Test/TelemetryManagerTest.cs +0 -117
  54. package/windows-legacy/CodePush.Net46.Test/app.config +0 -11
  55. package/windows-legacy/CodePush.Net46.Test/packages.config +0 -4
  56. package/windows-legacy/CodePush.Shared/CodePush.Shared.projitems +0 -22
  57. package/windows-legacy/CodePush.Shared/CodePush.Shared.shproj +0 -13
  58. package/windows-legacy/CodePush.Shared/CodePushConstants.cs +0 -35
  59. package/windows-legacy/CodePush.Shared/CodePushNativeModule.cs +0 -329
  60. package/windows-legacy/CodePush.Shared/CodePushReactPackage.cs +0 -235
  61. package/windows-legacy/CodePush.Shared/CodePushUtils.cs +0 -70
  62. package/windows-legacy/CodePush.Shared/InstallMode.cs +0 -9
  63. package/windows-legacy/CodePush.Shared/MinimumBackgroundListener.cs +0 -44
  64. package/windows-legacy/CodePush.Shared/SettingsManager.cs +0 -148
  65. package/windows-legacy/CodePush.Shared/TelemetryManager.cs +0 -250
  66. package/windows-legacy/CodePush.Shared/UpdateState.cs +0 -9
@@ -1,235 +0,0 @@
1
- using Newtonsoft.Json.Linq;
2
- using ReactNative;
3
- using ReactNative.Bridge;
4
- using ReactNative.Modules.Core;
5
- using ReactNative.UIManager;
6
- using System;
7
- using System.Collections.Generic;
8
- using System.Reflection;
9
- using System.Threading.Tasks;
10
-
11
-
12
- namespace CodePush.ReactNative
13
- {
14
- public sealed class CodePushReactPackage : IReactPackage
15
- {
16
- private static CodePushReactPackage CurrentInstance;
17
-
18
- internal string AppVersion { get; private set; }
19
- internal string DeploymentKey { get; private set; }
20
- internal string AssetsBundleFileName { get; private set; }
21
- internal bool NeedToReportRollback { get; set; } = false;
22
- internal bool DidUpdate { get; private set; } = false;
23
- internal bool IsRunningBinaryVersion { get; private set; } = false;
24
- #pragma warning disable CS0618 // Keeping for backward compatibility
25
- internal ReactPage MainPage { get; private set; }
26
- #pragma warning restore CS0618 // Keeping for backward compatibility
27
- internal ReactNativeHost Host { get; private set; }
28
- internal UpdateManager UpdateManager { get; private set; }
29
-
30
- internal ReactInstanceManager ReactInstanceManager
31
- {
32
- get
33
- {
34
- if (Host != null)
35
- {
36
- return Host.ReactInstanceManager;
37
- }
38
-
39
- #if WINDOWS_UWP
40
- #pragma warning disable CS0618 // Keeping for backward compatibility
41
- return (ReactInstanceManager)typeof(ReactPage)
42
- #pragma warning restore CS0618 // Keeping for backward compatibility
43
- .GetField("_reactInstanceManager", BindingFlags.NonPublic | BindingFlags.Instance)
44
- .GetValue(MainPage);
45
- #else
46
- return ((Lazy<ReactInstanceManager>)typeof(ReactPage)
47
- .GetField("_reactInstanceManager", BindingFlags.NonPublic | BindingFlags.Instance)
48
- .GetValue(MainPage)).Value as ReactInstanceManager;
49
- #endif
50
- }
51
- }
52
-
53
- internal bool UseDeveloperSupport
54
- {
55
- get
56
- {
57
- return Host?.UseDeveloperSupport ?? MainPage.UseDeveloperSupport;
58
- }
59
- }
60
-
61
-
62
- #pragma warning disable CS0618 // Keeping for backward compatibility
63
- public CodePushReactPackage(string deploymentKey, ReactPage mainPage)
64
- #pragma warning restore CS0618 // Keeping for backward compatibility
65
- {
66
- AppVersion = CodePushUtils.GetAppVersion();
67
- DeploymentKey = deploymentKey;
68
- MainPage = mainPage;
69
- UpdateManager = new UpdateManager();
70
-
71
- if (CurrentInstance != null)
72
- {
73
- CodePushUtils.Log("More than one CodePush instance has been initialized. Please use the instance method codePush.getBundleUrlInternal() to get the correct bundleURL for a particular instance.");
74
- }
75
-
76
- CurrentInstance = this;
77
- }
78
-
79
- public CodePushReactPackage(string deploymentKey, ReactNativeHost host)
80
- {
81
- AppVersion = CodePushUtils.GetAppVersion();
82
- DeploymentKey = deploymentKey;
83
- Host = host;
84
- UpdateManager = new UpdateManager();
85
-
86
- if (CurrentInstance != null)
87
- {
88
- CodePushUtils.Log("More than one CodePush instance has been initialized. Please use the instance method codePush.getBundleUrlInternal() to get the correct bundleURL for a particular instance.");
89
- }
90
-
91
- CurrentInstance = this;
92
- }
93
-
94
- #region Public methods
95
- public IReadOnlyList<Type> CreateJavaScriptModulesConfig()
96
- {
97
- return new List<Type>();
98
- }
99
-
100
- public IReadOnlyList<INativeModule> CreateNativeModules(ReactContext reactContext)
101
- {
102
- return new List<INativeModule>
103
- {
104
- new CodePushNativeModule(reactContext, this)
105
- };
106
- }
107
-
108
- public IReadOnlyList<IViewManager> CreateViewManagers(ReactContext reactContext)
109
- {
110
- return new List<IViewManager>();
111
- }
112
-
113
- public string GetJavaScriptBundleFile()
114
- {
115
- return GetJavaScriptBundleFile(CodePushConstants.DefaultJsBundleName);
116
- }
117
-
118
- public string GetJavaScriptBundleFile(string assetsBundleFileName)
119
- {
120
- if (CurrentInstance == null)
121
- {
122
- throw new InvalidOperationException("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?");
123
- }
124
-
125
- return CurrentInstance.GetJavaScriptBundleFileAsync(assetsBundleFileName).Result;
126
- }
127
-
128
- public async Task<string> GetJavaScriptBundleFileAsync(string assetsBundleFileName)
129
- {
130
- AssetsBundleFileName = assetsBundleFileName;
131
- string binaryJsBundleUrl = CodePushUtils.GetAssetsBundlePrefix() + assetsBundleFileName;
132
-
133
- var binaryResourcesModifiedTime = await FileUtils.GetBinaryResourcesModifiedTimeAsync(AssetsBundleFileName).ConfigureAwait(false);
134
- var packageFile = await UpdateManager.GetCurrentPackageBundleAsync(AssetsBundleFileName).ConfigureAwait(false);
135
- if (packageFile == null)
136
- {
137
- // There has not been any downloaded updates.
138
- CodePushUtils.LogBundleUrl(binaryJsBundleUrl);
139
- IsRunningBinaryVersion = true;
140
- return binaryJsBundleUrl;
141
- }
142
-
143
- var packageMetadata = await UpdateManager.GetCurrentPackageAsync().ConfigureAwait(false);
144
- long? binaryModifiedDateDuringPackageInstall = null;
145
- var binaryModifiedDateDuringPackageInstallString = (string)packageMetadata[CodePushConstants.BinaryModifiedTimeKey];
146
- if (binaryModifiedDateDuringPackageInstallString != null)
147
- {
148
- binaryModifiedDateDuringPackageInstall = long.Parse(binaryModifiedDateDuringPackageInstallString);
149
- }
150
-
151
- var packageAppVersion = (string)packageMetadata["appVersion"];
152
-
153
- if (binaryModifiedDateDuringPackageInstall != null &&
154
- binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
155
- AppVersion.Equals(packageAppVersion))
156
- {
157
- CodePushUtils.LogBundleUrl(packageFile.Path);
158
- IsRunningBinaryVersion = false;
159
-
160
- return CodePushUtils.GetFileBundlePrefix() + CodePushUtils.ExtractSubFolder(packageFile.Path);
161
- }
162
- else
163
- {
164
- // The binary version is newer.
165
- DidUpdate = false;
166
- if (!UseDeveloperSupport || !AppVersion.Equals(packageAppVersion))
167
- {
168
- await ClearUpdatesAsync().ConfigureAwait(false);
169
- }
170
-
171
- CodePushUtils.LogBundleUrl(binaryJsBundleUrl);
172
- IsRunningBinaryVersion = true;
173
- return binaryJsBundleUrl;
174
- }
175
- }
176
-
177
- #endregion
178
-
179
- #region Internal methods
180
-
181
- internal void InitializeUpdateAfterRestart()
182
- {
183
- // Reset the state which indicates that
184
- // the app was just freshly updated.
185
- DidUpdate = false;
186
-
187
- JObject pendingUpdate = SettingsManager.GetPendingUpdate();
188
- if (pendingUpdate != null)
189
- {
190
- var updateIsLoading = (bool)pendingUpdate[CodePushConstants.PendingUpdateIsLoadingKey];
191
- if (updateIsLoading)
192
- {
193
- // Pending update was initialized, but notifyApplicationReady was not called.
194
- // Therefore, deduce that it is a broken update and rollback.
195
- CodePushUtils.Log("Update did not finish loading the last time, rolling back to a previous version.");
196
- NeedToReportRollback = true;
197
- RollbackPackageAsync().Wait();
198
- }
199
- else
200
- {
201
- DidUpdate = true;
202
- // Clear the React dev bundle cache so that new updates can be loaded.
203
- if (UseDeveloperSupport)
204
- {
205
- FileUtils.ClearReactDevBundleCacheAsync().Wait();
206
- }
207
- // Mark that we tried to initialize the new update, so that if it crashes,
208
- // we will know that we need to rollback when the app next starts.
209
- SettingsManager.SavePendingUpdate((string)pendingUpdate[CodePushConstants.PendingUpdateHashKey], /* isLoading */true);
210
- }
211
- }
212
- }
213
-
214
- internal async Task ClearUpdatesAsync()
215
- {
216
- await UpdateManager.ClearUpdatesAsync().ConfigureAwait(false);
217
- SettingsManager.RemovePendingUpdate();
218
- SettingsManager.RemoveFailedUpdates();
219
- }
220
-
221
- #endregion
222
-
223
- #region Private methods
224
-
225
- private async Task RollbackPackageAsync()
226
- {
227
- JObject failedPackage = await UpdateManager.GetCurrentPackageAsync().ConfigureAwait(false);
228
- SettingsManager.SaveFailedUpdate(failedPackage);
229
- await UpdateManager.RollbackPackageAsync().ConfigureAwait(false);
230
- SettingsManager.RemovePendingUpdate();
231
- }
232
-
233
- #endregion
234
- }
235
- }
@@ -1,70 +0,0 @@
1
- using System;
2
- using System.Diagnostics;
3
- using System.Linq;
4
- using System.IO;
5
- #if WINDOWS_UWP
6
- using Windows.ApplicationModel;
7
- using Windows.Storage;
8
- #endif
9
-
10
- namespace CodePush.ReactNative
11
- {
12
- internal partial class CodePushUtils
13
- {
14
- internal static void Log(string message)
15
- {
16
- Debug.WriteLine("[CodePush] " + message, CodePushConstants.ReactNativeLogCategory);
17
- }
18
-
19
- internal static void LogBundleUrl(string path)
20
- {
21
- Log("Loading JS bundle from \"" + path + "\"");
22
- }
23
-
24
- static string _deviceId = String.Empty;
25
-
26
- internal static string GetDeviceId()
27
- {
28
- //It's quite long operation, cache it
29
- if (!String.IsNullOrEmpty(_deviceId))
30
- return _deviceId;
31
-
32
- _deviceId = GetDeviceIdImpl();
33
- return _deviceId;
34
- }
35
-
36
- internal static string GetAppVersion()
37
- {
38
- #if WINDOWS_UWP
39
- return Package.Current.Id.Version.Major + "." + Package.Current.Id.Version.Minor + "." + Package.Current.Id.Version.Build;
40
- #else
41
- return applicationInfo.Version;
42
- #endif
43
- }
44
-
45
- internal static string GetAppFolder()
46
- {
47
- #if WINDOWS_UWP
48
- return ApplicationData.Current.LocalFolder.Path;
49
- #else
50
- return AppDomain.CurrentDomain.BaseDirectory;
51
- #endif
52
- }
53
-
54
- internal static string GetAssetsBundlePrefix()
55
- {
56
- #if WINDOWS_UWP
57
- return CodePushConstants.AssetsBundlePrefix;
58
- #else
59
- return Path.Combine(GetAppFolder(), CodePushConstants.AssetsBundlePrefix);
60
- #endif
61
- }
62
-
63
- internal static string ExtractSubFolder(string fullPath)
64
- {
65
- var codePushSubPathArray = fullPath.Split(Path.DirectorySeparatorChar);
66
- return String.Join("/", codePushSubPathArray.SkipWhile((value, index) => codePushSubPathArray.Length - index > 4).ToArray());
67
- }
68
-
69
- }
70
- }
@@ -1,9 +0,0 @@
1
- namespace CodePush.ReactNative
2
- {
3
- enum InstallMode
4
- {
5
- Immediate,
6
- OnNextRestart,
7
- OnNextResume
8
- }
9
- }
@@ -1,44 +0,0 @@
1
- using ReactNative.Bridge;
2
- using System;
3
-
4
- namespace CodePush.ReactNative
5
- {
6
- internal class MinimumBackgroundListener : ILifecycleEventListener
7
- {
8
- private DateTimeOffset? _lastSuspendDate;
9
- private Action _resumeAction;
10
-
11
- internal int MinimumBackgroundDuration { get; set; }
12
-
13
- internal MinimumBackgroundListener(Action resumeAction, int minimumBackgroundDuration)
14
- {
15
- _resumeAction = resumeAction;
16
- MinimumBackgroundDuration = minimumBackgroundDuration;
17
- }
18
-
19
- public void OnDestroy()
20
- {
21
- }
22
-
23
- public void OnResume()
24
- {
25
- if (_lastSuspendDate != null)
26
- {
27
- // Determine how long the app was in the background and ensure
28
- // that it meets the minimum duration amount of time.
29
- double durationInBackground = (DateTimeOffset.Now - _lastSuspendDate.Value).TotalSeconds;
30
- if (durationInBackground >= MinimumBackgroundDuration)
31
- {
32
- _resumeAction.Invoke();
33
- }
34
- }
35
- }
36
-
37
- public void OnSuspend()
38
- {
39
- // Save the current time so that when the app is later
40
- // resumed, we can detect how long it was in the background.
41
- _lastSuspendDate = DateTimeOffset.Now;
42
- }
43
- }
44
- }
@@ -1,148 +0,0 @@
1
- using Newtonsoft.Json;
2
- using Newtonsoft.Json.Linq;
3
- using System;
4
- #if WINDOWS_UWP
5
- using Windows.Storage;
6
- #else
7
- using CodePush.Net46.Adapters.Storage;
8
- using System.IO;
9
- #endif
10
-
11
- namespace CodePush.ReactNative
12
- {
13
- internal class SettingsManager
14
- {
15
- private static ApplicationDataContainer Settings = null;
16
-
17
- static SettingsManager ()
18
- {
19
-
20
- #if WINDOWS_UWP
21
- Settings = ApplicationData.Current.LocalSettings.CreateContainer(CodePushConstants.CodePushPreferences, ApplicationDataCreateDisposition.Always);
22
- #else
23
- var folder = UpdateUtils.GetCodePushFolderAsync().Result;
24
- Settings = new ApplicationDataContainer(Path.Combine(folder.Path, CodePushConstants.CodePushPreferences));
25
- #endif
26
- }
27
-
28
- public static JArray GetFailedUpdates()
29
- {
30
- var failedUpdatesString = (string)Settings.Values[CodePushConstants.FailedUpdatesKey];
31
- if (failedUpdatesString == null)
32
- {
33
- return new JArray();
34
- }
35
-
36
- try
37
- {
38
- return JArray.Parse(failedUpdatesString);
39
- }
40
- catch (Exception)
41
- {
42
- var emptyArray = new JArray();
43
- Settings.Values[CodePushConstants.FailedUpdatesKey] = JsonConvert.SerializeObject(emptyArray);
44
- return emptyArray;
45
- }
46
- }
47
-
48
- internal static JObject GetPendingUpdate()
49
- {
50
- var pendingUpdateString = (string)Settings.Values[CodePushConstants.PendingUpdateKey];
51
- if (pendingUpdateString == null)
52
- {
53
- return null;
54
- }
55
-
56
- try
57
- {
58
- return JObject.Parse(pendingUpdateString);
59
- }
60
- catch (Exception)
61
- {
62
- // Should not happen.
63
- CodePushUtils.Log("Unable to parse pending update metadata " + pendingUpdateString +
64
- " stored in SharedPreferences");
65
- return null;
66
- }
67
- }
68
-
69
- internal static bool IsFailedHash(string packageHash)
70
- {
71
- JArray failedUpdates = SettingsManager.GetFailedUpdates();
72
- if (packageHash != null)
73
- {
74
- foreach (var failedPackage in failedUpdates)
75
- {
76
- var failedPackageHash = (string)failedPackage[CodePushConstants.PackageHashKey];
77
- if (packageHash.Equals(failedPackageHash))
78
- {
79
- return true;
80
- }
81
- }
82
- }
83
-
84
- return false;
85
- }
86
-
87
- internal static bool IsPendingUpdate(string packageHash)
88
- {
89
- JObject pendingUpdate = SettingsManager.GetPendingUpdate();
90
- return pendingUpdate != null &&
91
- !(bool)pendingUpdate[CodePushConstants.PendingUpdateIsLoadingKey] &&
92
- (packageHash == null || ((string)pendingUpdate[CodePushConstants.PendingUpdateHashKey]).Equals(packageHash));
93
- }
94
-
95
- internal static void RemoveFailedUpdates()
96
- {
97
- Settings.Values.Remove(CodePushConstants.FailedUpdatesKey);
98
- }
99
-
100
- internal static void RemovePendingUpdate()
101
- {
102
- Settings.Values.Remove(CodePushConstants.PendingUpdateKey);
103
- }
104
-
105
- internal static void SaveFailedUpdate(JObject failedPackage)
106
- {
107
- var failedUpdatesString = (string)Settings.Values[CodePushConstants.FailedUpdatesKey];
108
- JArray failedUpdates;
109
- if (failedUpdatesString == null)
110
- {
111
- failedUpdates = new JArray();
112
- }
113
- else
114
- {
115
- failedUpdates = JArray.Parse(failedUpdatesString);
116
- }
117
-
118
- failedUpdates.Add(failedPackage);
119
- Settings.Values[CodePushConstants.FailedUpdatesKey] = JsonConvert.SerializeObject(failedUpdates);
120
- }
121
-
122
- internal static void SavePendingUpdate(string packageHash, bool isLoading)
123
- {
124
- var pendingUpdate = new JObject()
125
- {
126
- { CodePushConstants.PendingUpdateHashKey, packageHash },
127
- { CodePushConstants.PendingUpdateIsLoadingKey, isLoading }
128
- };
129
-
130
- Settings.Values[CodePushConstants.PendingUpdateKey] = JsonConvert.SerializeObject(pendingUpdate);
131
- }
132
-
133
- internal static void SetString(string key, string value)
134
- {
135
- Settings.Values[key] = value;
136
- }
137
-
138
- internal static string GetString(string key)
139
- {
140
- return (string)Settings.Values[key];
141
- }
142
-
143
- internal static void RemoveString(string key)
144
- {
145
- Settings.Values.Remove(key);
146
- }
147
- }
148
- }