From 46bd7702191916925f38187fb3c5ff7da1ea107e Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Mon, 20 Jun 2016 15:15:45 -0700 Subject: [PATCH 01/11] fixes issue --- RestartManager.js | 6 ++++++ .../scenarios/scenarioInstallRestart2x.js | 17 +++++++++++++++ test/test.ts | 21 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/template/scenarios/scenarioInstallRestart2x.js diff --git a/RestartManager.js b/RestartManager.js index a34fffe..b3198fc 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -2,6 +2,7 @@ const log = require("./logging"); const NativeCodePush = require("react-native").NativeModules.CodePush; const RestartManager = (() => { + let _in_progress = false; let _allowed = true; let _restartPending = false; @@ -25,6 +26,11 @@ const RestartManager = (() => { } function restartApp(onlyIfUpdateIsPending = false) { + if (_in_progress) { + log("A restart request is already in progress or queued"); + return; + } + _in_progress = true; if (_allowed) { NativeCodePush.restartApp(onlyIfUpdateIsPending); log("Restarting app"); diff --git a/test/template/scenarios/scenarioInstallRestart2x.js b/test/template/scenarios/scenarioInstallRestart2x.js new file mode 100644 index 0000000..bd78f68 --- /dev/null +++ b/test/template/scenarios/scenarioInstallRestart2x.js @@ -0,0 +1,17 @@ +var CodePushWrapper = require("../codePushWrapper.js"); +import CodePush from "react-native-code-push"; + +module.exports = { + startTest: function(testApp) { + CodePushWrapper.checkAndInstall(testApp, + () => { + CodePush.restartApp(); + CodePush.restartApp(); + } + ); + }, + + getScenarioName: function() { + return "Install and Restart 2x"; + } +}; \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 6d90225..e21596e 100644 --- a/test/test.ts +++ b/test/test.ts @@ -465,6 +465,7 @@ const ScenarioInstall = "scenarioInstall.js"; const ScenarioInstallOnResumeWithRevert = "scenarioInstallOnResumeWithRevert.js"; const ScenarioInstallOnRestartWithRevert = "scenarioInstallOnRestartWithRevert.js"; const ScenarioInstallWithRevert = "scenarioInstallWithRevert.js"; +const ScenarioInstallRestart2x = "scenarioInstallRestart2x.js"; const ScenarioSync1x = "scenarioSync.js"; const ScenarioSyncResume = "scenarioSyncResume.js"; const ScenarioSyncResumeDelay = "scenarioSyncResumeDelay.js"; @@ -986,6 +987,26 @@ PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPl }); }, ScenarioRestart); + TestBuilder.describe("#codePush.restartApplication.2x", + () => { + TestBuilder.it("with pending update", false, + (done: MochaDone) => { + ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; + + setupUpdateScenario(projectManager, targetPlatform, UpdateDeviceReady, "Update 1") + .then((updatePath: string) => { + ServerUtil.updatePackagePath = updatePath; + projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); + return ServerUtil.expectTestMessages([ + ServerUtil.TestMessage.CHECK_UPDATE_AVAILABLE, + ServerUtil.TestMessage.DOWNLOAD_SUCCEEDED, + ServerUtil.TestMessage.UPDATE_INSTALLED, + ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]); + }) + .done(() => { done(); }, (e) => { done(e); }); + }); + }, ScenarioInstallRestart2x); + TestBuilder.describe("#window.codePush.sync", () => { // We test the functionality with sync twice--first, with sync only called once, From d57278bcb07a774a53f8f737787adcbe6a38cd8b Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Tue, 21 Jun 2016 15:57:58 -0700 Subject: [PATCH 02/11] set _inProgress back to false if a restart will not happen because there is no pending package --- RestartManager.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/RestartManager.js b/RestartManager.js index b3198fc..1f0d6f3 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -1,8 +1,9 @@ const log = require("./logging"); const NativeCodePush = require("react-native").NativeModules.CodePush; +const CodePush = require("./CodePush"); const RestartManager = (() => { - let _in_progress = false; + let _inProgress = false; let _allowed = true; let _restartPending = false; @@ -26,12 +27,13 @@ const RestartManager = (() => { } function restartApp(onlyIfUpdateIsPending = false) { - if (_in_progress) { - log("A restart request is already in progress or queued"); - return; - } - _in_progress = true; if (_allowed) { + if (_inProgress) { + log("A restart request is already in progress or queued"); + return; + } + // The restart won't execute if `onlyIfUpdateIsPending === true` and there is no pending update. + _inProgress = !onlyIfUpdateIsPending || !!(NativeCodePush.getUpdateMetadata(CodePush.UpdateState.PENDING)); NativeCodePush.restartApp(onlyIfUpdateIsPending); log("Restarting app"); } else { From 7e5ac6b7f89e9b6bc5ad0bac1ff1ce038fc05af8 Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Wed, 22 Jun 2016 17:00:24 -0700 Subject: [PATCH 03/11] another test case --- test/template/scenarios/scenarioRestart2x.js | 16 ++++++++++++ test/test.ts | 26 +++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 test/template/scenarios/scenarioRestart2x.js diff --git a/test/template/scenarios/scenarioRestart2x.js b/test/template/scenarios/scenarioRestart2x.js new file mode 100644 index 0000000..819ec3b --- /dev/null +++ b/test/template/scenarios/scenarioRestart2x.js @@ -0,0 +1,16 @@ +import CodePush from "react-native-code-push"; + +module.exports = { + startTest: function(testApp) { + CodePush.restartApp(true); + CodePushWrapper.checkAndInstall(testApp, + () => { + CodePush.restartApp(true); + } + ); + }, + + getScenarioName: function() { + return "Restart2x"; + } +}; \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index e21596e..a0c6472 100644 --- a/test/test.ts +++ b/test/test.ts @@ -472,6 +472,7 @@ const ScenarioSyncResumeDelay = "scenarioSyncResumeDelay.js"; const ScenarioSyncRestartDelay = "scenarioSyncResumeDelay.js"; const ScenarioSync2x = "scenarioSync2x.js"; const ScenarioRestart = "scenarioRestart.js"; +const ScenarioRestart2x = "scenarioRestart2x.js"; const ScenarioSyncMandatoryDefault = "scenarioSyncMandatoryDefault.js"; const ScenarioSyncMandatoryResume = "scenarioSyncMandatoryResume.js"; const ScenarioSyncMandatoryRestart = "scenarioSyncMandatoryRestart.js"; @@ -989,11 +990,28 @@ PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPl TestBuilder.describe("#codePush.restartApplication.2x", () => { - TestBuilder.it("with pending update", false, + // TestBuilder.it("blocks when a restart is in progress and doesn't crash if there is a pending package", false, + // (done: MochaDone) => { + // ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; + // setupTestRunScenario(projectManager, targetPlatform, ScenarioInstallRestart2x) + // .then(setupUpdateScenario.bind(this, projectManager, targetPlatform, UpdateDeviceReady, "Good Update")) + // .then((updatePath: string) => { + // ServerUtil.updatePackagePath = updatePath; + // projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); + // return ServerUtil.expectTestMessages([ + // ServerUtil.TestMessage.CHECK_UPDATE_AVAILABLE, + // ServerUtil.TestMessage.DOWNLOAD_SUCCEEDED, + // ServerUtil.TestMessage.UPDATE_INSTALLED, + // ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]); + // }) + // .done(() => { done(); }, (e) => { done(e); }); + // }); + + TestBuilder.it("doesn't block when the restart is ignored", false, (done: MochaDone) => { ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; - - setupUpdateScenario(projectManager, targetPlatform, UpdateDeviceReady, "Update 1") + setupTestRunScenario(projectManager, targetPlatform, ScenarioRestart2x) + .then(setupUpdateScenario.bind(this, projectManager, targetPlatform, UpdateDeviceReady, "Good Update")) .then((updatePath: string) => { ServerUtil.updatePackagePath = updatePath; projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); @@ -1005,7 +1023,7 @@ PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPl }) .done(() => { done(); }, (e) => { done(e); }); }); - }, ScenarioInstallRestart2x); + }); TestBuilder.describe("#window.codePush.sync", () => { From a37c0b989e7a8793b1ad9220eb04f6ae2649a4b2 Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Thu, 23 Jun 2016 15:44:05 -0700 Subject: [PATCH 04/11] use promises and an async function to improve behavior --- RestartManager.js | 43 +++++++++++++++---- .../microsoft/codepush/react/CodePush.java | 4 +- .../script/testBuilder.js | 2 +- .../script/testUtil.js | 2 +- ios/CodePush/CodePush.m | 6 ++- test/template/scenarios/scenarioRestart2x.js | 1 + test/test.ts | 34 +++++++-------- 7 files changed, 63 insertions(+), 29 deletions(-) diff --git a/RestartManager.js b/RestartManager.js index 1f0d6f3..bdaddf9 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -3,9 +3,12 @@ const NativeCodePush = require("react-native").NativeModules.CodePush; const CodePush = require("./CodePush"); const RestartManager = (() => { - let _inProgress = false; + let _inProgressPromise = null; + let _inProgressOnUpdateOnly = false; + let _allowed = true; let _restartPending = false; + let _restartPendingOnUpdateOnly = false; function allow() { log("Re-allowing restarts"); @@ -13,7 +16,7 @@ const RestartManager = (() => { if (_restartPending) { log("Executing pending restart"); - restartApp(true); + restartApp(_restartPendingOnUpdateOnly); } } @@ -27,18 +30,42 @@ const RestartManager = (() => { } function restartApp(onlyIfUpdateIsPending = false) { - if (_allowed) { - if (_inProgress) { - log("A restart request is already in progress or queued"); + (async function(onlyIfUpdateIsPending) { + var didRestartSucceed = false; + + if (_restartPending) { + _restartPendingOnUpdateOnly = _restartPendingOnUpdateOnly && onlyIfUpdateIsPending; + log("Restart request queued until restarts are re-allowed"); return; } - // The restart won't execute if `onlyIfUpdateIsPending === true` and there is no pending update. - _inProgress = !onlyIfUpdateIsPending || !!(NativeCodePush.getUpdateMetadata(CodePush.UpdateState.PENDING)); - NativeCodePush.restartApp(onlyIfUpdateIsPending); + + if (!!_inProgressPromise) { + didRestartSucceed = await _inProgressPromise; + if (didRestartSucceed) { + log("A restart is already in progress."); + return; + } + } + + _inProgressPromise = new Promise(async function(resolve, reject) { + resolve(await restartAppInternal(onlyIfUpdateIsPending)); + }); + _inProgressOnUpdateOnly = onlyIfUpdateIsPending; + + didRestartSucceed = await _inProgressPromise; + if (!didRestartSucceed) _inProgressPromise = null; + })(onlyIfUpdateIsPending); + }; + + async function restartAppInternal(onlyIfUpdateIsPending = false) { + if (_allowed) { + var didRestartSucceed = await NativeCodePush.restartApp(onlyIfUpdateIsPending); log("Restarting app"); + return didRestartSucceed; } else { log("Restart request queued until restarts are re-allowed"); _restartPending = true; + _restartPendingOnUpdateOnly = onlyIfUpdateIsPending; return true; } } diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index bd7585e..911ceb7 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -738,12 +738,14 @@ public class CodePush implements ReactPackage { } @ReactMethod - public void restartApp(boolean onlyIfUpdateIsPending) { + public void restartApp(boolean onlyIfUpdateIsPending, Promise promise) { // If this is an unconditional restart request, or there // is current pending update, then reload the app. if (!onlyIfUpdateIsPending || CodePush.this.isPendingUpdate(null)) { loadBundle(); + promise.resolve(true); } + promise.resolve(false); } @ReactMethod diff --git a/code-push-plugin-testing-framework/script/testBuilder.js b/code-push-plugin-testing-framework/script/testBuilder.js index 5eb311b..c61d7a4 100644 --- a/code-push-plugin-testing-framework/script/testBuilder.js +++ b/code-push-plugin-testing-framework/script/testBuilder.js @@ -64,7 +64,7 @@ function itInternal(func, expectation, isCoreTest, assertion) { if ((!TestConfig.onlyRunCoreTests || isCoreTest)) { // Create a wrapper around the assertion to set the timeout on the test to 10 minutes. var assertionWithTimeout = function (done) { - this.timeout(10 * 60 * 1000); + this.timeout(20 * 60 * 1000); assertion(done); }; return it(expectation, assertionWithTimeout); diff --git a/code-push-plugin-testing-framework/script/testUtil.js b/code-push-plugin-testing-framework/script/testUtil.js index afe255a..ede3f11 100644 --- a/code-push-plugin-testing-framework/script/testUtil.js +++ b/code-push-plugin-testing-framework/script/testUtil.js @@ -48,7 +48,7 @@ var TestUtil = (function () { if (options.maxBuffer === undefined) options.maxBuffer = 1024 * 500; if (options.timeout === undefined) - options.timeout = 10 * 60 * 1000; + options.timeout = 20 * 60 * 1000; if (!options.noLogCommand) console.log("Running command: " + command); var execProcess = child_process.exec(command, options, function (error, stdout, stderr) { diff --git a/ios/CodePush/CodePush.m b/ios/CodePush/CodePush.m index c703092..6e2299e 100644 --- a/ios/CodePush/CodePush.m +++ b/ios/CodePush/CodePush.m @@ -740,13 +740,17 @@ RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve /* * This method is the native side of the CodePush.restartApp() method. */ -RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending) +RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending + resolve:(RCTPromiseResolveBlock)resolve + rejecter:(RCTPromiseRejectBlock)reject) { // If this is an unconditional restart request, or there // is current pending update, then reload the app. if (!onlyIfUpdateIsPending || [self isPendingUpdate:nil]) { [self loadBundle]; + resolve(@(YES)); } + resolve(@(NO)); } #pragma mark - JavaScript-exported module methods (Private) diff --git a/test/template/scenarios/scenarioRestart2x.js b/test/template/scenarios/scenarioRestart2x.js index 819ec3b..11e775b 100644 --- a/test/template/scenarios/scenarioRestart2x.js +++ b/test/template/scenarios/scenarioRestart2x.js @@ -1,3 +1,4 @@ +var CodePushWrapper = require("../codePushWrapper.js"); import CodePush from "react-native-code-push"; module.exports = { diff --git a/test/test.ts b/test/test.ts index a0c6472..9399266 100644 --- a/test/test.ts +++ b/test/test.ts @@ -990,28 +990,28 @@ PluginTestingFramework.initializeTests(new RNProjectManager(), supportedTargetPl TestBuilder.describe("#codePush.restartApplication.2x", () => { - // TestBuilder.it("blocks when a restart is in progress and doesn't crash if there is a pending package", false, - // (done: MochaDone) => { - // ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; - // setupTestRunScenario(projectManager, targetPlatform, ScenarioInstallRestart2x) - // .then(setupUpdateScenario.bind(this, projectManager, targetPlatform, UpdateDeviceReady, "Good Update")) - // .then((updatePath: string) => { - // ServerUtil.updatePackagePath = updatePath; - // projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); - // return ServerUtil.expectTestMessages([ - // ServerUtil.TestMessage.CHECK_UPDATE_AVAILABLE, - // ServerUtil.TestMessage.DOWNLOAD_SUCCEEDED, - // ServerUtil.TestMessage.UPDATE_INSTALLED, - // ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]); - // }) - // .done(() => { done(); }, (e) => { done(e); }); - // }); + TestBuilder.it("blocks when a restart is in progress and doesn't crash if there is a pending package", false, + (done: MochaDone) => { + ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; + setupTestRunScenario(projectManager, targetPlatform, ScenarioInstallRestart2x) + .then(setupUpdateScenario.bind(this, projectManager, targetPlatform, UpdateDeviceReady, "Update 1")) + .then((updatePath: string) => { + ServerUtil.updatePackagePath = updatePath; + projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); + return ServerUtil.expectTestMessages([ + ServerUtil.TestMessage.CHECK_UPDATE_AVAILABLE, + ServerUtil.TestMessage.DOWNLOAD_SUCCEEDED, + ServerUtil.TestMessage.UPDATE_INSTALLED, + ServerUtil.TestMessage.DEVICE_READY_AFTER_UPDATE]); + }) + .done(() => { done(); }, (e) => { done(e); }); + }); TestBuilder.it("doesn't block when the restart is ignored", false, (done: MochaDone) => { ServerUtil.updateResponse = { updateInfo: ServerUtil.createUpdateResponse(false, targetPlatform) }; setupTestRunScenario(projectManager, targetPlatform, ScenarioRestart2x) - .then(setupUpdateScenario.bind(this, projectManager, targetPlatform, UpdateDeviceReady, "Good Update")) + .then(setupUpdateScenario.bind(this, projectManager, targetPlatform, UpdateDeviceReady, "Update 1")) .then((updatePath: string) => { ServerUtil.updatePackagePath = updatePath; projectManager.runApplication(TestConfig.testRunDirectory, targetPlatform); From ab8f33890734d4e2dbfd4fcf8b90274a9dccdf64 Mon Sep 17 00:00:00 2001 From: scottbommarito Date: Thu, 23 Jun 2016 15:46:40 -0700 Subject: [PATCH 05/11] reset timeouts --- code-push-plugin-testing-framework/script/testBuilder.js | 2 +- code-push-plugin-testing-framework/script/testUtil.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code-push-plugin-testing-framework/script/testBuilder.js b/code-push-plugin-testing-framework/script/testBuilder.js index c61d7a4..5eb311b 100644 --- a/code-push-plugin-testing-framework/script/testBuilder.js +++ b/code-push-plugin-testing-framework/script/testBuilder.js @@ -64,7 +64,7 @@ function itInternal(func, expectation, isCoreTest, assertion) { if ((!TestConfig.onlyRunCoreTests || isCoreTest)) { // Create a wrapper around the assertion to set the timeout on the test to 10 minutes. var assertionWithTimeout = function (done) { - this.timeout(20 * 60 * 1000); + this.timeout(10 * 60 * 1000); assertion(done); }; return it(expectation, assertionWithTimeout); diff --git a/code-push-plugin-testing-framework/script/testUtil.js b/code-push-plugin-testing-framework/script/testUtil.js index ede3f11..afe255a 100644 --- a/code-push-plugin-testing-framework/script/testUtil.js +++ b/code-push-plugin-testing-framework/script/testUtil.js @@ -48,7 +48,7 @@ var TestUtil = (function () { if (options.maxBuffer === undefined) options.maxBuffer = 1024 * 500; if (options.timeout === undefined) - options.timeout = 20 * 60 * 1000; + options.timeout = 10 * 60 * 1000; if (!options.noLogCommand) console.log("Running command: " + command); var execProcess = child_process.exec(command, options, function (error, stdout, stderr) { From c9a8f724c4619f658d97ae9ec8a8b6b14ab5e90c Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 28 Jun 2016 14:40:59 -0700 Subject: [PATCH 06/11] use queue instead --- RestartManager.js | 73 ++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/RestartManager.js b/RestartManager.js index bdaddf9..807bc9b 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -1,78 +1,55 @@ const log = require("./logging"); const NativeCodePush = require("react-native").NativeModules.CodePush; -const CodePush = require("./CodePush"); const RestartManager = (() => { - let _inProgressPromise = null; - let _inProgressOnUpdateOnly = false; - let _allowed = true; - let _restartPending = false; - let _restartPendingOnUpdateOnly = false; + let _restartQueue = []; function allow() { log("Re-allowing restarts"); _allowed = true; - - if (_restartPending) { + + if (_restartQueue.length) { log("Executing pending restart"); - restartApp(_restartPendingOnUpdateOnly); + restartApp(_restartQueue.shift(1)); } } - + function clearPendingRestart() { - _restartPending = false; + _restartQueue = []; } - + function disallow() { log("Disallowing restarts"); _allowed = false; } - function restartApp(onlyIfUpdateIsPending = false) { - (async function(onlyIfUpdateIsPending) { - var didRestartSucceed = false; - - if (_restartPending) { - _restartPendingOnUpdateOnly = _restartPendingOnUpdateOnly && onlyIfUpdateIsPending; - log("Restart request queued until restarts are re-allowed"); + async function restartApp(onlyIfUpdateIsPending = false) { + if (_restartInProgress) { + log("Restart request queued until the current restart is completed"); + _restartQueue.push(onlyIfUpdateIsPending); + } else if (!_allowed) { + log("Restart request queued until restarts are re-allowed"); + _restartQueue.push(onlyIfUpdateIsPending); + } else { + _restartInProgress = true; + log("Restarting app"); + if (await NativeCodePush.restartApp(onlyIfUpdateIsPending)) { + // The app has already restarted, so there is no need to + // process the remaining queued restarts. return; } - - if (!!_inProgressPromise) { - didRestartSucceed = await _inProgressPromise; - if (didRestartSucceed) { - log("A restart is already in progress."); - return; - } + + _restartInProgress = false; + if (_restartQueue.length) { + restartApp(_restartQueue.shift(1)); } - - _inProgressPromise = new Promise(async function(resolve, reject) { - resolve(await restartAppInternal(onlyIfUpdateIsPending)); - }); - _inProgressOnUpdateOnly = onlyIfUpdateIsPending; - - didRestartSucceed = await _inProgressPromise; - if (!didRestartSucceed) _inProgressPromise = null; - })(onlyIfUpdateIsPending); - }; - - async function restartAppInternal(onlyIfUpdateIsPending = false) { - if (_allowed) { - var didRestartSucceed = await NativeCodePush.restartApp(onlyIfUpdateIsPending); - log("Restarting app"); - return didRestartSucceed; - } else { - log("Restart request queued until restarts are re-allowed"); - _restartPending = true; - _restartPendingOnUpdateOnly = onlyIfUpdateIsPending; - return true; } } return { allow, - clearPendingRestart, + clearPendingRestart, disallow, restartApp }; From 228441f3d3b73fc3f9426ebc11d321401b6073fe Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 28 Jun 2016 14:42:12 -0700 Subject: [PATCH 07/11] add restartInProgress flag --- RestartManager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/RestartManager.js b/RestartManager.js index 807bc9b..1677f74 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -3,6 +3,7 @@ const NativeCodePush = require("react-native").NativeModules.CodePush; const RestartManager = (() => { let _allowed = true; + let _restartInProgress = false; let _restartQueue = []; function allow() { From c7fa9ace2ddca56a9f19f396e4c5c3882de78a29 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 28 Jun 2016 14:52:48 -0700 Subject: [PATCH 08/11] remove old method --- .../microsoft/codepush/react/CodePushNativeModule.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 95459d9..9894599 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -461,15 +461,6 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { promise.resolve(false); } - @ReactMethod - public void restartApp(boolean onlyIfUpdateIsPending) { - // If this is an unconditional restart request, or there - // is current pending update, then reload the app. - if (!onlyIfUpdateIsPending || mSettingsManager.isPendingUpdate(null)) { - loadBundle(); - } - } - @ReactMethod public void saveStatusReportForRetry(ReadableMap statusReport) { mTelemetryManager.saveStatusReportForRetry(statusReport); From 8624904cd4e03473ee8e3486c2c5d4d8224c3356 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 28 Jun 2016 14:53:42 -0700 Subject: [PATCH 09/11] fix bug from merge conflict resolution --- .../java/com/microsoft/codepush/react/CodePushNativeModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 9894599..8a88db1 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -452,7 +452,7 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { public void restartApp(boolean onlyIfUpdateIsPending, Promise promise) { // If this is an unconditional restart request, or there // is current pending update, then reload the app. - if (!onlyIfUpdateIsPending || CodePush.this.isPendingUpdate(null)) { + if (!onlyIfUpdateIsPending || mSettingsManager.isPendingUpdate(null)) { loadBundle(); promise.resolve(true); return; From e36861ea01c15229c8da53dd599491f6103ef971 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 28 Jun 2016 16:35:18 -0700 Subject: [PATCH 10/11] Update RestartManager.js --- RestartManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RestartManager.js b/RestartManager.js index 1677f74..00bde29 100644 --- a/RestartManager.js +++ b/RestartManager.js @@ -34,10 +34,10 @@ const RestartManager = (() => { _restartQueue.push(onlyIfUpdateIsPending); } else { _restartInProgress = true; - log("Restarting app"); if (await NativeCodePush.restartApp(onlyIfUpdateIsPending)) { // The app has already restarted, so there is no need to // process the remaining queued restarts. + log("Restarting app"); return; } @@ -56,4 +56,4 @@ const RestartManager = (() => { }; })(); -module.exports = RestartManager; \ No newline at end of file +module.exports = RestartManager; From 9cfbac6d6fb42cd6e5f94f40a1f067e151e352e9 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 28 Jun 2016 17:03:53 -0700 Subject: [PATCH 11/11] update installed message in demo app --- Examples/CodePushDemoApp/android/app/build.gradle | 5 ++--- Examples/CodePushDemoApp/crossplatformdemo.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Examples/CodePushDemoApp/android/app/build.gradle b/Examples/CodePushDemoApp/android/app/build.gradle index 19f6777..6170451 100644 --- a/Examples/CodePushDemoApp/android/app/build.gradle +++ b/Examples/CodePushDemoApp/android/app/build.gradle @@ -61,8 +61,7 @@ apply from: "react.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" /** - * Set this to true to create three separate APKs instead of one: - * - A universal APK that works on all devices + * Set this to true to create two separate APKs instead of one: * - An APK that only works on ARM devices * - An APK that only works on x86 devices * The advantage is the size of the APK is reduced by about 4MB. @@ -93,7 +92,7 @@ android { splits { abi { enable enableSeparateBuildPerCPUArchitecture - universalApk true + universalApk false // Also generate an universal APK reset() include "armeabi-v7a", "x86" } diff --git a/Examples/CodePushDemoApp/crossplatformdemo.js b/Examples/CodePushDemoApp/crossplatformdemo.js index ff7de19..368b7e3 100644 --- a/Examples/CodePushDemoApp/crossplatformdemo.js +++ b/Examples/CodePushDemoApp/crossplatformdemo.js @@ -57,7 +57,7 @@ let CodePushDemoApp = React.createClass({ break; case CodePush.SyncStatus.UPDATE_INSTALLED: self.setState({ - syncMessage: "Update installed and will be run when the app next resumes.", + syncMessage: "Update installed.", progress: false }); break;