Skip to content

Commit

Permalink
fix: use bundle instead of version in appropriate places (affects bot…
Browse files Browse the repository at this point in the history
…h typescript and java, possibly ios)
  • Loading branch information
lincolnthree committed Jun 29, 2022
1 parent caac9dc commit 2a40471
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void notifyDownload(final String id, final int percent) {
try {
final JSObject ret = new JSObject();
ret.put("percent", percent);
ret.put("version", this.implementation.getBundleInfo(id).toJSON());
ret.put("bundle", this.implementation.getBundleInfo(id).toJSON());
this.notifyListeners("download", ret);
} catch (final Exception e) {
Log.e(CapacitorUpdater.TAG, "Could not notify listeners", e);
Expand Down Expand Up @@ -227,7 +227,7 @@ public void next(final PluginCall call) {
try {
Log.i(CapacitorUpdater.TAG, "Setting next active id " + id);
if (!this.implementation.setNextVersion(id)) {
call.reject("Set next id failed. Version " + id + " does not exist.");
call.reject("Set next id failed. Bundle " + id + " does not exist.");
} else {
call.resolve(this.implementation.getBundleInfo(id).toJSON());
}
Expand Down Expand Up @@ -287,8 +287,8 @@ public void list(final PluginCall call) {
call.resolve(ret);
}
catch(final Exception e) {
Log.e(CapacitorUpdater.TAG, "Could not list versions", e);
call.reject("Could not list versions", e);
Log.e(CapacitorUpdater.TAG, "Could not list bundles", e);
call.reject("Could not list bundles", e);
}
}

Expand Down Expand Up @@ -331,8 +331,8 @@ public void current(final PluginCall call) {
call.resolve(ret);
}
catch(final Exception e) {
Log.e(CapacitorUpdater.TAG, "Could not get current bundle version", e);
call.reject("Could not get current bundle version", e);
Log.e(CapacitorUpdater.TAG, "Could not get current bundle", e);
call.reject("Could not get current bundle", e);
}
}

Expand Down Expand Up @@ -433,11 +433,11 @@ public void run() {
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
if(latest != null) {
if(latest.isErrorStatus()) {
Log.e(CapacitorUpdater.TAG, "Latest version already exists, and is in error state. Aborting update.");
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists, and is in error state. Aborting update.");
return;
}
if(latest.isDownloaded()){
Log.e(CapacitorUpdater.TAG, "Latest version already exists and download is NOT required. Update will occur next time app moves to background.");
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
CapacitorUpdaterPlugin.this.implementation.setNextVersion(latest.getId());
return;
}
Expand All @@ -464,7 +464,7 @@ public void run() {
}
}).start();
} else {
Log.i(CapacitorUpdater.TAG, "No need to update, " + current + " is the latest version.");
Log.i(CapacitorUpdater.TAG, "No need to update, " + current + " is the latest bundle.");
}
} catch (final JSONException e) {
Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
Expand Down Expand Up @@ -496,28 +496,28 @@ public void onActivityStopped(@NonNull final Activity activity) {

final Boolean success = current.getStatus() == BundleStatus.SUCCESS;

Log.d(CapacitorUpdater.TAG, "Fallback version is: " + fallback);
Log.d(CapacitorUpdater.TAG, "Current version is: " + current);
Log.d(CapacitorUpdater.TAG, "Fallback bundle is: " + fallback);
Log.d(CapacitorUpdater.TAG, "Current bundle is: " + current);

if (next != null && !next.isErrorStatus() && (next.getId() != current.getId())) {
// There is a next version waiting for activation
Log.d(CapacitorUpdater.TAG, "Next version is: " + next.getVersionName());
// There is a next bundle waiting for activation
Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
if (this.implementation.set(next) && this._reload()) {
Log.i(CapacitorUpdater.TAG, "Updated to version: " + next.getVersionName());
Log.i(CapacitorUpdater.TAG, "Updated to bundle: " + next.getVersionName());
this.implementation.setNextVersion(null);
} else {
Log.e(CapacitorUpdater.TAG, "Update to version: " + next.getVersionName() + " Failed!");
Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
}
} else if (!success) {
// There is a no next version, and the current version has failed
// There is a no next bundle, and the current bundle has failed

if(!current.isBuiltin()) {
// Don't try to roll back the builtin version. Nothing we can do.
// Don't try to roll back the builtin bundle. Nothing we can do.

this.implementation.rollback(current);

Log.i(CapacitorUpdater.TAG, "Update failed: 'notifyAppReady()' was never called.");
Log.i(CapacitorUpdater.TAG, "Version: " + current + ", is in error state.");
Log.i(CapacitorUpdater.TAG, "Bundle: " + current + ", is in error state.");
Log.i(CapacitorUpdater.TAG, "Will fallback to: " + fallback + " on application restart.");
Log.i(CapacitorUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
final JSObject ret = new JSObject();
Expand All @@ -527,9 +527,9 @@ public void onActivityStopped(@NonNull final Activity activity) {
if (!fallback.isBuiltin() && !fallback.equals(current)) {
final Boolean res = this.implementation.set(fallback);
if (res && this._reload()) {
Log.i(CapacitorUpdater.TAG, "Revert to version: " + fallback.getVersionName());
Log.i(CapacitorUpdater.TAG, "Revert to bundle: " + fallback.getVersionName());
} else {
Log.e(CapacitorUpdater.TAG, "Revert to version: " + fallback.getVersionName() + " Failed!");
Log.e(CapacitorUpdater.TAG, "Revert to bundle: " + fallback.getVersionName() + " Failed!");
}
} else {
if (this._reset(false)) {
Expand All @@ -538,33 +538,33 @@ public void onActivityStopped(@NonNull final Activity activity) {
}

if (this.autoDeleteFailed) {
Log.i(CapacitorUpdater.TAG, "Deleting failing version: " + current.getVersionName());
Log.i(CapacitorUpdater.TAG, "Deleting failing bundle: " + current.getVersionName());
try {
final Boolean res = this.implementation.delete(current.getId());
if (res) {
Log.i(CapacitorUpdater.TAG, "Failed version deleted: " + current.getVersionName());
Log.i(CapacitorUpdater.TAG, "Failed bundle deleted: " + current.getVersionName());
}
} catch (final IOException e) {
Log.e(CapacitorUpdater.TAG, "Failed to delete failed version: " + current.getVersionName(), e);
Log.e(CapacitorUpdater.TAG, "Failed to delete failed bundle: " + current.getVersionName(), e);
}
}
} else {
// Nothing we can/should do by default if the 'builtin' bundle fails to call 'notifyAppReady()'.
}

} else if (!fallback.isBuiltin()) {
// There is a no next version, and the current version has succeeded
// There is a no next bundle, and the current bundle has succeeded
this.implementation.commit(current);

if(this.autoDeletePrevious) {
Log.i(CapacitorUpdater.TAG, "Version successfully loaded: " + current);
Log.i(CapacitorUpdater.TAG, "Bundle successfully loaded: " + current);
try {
final Boolean res = this.implementation.delete(fallback.getVersionName());
if (res) {
Log.i(CapacitorUpdater.TAG, "Deleted previous version: " + fallback.getVersionName());
Log.i(CapacitorUpdater.TAG, "Deleted previous bundle: " + fallback.getVersionName());
}
} catch (final IOException e) {
Log.e(CapacitorUpdater.TAG, "Failed to delete previous version: " + fallback.getVersionName(), e);
Log.e(CapacitorUpdater.TAG, "Failed to delete previous bundle: " + fallback.getVersionName(), e);
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare module '@capacitor/cli' {
appReadyTimeout?: number;

/**
* Configure whether the plugin should use automatically delete failed versions.
* Configure whether the plugin should use automatically delete failed bundles.
*
* Only available for Android and iOS.
*
Expand All @@ -28,7 +28,7 @@ declare module '@capacitor/cli' {
autoDeleteFailed?: boolean;

/**
* Configure whether the plugin should use automatically delete previous versions after a successful update.
* Configure whether the plugin should use automatically delete previous bundles after a successful update.
*
* Only available for Android and iOS.
*
Expand Down Expand Up @@ -58,7 +58,7 @@ declare module '@capacitor/cli' {
autoUpdateUrl?: string;

/**
* Automatically delete previous downloaded bundles when a newer native version is installed to the device.
* Automatically delete previous downloaded bundles when a newer native app version is installed to the device.
*
* Only available for Android and iOS.
*
Expand Down Expand Up @@ -88,23 +88,23 @@ export interface DownloadEvent {
* @since 4.0.0
*/
percent: number;
version: BundleInfo;
bundle: BundleInfo;
}
export interface MajorAvailableEvent {
/**
* Emit when a new major version is available.
*
* @since 4.0.0
*/
version: BundleInfo;
bundle: BundleInfo;
}
export interface UpdateAvailableEvent {
/**
* Emit when a new update is available.
*
* @since 4.0.0
*/
version: BundleInfo;
bundle: BundleInfo;
}

export interface UpdateFailedEvent {
Expand All @@ -113,7 +113,7 @@ export interface UpdateFailedEvent {
*
* @since 4.0.0
*/
version: BundleInfo;
bundle: BundleInfo;
}

export interface BundleInfo {
Expand Down Expand Up @@ -148,34 +148,34 @@ export interface CapacitorUpdaterPlugin {
*
* @returns {Promise<BundleInfo>} The {@link BundleInfo} for the specified version.
* @param url The URL of the bundle zip file (e.g: dist.zip) to be downloaded. (This can be any URL. E.g: Amazon S3, a github tag, any other place you've hosted your bundle.)
* @param version (optional) set the name of this version
* @param version (optional) set the version code/name of this bundle/version
* @example https://example.com/versions/{version}/dist.zip
*/
download(options: { url: string, version?: string }): Promise<BundleInfo>;

/**
* Set the next bundle version to be used when the app is reloaded.
* Set the next bundle to be used when the app is reloaded.
*
* @returns {Promise<BundleInfo>} The {@link BundleInfo.id} for the specified version.
* @param id The version id to set as current, next time the app is reloaded. See {@link BundleInfo.id}
* @returns {Promise<BundleInfo>} The {@link BundleInfo} for the specified bundle id.
* @param id The bundle id to set as current, next time the app is reloaded. See {@link BundleInfo.id}
* @throws An error if there are is no index.html file inside the version folder.
*/
next(options: { id: string }): Promise<BundleInfo>;

/**
* Set the current bundle version and immediately reloads the app.
* Set the current bundle and immediately reloads the app.
*
* @param id The version id to set as current. See {@link BundleInfo.id}
* @param id The bundle id to set as current. See {@link BundleInfo.id}
* @returns {Promise<Void>} An empty promise.
* @throws An error if there are is no index.html file inside the version folder.
*/
set(options: { id: string }): Promise<void>;

/**
* Delete version in storage
* Delete bundle in storage
*
* @returns {Promise<void>} an empty Promise when the version is deleted
* @param version The version to delete (note, this is the version, NOT the version name)
* @returns {Promise<void>} an empty Promise when the bundle is deleted
* @param id The bundle id to delete (note, this is the bundle id, NOT the version name)
* @throws An error if the something went wrong
*/
delete(options: { id: string }): Promise<void>;
Expand All @@ -186,21 +186,21 @@ export interface CapacitorUpdaterPlugin {
* @returns {Promise<{version: BundleInfo[]}>} an Promise witht the version list
* @throws An error if the something went wrong
*/
list(): Promise<{ versions: BundleInfo[] }>;
list(): Promise<{ bundles: BundleInfo[] }>;

/**
* Set the `builtin` version (the one sent to Apple store / Google play store ) as current version
*
* @returns {Promise<void>} an empty Promise
* @param toLastSuccessful [false] if yes it reset to to the last successfully loaded bundle version instead of `builtin`
* @param toLastSuccessful [false] if yes it reset to to the last successfully loaded bundle instead of `builtin`
* @throws An error if the something went wrong
*/
reset(options?: { toLastSuccessful?: boolean }): Promise<void>;

/**
* Get the current version, if none are set it returns `builtin`, currentNative is the original version install on the device
* Get the current bundle, if none are set it returns `builtin`, currentNative is the original bundle installed on the device
*
* @returns {Promise<{ current: string, currentNative: string }>} an Promise with the current version name
* @returns {Promise<{ current: string, currentNative: string }>} an Promise with the current bundle info
* @throws An error if the something went wrong
*/
current(): Promise<{ bundle: BundleInfo, native: string }>;
Expand Down
28 changes: 14 additions & 14 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,57 @@ import { WebPlugin } from '@capacitor/core';

import type { CapacitorUpdaterPlugin, BundleInfo } from './definitions';

const VERSION_BUILTIN: BundleInfo = { status: 'success', version: '', downloaded: '1970-01-01T00:00:00.000Z', id: 'builtin' };
const BUNDLE_BUILTIN: BundleInfo = { status: 'success', version: '', downloaded: '1970-01-01T00:00:00.000Z', id: 'builtin' };

export class CapacitorUpdaterWeb
extends WebPlugin
implements CapacitorUpdaterPlugin {
async download(options: { url: string, version?: string }): Promise<BundleInfo> {
console.warn('Cannot download version in web', options);
return VERSION_BUILTIN;
return BUNDLE_BUILTIN;
}
async next(options: { id: string }): Promise<BundleInfo> {
console.warn('Cannot set next version in web', options);
return VERSION_BUILTIN;
return BUNDLE_BUILTIN;
}

async isAutoUpdateEnabled(): Promise<{ enabled: boolean }> {
console.warn('Cannot get isAutoUpdateEnabled version in web');
console.warn('Cannot get isAutoUpdateEnabled in web');
return { enabled: false };
}
async set(options: { id: string }): Promise<void> {
console.warn('Cannot set version in web', options);
console.warn('Cannot set active bundle in web', options);
return;
}
async getId(): Promise<{ id: string }> {
console.warn('Cannot get ID in web');
return { id: 'default' };
}
async getPluginVersion(): Promise<{ version: string }> {
console.warn('Cannot get version in web');
console.warn('Cannot get plugin version in web');
return { version: 'default'};
}
async delete(options: { id: string }): Promise<void> {
console.warn('Cannot delete version in web', options);
console.warn('Cannot delete bundle in web', options);
}
async list(): Promise<{ versions: BundleInfo[] }> {
console.warn('Cannot list version in web');
return { versions: [] };
async list(): Promise<{ bundles: BundleInfo[] }> {
console.warn('Cannot list bundles in web');
return { bundles: [] };
}
async reset(options?: { toLastSuccessful?: boolean }): Promise<void> {
console.warn('Cannot reset version in web', options);
}
async current(): Promise<{ bundle: BundleInfo, native: string }> {
console.warn('Cannot get current version in web');
return { bundle: VERSION_BUILTIN, native: '0.0.0' };
console.warn('Cannot get current bundle in web');
return { bundle: BUNDLE_BUILTIN, native: '0.0.0' };
}
async reload(): Promise<void> {
console.warn('Cannot reload current version in web');
console.warn('Cannot reload current bundle in web');
return;
}
async notifyAppReady(): Promise<BundleInfo> {
console.warn('Cannot notify App Ready in web');
return VERSION_BUILTIN;
return BUNDLE_BUILTIN;
}
async setDelay(options: { delay: boolean }): Promise<void> {
console.warn('Cannot setDelay delay update in web', options);
Expand Down

0 comments on commit 2a40471

Please sign in to comment.