Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions CodePush.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,36 @@ const sync = (() => {
const setSyncCompleted = () => { syncInProgress = false; };

return (options = {}, syncStatusChangeCallback, downloadProgressCallback) => {
let syncStatusCallbackWithTryCatch, downloadProgressCallbackkWithTryCatch;
if (typeof syncStatusChangeCallback === "function") {
syncStatusCallbackWithTryCatch = (...args) => {
try {
syncStatusChangeCallback(...args);
} catch (error) {
log(`An error has occurred : ${error.stack}`);
}
}
}

if (typeof downloadProgressCallback === "function") {
downloadProgressCallbackkWithTryCatch = (...args) => {
try {
downloadProgressCallback(...args);
} catch (error) {
log(`An error has occurred: ${error.stack}`);
}
}
}

if (syncInProgress) {
typeof syncStatusChangeCallback === "function"
? syncStatusChangeCallback(CodePush.SyncStatus.SYNC_IN_PROGRESS)
typeof syncStatusCallbackWithTryCatch === "function"
? syncStatusCallbackWithTryCatch(CodePush.SyncStatus.SYNC_IN_PROGRESS)
: log("Sync already in progress.");
return Promise.resolve(CodePush.SyncStatus.SYNC_IN_PROGRESS);
}

syncInProgress = true;
const syncPromise = syncInternal(options, syncStatusChangeCallback, downloadProgressCallback);
const syncPromise = syncInternal(options, syncStatusCallbackWithTryCatch, downloadProgressCallbackkWithTryCatch);
syncPromise
.then(setSyncCompleted)
.catch(setSyncCompleted);
Expand Down