Skip to content

Commit

Permalink
feat: add cancel delay
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Feb 11, 2022
1 parent 6a70e7f commit e06caa2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ public void delayUpdate(PluginCall call) {
call.resolve();
}

@PluginMethod
public void cancelDelay(PluginCall call) {
editor.putBoolean("delayUpdate", false);
editor.commit();
call.resolve();
}

@Override
public void onActivityStarted(@NonNull Activity activity) {
Log.i(TAG, "Check for update in the server");
Expand Down
8 changes: 7 additions & 1 deletion ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {

@objc func appMovedToBackground() {
print("✨ Capacitor-updater: Check for waiting update")
let delayUpdate = UserDefaults.standard.bool(forKey: "delayUpdate") ?? false
let delayUpdate = UserDefaults.standard.bool(forKey: "delayUpdate")
UserDefaults.standard.set(false, forKey: "delayUpdate")
if (delayUpdate) {
print("✨ Capacitor-updater: Update delayed to next backgrounding")
Expand Down Expand Up @@ -226,8 +226,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
UserDefaults.standard.set(true, forKey: "notifyAppReady")
call.resolve()
}

@objc func delayUpdate(_ call: CAPPluginCall) {
UserDefaults.standard.set(true, forKey: "delayUpdate")
call.resolve()
}

@objc func cancelDelay(_ call: CAPPluginCall) {
UserDefaults.standard.set(false, forKey: "delayUpdate")
call.resolve()
}
}
23 changes: 14 additions & 9 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
export interface CapacitorUpdaterPlugin {
/**
* download new version from url, it should be a zip file, with files inside or with a unique folder inside with all your files
* Download new version from url, it should be a zip file, with files inside or with a unique folder inside with all your files
* @returns {Promise<{version: string}>} an Promise with version name of the downloaded version, version is generated by the plugin, it's a random string of 10 char length
* @param url The url where download the version, it can be S3 github tag or whatever, it should be a zip file
*/
download(options: { url: string }): Promise<{ version: string }>;
/**
* set version as current version, set will return error if there are no index.html file inside the version folder, versionName is optional and it's a custom value who will be saved for you
* Set version as current version, set will return error if there are no index.html file inside the version folder, versionName is optional and it's a custom value who will be saved for you
* @returns {Promise<void>} an empty Promise when the version is set, if there are no index.html or no version folder throw an error
* @param version The version name to set as current version
*/
set(options: { version: string, versionName?: string }): Promise<void>;
/**
* delete version in storage
* Delete version in storage
* @returns {Promise<void>} an empty Promise when the version is delete, otherwise throw an error
* @param version The version name to delete
*/
delete(options: { version: string }): Promise<void>;
/**
* get all avaible versions
* Get all avaible versions
* @returns {Promise<{version: string[]}>} an Promise witht the version list
*/
list(): Promise<{ versions: string[] }>;
/**
* set the original version (the one sent to Apple store / Google play store ) as current version
* Set the original version (the one sent to Apple store / Google play store ) as current version
* @returns {Promise<void>} an empty Promise
*/
reset(): Promise<void>;
/**
* get the curent version, if none are set it return 'default'
* Get the curent version, if none are set it return 'default'
* @returns {Promise<{ current: string }>} an Promise with the current version name
*/
current(): Promise<{ current: string }>;
/**
* reload the view
* Reload the view
* @returns {Promise<void>} an Promise resolved when the view is reloaded
*/
reload(): Promise<void>;
Expand All @@ -43,13 +43,18 @@ export interface CapacitorUpdaterPlugin {
*/
versionName(): Promise<{ versionName: string }>;
/**
* notify native plugin that the update is working
* Notify native plugin that the update is working
* @returns {Promise<void>} an Promise resolved directly
*/
notifyAppReady(): Promise<void>;
/**
* skip update in the next app backgrounding
* Skip update in the next app backgrounding
* @returns {Promise<void>} an Promise resolved directly
*/
delayUpdate(): Promise<void>;
/**
* Cancel skip update in the next app backgrounding
* @returns {Promise<void>} an Promise resolved directly
*/
cancelDelay(): Promise<void>;
}
4 changes: 4 additions & 0 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ export class CapacitorUpdaterWeb
console.log('Cannot delay update in web');
return;
}
async cancelDelay(): Promise<void> {
console.log('Cannot cancel delay update in web');
return;
}
}

0 comments on commit e06caa2

Please sign in to comment.