This commit is contained in:
Igor Krasavin 2020-08-28 17:16:35 +03:00 коммит произвёл GitHub
Родитель 83a9fedc17
Коммит 29feb6f967
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 66 добавлений и 49 удалений

Просмотреть файл

@ -6,7 +6,7 @@
This plugin provides client-side integration for the [CodePush service](https://microsoft.github.io/code-push/), allowing you to easily add a dynamic update experience to your Cordova app(s).
<!-- Cordova Catelog -->
<!-- Cordova Catalog -->
* [How does it work?](#how-does-it-work)
* [Supported Cordova Platforms](#supported-cordova-platforms)
@ -18,7 +18,7 @@ This plugin provides client-side integration for the [CodePush service](https://
* [PhoneGap Build](#phonegap-build)
* [Example Apps](#example-apps)
<!-- Cordova Catelog -->
<!-- Cordova Catalog -->
## How does it work?
@ -94,33 +94,33 @@ With the CodePush plugin installed, configure your app to use it via the followi
</platform>
```
You can use the same private/public key pair for each platform.
2. If you're using an `<access origin="*" />` element in your `config.xml` file, then your app is already allowed to communicate with the CodePush servers and you can safely skip this step. Otherwise, add the following additional `<access />` elements:
```xml
<access origin="https://codepush.appcenter.ms" />
<access origin="https://codepush.blob.core.windows.net" />
<access origin="https://codepushupdates.azureedge.net" />
```
3. To ensure that your app can access the CodePush server on [CSP](https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Introducing_Content_Security_Policy)-compliant platforms, add `https://codepush.appcenter.ms` to the `Content-Security-Policy` `meta` tag in your `index.html` file:
```xml
<meta http-equiv="Content-Security-Policy" content="default-src https://codepush.appcenter.ms 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *" />
```
4. Finally, double-check that you already have the [`cordova-plugin-whitelist`](https://github.com/apache/cordova-plugin-whitelist) plugin installed (most apps will). To check this, simply run the following command:
```shell
cordova plugin ls
```
If `cordova-plugin-whitelist` is in the list, then you are good to go. Otherwise, simply run the following command to add it:
```shell
cordova plugin add cordova-plugin-whitelist
```
You are now ready to use the plugin in the application code. See the [sample applications](/samples) for examples and the API documentation for more details.
*NOTE: There is a possibility to specify WebView engine on the plugin build phase. By default UIWebView engine is used. You can force plugin to use WKWebView by adding this iOS specific preference:*
@ -198,7 +198,7 @@ The CodePush client supports differential updates, so even though you are releas
*NOTE: for **Ionic** apps you need to run `ionic build` before running `cordova-release` or `release` command in order to build web assets.*
For more details about how the `release-cordova` command works, as well as the various parameters it exposes, refer to the [CLI docs](https://github.com/Microsoft/code-push/tree/master/cli#releasing-updates-cordova). Additionally, if you would prefer to handle running the `cordova prepare` command yourself, and therefore, want an even more flexible solution than `release-cordova`, refer to the [`release` command](https://github.com/Microsoft/code-push/tree/master/cli#releasing-updates-general) for more details.
For more details about how the `release-cordova` command works, as well as the various parameters it exposes, refer to the [CLI docs](https://docs.microsoft.com/en-us/appcenter/distribution/codepush/cli#releasing-updates-cordova). Additionally, if you would prefer to handle running the `cordova prepare` command yourself, and therefore, want an even more flexible solution than `release-cordova`, refer to the [`release` command](https://docs.microsoft.com/en-us/appcenter/distribution/codepush/cli#releasing-updates-general) for more details.
If you run into any issues, or have any questions/comments/feedback, you can [e-mail us](mailto:codepushfeed@microsoft.com) and/or open a new issue on this repo and we'll respond ASAP!
@ -241,7 +241,7 @@ When the update check completes, it will trigger the `onUpdateCheck` callback wi
1. `null` if there is no update available. This occurs in the following scenarios:
1. The configured deployment doesn't contain any releases, and therefore, nothing to update.
2. The latest release within the configured deployment is targeting a different binary version than what you're currently running (either older or newer).
3. The currently running app already has the latest release from the configured deployment, and therefore, doesn't need it again.
@ -281,9 +281,9 @@ When the update retrieval completes, it will trigger the `onSuccess` callback wi
1. `null` if the app is currently running the HTML start page from the binary and not a CodePush update. This occurs in the following scenarios:
1. The end-user installed the app binary and has yet to install a CodePush update
2. The end-user installed an update of the binary (e.g. from the store), which cleared away the old CodePush updates, and gave precedence back to the binary.
2. A `LocalPackage` instance which represents the metadata for the currently running CodePush update.
Parameters:
@ -300,7 +300,7 @@ codePush.getCurrentPackage(function (update) {
console.log("No updates have been installed");
return;
}
// If the current app "session" represents the first time
// this update has run, and it had a description provided
// with it upon release, let's show it to the end user
@ -321,7 +321,7 @@ Gets the metadata for the currently pending update (if one exists). An update is
When the update retrieval completes, it will trigger the `onSuccess` callback with one of two possible values:
1. `null` if the app doesn't currently have a pending update (e.g. the app is already running the latest available version).
2. A `LocalPackage` instance which represents the metadata for the currently pending CodePush update.
Parameters:
@ -387,7 +387,7 @@ Example Usage:
```javascript
// Fully silent update which keeps the app in
// sync with the server, without ever
// sync with the server, without ever
// interrupting the end user
codePush.sync();
@ -408,7 +408,7 @@ While the sync method tries to make it easy to perform silent and active updates
- __downloadProgress__: Called periodically when an available update is being downloaded from the CodePush server. The method is called with a `DownloadProgress` object, which contains the following two properties:
- __totalBytes__ *(Number)* - The total number of bytes expected to be received for this update (i.e. the size of the set of files which changed from the previous release).
- __receivedBytes__ *(Number)* - The number of bytes downloaded thus far, which can be used to track download progress.
#### SyncOptions
@ -466,14 +466,14 @@ codePush.sync(null, { updateDialog: { updateTitle: "An update is available!" } }
codePush.sync(null, {
updateDialog: {
appendReleaseDescription: true,
descriptionPrefix: "\n\nChange log:\n"
descriptionPrefix: "\n\nChange log:\n"
},
installMode: InstallMode.IMMEDIATE
});
// Silently check for the update, but
// display a custom downloading UI
// via the SyncStatus and DowloadProgress callbacks
// via the SyncStatus and DownloadProgress callbacks
codePush.sync(syncStatus, null, downloadProgress);
function syncStatus(status) {
@ -499,7 +499,7 @@ The `sync` method can be called anywhere you'd like to check for an update. That
### Package objects
The `checkForUpdate` and `getCurrentPackage` methods invoke success callbacks, that when triggered, provide acces to "package" objects. The package represents your code update as well as any extra metadata (e.g. description, mandatory?). The CodePush API has the distinction between the following types of packages:
The `checkForUpdate` and `getCurrentPackage` methods invoke success callbacks, that when triggered, provide access to "package" objects. The package represents your code update as well as any extra metadata (e.g. description, mandatory?). The CodePush API has the distinction between the following types of packages:
1. `LocalPackage`: Represents a downloaded update that is either already running, or has been installed and is pending an app restart.
@ -561,7 +561,7 @@ var onUpdateCheck = function (remotePackage) {
if (!remotePackage) {
console.log("The application is up to date.");
} else {
// The hash of each previously reverted package is stored for later use.
// The hash of each previously reverted package is stored for later use.
// This way, we avoid going into an infinite bad update/revert loop.
if (!remotePackage.failedInstall) {
console.log("A CodePush update is available. Package hash: " + remotePackage.packageHash);
@ -667,8 +667,8 @@ Defines the possible statuses of the [sync](#codepushsync) operation. There are
- __UPDATE_INSTALLED__: An available update has been installed and will be run either immediately after the callback function returns or the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
- __UPDATE_IGNORED__: The app has an optional update, which the end user chose to ignore. *(This is only applicable when the `updateDialog` is used)*
- __ERROR__: An error occurred during the `sync` operation. This might be an error while communicating with the server, downloading or unziping the update. The console logs should contain more information about what happened. No update has been applied in this case.
- __ERROR__: An error occurred during the `sync` operation. This might be an error while communicating with the server, downloading or unzipping the update. The console logs should contain more information about what happened. No update has been applied in this case.
- __IN_PROGRESS__: Another sync is already running, so this attempt to sync has been aborted.

Просмотреть файл

@ -86,7 +86,7 @@ var LocalPackage = (function (_super) {
});
}
catch (e) {
installError && installError(new Error("An error occured while installing the package. " + CodePushUtil.getErrorMessage(e)));
installError && installError(new Error("An error occurred while installing the package. " + CodePushUtil.getErrorMessage(e)));
}
};
LocalPackage.prototype.verifyPackage = function (deploymentResult, installError, successCallback) {
@ -232,12 +232,18 @@ var LocalPackage = (function (_super) {
var installModeToUse = _this.isMandatory ? installOptions.mandatoryInstallMode : installOptions.installMode;
if (installModeToUse === InstallMode.IMMEDIATE) {
installSuccess && installSuccess(installModeToUse);
cordova.exec(function () { }, function () { }, "CodePush", "install", [deployDir.fullPath,
installModeToUse.toString(), installOptions.minimumBackgroundDuration.toString()]);
cordova.exec(function () { }, function () { }, "CodePush", "install", [
deployDir.fullPath,
installModeToUse.toString(),
installOptions.minimumBackgroundDuration.toString()
]);
}
else {
cordova.exec(function () { installSuccess && installSuccess(installModeToUse); }, function () { installError && installError(); }, "CodePush", "install", [deployDir.fullPath,
installModeToUse.toString(), installOptions.minimumBackgroundDuration.toString()]);
cordova.exec(function () { installSuccess && installSuccess(installModeToUse); }, function () { installError && installError(); }, "CodePush", "install", [
deployDir.fullPath,
installModeToUse.toString(),
installOptions.minimumBackgroundDuration.toString()
]);
}
};
var preInstallSuccess = function () {
@ -245,7 +251,7 @@ var LocalPackage = (function (_super) {
};
var preInstallFailure = function (preInstallError) {
CodePushUtil.logError("Preinstall failure.", preInstallError);
var error = new Error("An error has occured while installing the package. " + CodePushUtil.getErrorMessage(preInstallError));
var error = new Error("An error has occurred while installing the package. " + CodePushUtil.getErrorMessage(preInstallError));
installError && installError(error);
};
cordova.exec(preInstallSuccess, preInstallFailure, "CodePush", "preInstall", [deployDir.fullPath]);

Просмотреть файл

@ -46,7 +46,7 @@ class LocalPackage extends Package implements ILocalPackage {
* Otherwise, the install operation will be marked as failed, and the application is reverted to its previous version on the next run.
*
* @param installSuccess Callback invoked if the install operation succeeded.
* @param installError Optional callback inovoked in case of an error.
* @param installError Optional callback invoked in case of an error.
* @param installOptions Optional parameter used for customizing the installation behavior.
*/
public install(installSuccess: SuccessCallback<InstallMode>, errorCallback?: ErrorCallback, installOptions?: InstallOptions) {
@ -110,7 +110,7 @@ class LocalPackage extends Package implements ILocalPackage {
}
});
} catch (e) {
installError && installError(new Error("An error occured while installing the package. " + CodePushUtil.getErrorMessage(e)));
installError && installError(new Error("An error occurred while installing the package. " + CodePushUtil.getErrorMessage(e)));
}
}
@ -130,10 +130,10 @@ class LocalPackage extends Package implements ILocalPackage {
});
} else {
var errorMessage =
"Error! Public key was provided but there is no JWT signature within app bundle to verify. " +
"Possible reasons, why that might happen: \n" +
"1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.\n" +
"2. You've been released CodePush bundle update without providing --privateKeyPath option.";
"Error! Public key was provided but there is no JWT signature within app bundle to verify. " +
"Possible reasons, why that might happen: \n" +
"1. You've been released CodePush bundle update using version of CodePush CLI that is not support code signing.\n" +
"2. You've been released CodePush bundle update without providing --privateKeyPath option.";
installError && installError(new Error(errorMessage));
}
} else {
@ -146,7 +146,7 @@ class LocalPackage extends Package implements ILocalPackage {
// verifyHash
this.verifyHash(deployDir, this.packageHash, verificationFail, successCallback);
} else {
if (deploymentResult.isDiffUpdate){
if (deploymentResult.isDiffUpdate) {
// verifyHash
this.verifyHash(deployDir, this.packageHash, verificationFail, successCallback);
} else {
@ -156,7 +156,7 @@ class LocalPackage extends Package implements ILocalPackage {
}
};
if (deploymentResult.isDiffUpdate){
if (deploymentResult.isDiffUpdate) {
CodePushUtil.logMessage("Applying diff update");
} else {
CodePushUtil.logMessage("Applying full update");
@ -200,7 +200,7 @@ class LocalPackage extends Package implements ILocalPackage {
cordova.exec(success, fail, "CodePush", "getPublicKey", []);
}
private getSignatureFromUpdate(deployDir: DirectoryEntry, callback: Callback<string>){
private getSignatureFromUpdate(deployDir: DirectoryEntry, callback: Callback<string>) {
var rootUri = cordova.file.dataDirectory;
var path = deployDir.fullPath + "/www";
@ -225,7 +225,7 @@ class LocalPackage extends Package implements ILocalPackage {
});
}
private verifyHash(deployDir: DirectoryEntry, newUpdateHash: string, errorCallback: ErrorCallback, successCallback: SuccessCallback<void>){
private verifyHash(deployDir: DirectoryEntry, newUpdateHash: string, errorCallback: ErrorCallback, successCallback: SuccessCallback<void>) {
var packageHashSuccess = (computedHash: string) => {
if (computedHash !== newUpdateHash) {
errorCallback(new Error("The update contents failed the data integrity check."));
@ -242,7 +242,7 @@ class LocalPackage extends Package implements ILocalPackage {
cordova.exec(packageHashSuccess, packageHashFail, "CodePush", "getPackageHash", [deployDir.fullPath]);
}
private verifySignature(deployDir: DirectoryEntry, newUpdateHash: string, publicKey: string, signature: string, errorCallback: ErrorCallback, successCallback: SuccessCallback<void>){
private verifySignature(deployDir: DirectoryEntry, newUpdateHash: string, publicKey: string, signature: string, errorCallback: ErrorCallback, successCallback: SuccessCallback<void>) {
var decodeSignatureSuccess = (contentHash: string) => {
if (contentHash !== newUpdateHash) {
errorCallback(new Error("The update contents failed the code signing check."));
@ -285,11 +285,22 @@ class LocalPackage extends Package implements ILocalPackage {
/* invoke success before navigating */
installSuccess && installSuccess(installModeToUse);
/* no need for callbacks, the javascript context will reload */
cordova.exec(() => { }, () => { }, "CodePush", "install", [deployDir.fullPath,
installModeToUse.toString(), installOptions.minimumBackgroundDuration.toString()]);
cordova.exec(() => { }, () => { }, "CodePush", "install",
[
deployDir.fullPath,
installModeToUse.toString(),
installOptions.minimumBackgroundDuration.toString()
]
);
} else {
cordova.exec(() => { installSuccess && installSuccess(installModeToUse); }, () => { installError && installError(); }, "CodePush", "install", [deployDir.fullPath,
installModeToUse.toString(), installOptions.minimumBackgroundDuration.toString()]);
cordova.exec(() => { installSuccess && installSuccess(installModeToUse); },
() => { installError && installError(); }, "CodePush", "install",
[
deployDir.fullPath,
installModeToUse.toString(),
installOptions.minimumBackgroundDuration.toString()
]
);
}
};
@ -300,7 +311,7 @@ class LocalPackage extends Package implements ILocalPackage {
var preInstallFailure = (preInstallError?: any) => {
CodePushUtil.logError("Preinstall failure.", preInstallError);
var error = new Error("An error has occured while installing the package. " + CodePushUtil.getErrorMessage(preInstallError));
var error = new Error("An error has occurred while installing the package. " + CodePushUtil.getErrorMessage(preInstallError));
installError && installError(error);
};
@ -319,7 +330,7 @@ class LocalPackage extends Package implements ILocalPackage {
LocalPackage.handleDiffDeployment(newPackageLocation, diffManifest, deployCallback);
} else {
LocalPackage.handleCleanDeployment(newPackageLocation, (error: Error) => {
deployCallback(error, {deployDir, isDiffUpdate: false});
deployCallback(error, { deployDir, isDiffUpdate: false });
});
}
});
@ -363,7 +374,7 @@ class LocalPackage extends Package implements ILocalPackage {
if (copyError) {
cleanDeployCallback(copyError, null);
} else {
cleanDeployCallback(null, {deployDir, isDiffUpdate: false});
cleanDeployCallback(null, { deployDir, isDiffUpdate: false });
}
});
}
@ -438,7 +449,7 @@ class LocalPackage extends Package implements ILocalPackage {
if (deleteError || deployDirError) {
handleError(new Error("Cannot clean up deleted manifest files."));
} else {
diffCallback(null, {deployDir, isDiffUpdate: true});
diffCallback(null, { deployDir, isDiffUpdate: true });
}
});
});