Skip to content

Commit 3eb375e

Browse files
jcesarmobilenphyatt
authored andcommitted
Allow to disable deploy updates with DisableDeploy preference (#142)
1 parent ec18a5f commit 3eb375e

9 files changed

+45
-35
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ The plugin will be available on `window` as `IonicCordova`
1717

1818
* `APP_ID` **Required** - Your Ionic Pro app ID
1919
* `CHANNEL_NAME` **Required** - The channel to check for updates from
20-
* `WARN_DEBUG` - Set false if you do not want the check when apk/ipa is in debug mode.
2120
* `UPDATE_API` - The location of the Ionic Pro API (only change this for development)
2221
* `UPDATE_METHOD` - `auto`, `background`, or `none`. Dictates the behavior of the plugin. `auto` will download and apply the latest update on app start, potentially leading to long splash screen loads if the connection is slow. `background` will only download the update in the background on app start, but will allow full functionality while doing so, only redirecting users the _next_ time the app is loaded. `none` will do nothing, leaving full plugin functionality in the hands of the developer. **Default is `background`**
2322
* `MAX_STORE` - The maximum number of downloaded versions to store on the device for quick loading. More versions means less downloading, but can increase the app size greatly. **Default is 3 (Defaults is 2 in V5)**
2423
* `MIN_BACKGROUND_DURATION` - The minimum duration in seconds after which the app in background checks for an update. **Default is 30 (New in V5)**
2524

25+
### Preferences
26+
27+
* `DisableDeploy` - Default value is `false`.
28+
29+
Allows to disable deploy updates by adding this preference in the config.xml
30+
31+
```
32+
<preference name="DisableDeploy" value="true" />
33+
```
34+
2635
## API Docs
2736

2837
* [IonicCordova](docs/interfaces/_ioniccordova_d_.ipluginbaseapi.md)

create-local-app.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ cordova plugin add ../cordova-plugin-ionic --save \
2626
--variable MIN_BACKGROUND_DURATION="$BACKGROUND_DURATION" \
2727
--variable APP_ID="${APP_ID}" \
2828
--variable CHANNEL_NAME="${CHANNEL}" \
29-
--variable UPDATE_METHOD="${UPDATE_METHOD}" \
30-
--variable WARN_DEBUG="false" --link
29+
--variable UPDATE_METHOD="${UPDATE_METHOD}" --link
3130
cordova prepare ios
3231
cordova prepare android

plugin.xml

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
</js-module>
1717
<preference name="APP_ID"/>
1818
<preference name="CHANNEL_NAME"/>
19-
<preference name="WARN_DEBUG" default="true"/>
2019
<preference name="UPDATE_API" default="https://api.ionicjs.com"/>
2120
<preference name="UPDATE_METHOD" default="background"/>
2221
<preference name="MAX_STORE" default="2"/>
@@ -29,16 +28,13 @@
2928
<feature name="IonicCordovaCommon">
3029
<param name="ios-package" value="IonicCordovaCommon" onload="true"/>
3130
</feature>
31+
<preference name="DisableDeploy" value="false" />
3232
</config-file>
3333

3434
<config-file target="*-Info.plist" parent="IonAppId">
3535
<string>$APP_ID</string>
3636
</config-file>
3737

38-
<config-file target="*-Info.plist" parent="IonDebug">
39-
<string>$WARN_DEBUG</string>
40-
</config-file>
41-
4238
<config-file target="*-Info.plist" parent="IonChannelName">
4339
<string>$CHANNEL_NAME</string>
4440
</config-file>
@@ -70,11 +66,11 @@
7066
<feature name="IonicCordovaCommon">
7167
<param name="android-package" value="com.ionicframework.common.IonicCordovaCommon" onload="true"/>
7268
</feature>
69+
<preference name="DisableDeploy" value="false" />
7370
</config-file>
7471

7572
<config-file target="res/values/strings.xml" parent="/resources">
7673
<string name="ionic_app_id">$APP_ID</string>
77-
<string name="ionic_debug">$WARN_DEBUG</string>
7874
<string name="ionic_channel_name">$CHANNEL_NAME</string>
7975
<string name="ionic_update_api">$UPDATE_API</string>
8076
<string name="ionic_update_method">$UPDATE_METHOD</string>

src/android/IonicCordovaCommon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private JSONObject getNativeConfig() throws JSONException {
229229

230230
String appId = getStringResourceByName("ionic_app_id");
231231
j.put("appId", appId);
232-
j.put("debug", getStringResourceByName("ionic_debug"));
232+
j.put("disabled", preferences.getBoolean("DisableDeploy", false));
233233
j.put("channel", getStringResourceByName("ionic_channel_name"));
234234
j.put("host", getStringResourceByName("ionic_update_api"));
235235
j.put("updateMethod", getStringResourceByName("ionic_update_method"));

src/ios/IonicCordovaCommon.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ - (void) setPreferences:(CDVInvokedUrlCommand*)command {
114114
- (NSMutableDictionary*) getNativeConfig {
115115
// Get preferences from cordova
116116
NSString *appId = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"IonAppId"]];
117-
NSString *debug = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"IonDebug"]];
117+
NSNumber * disabled = [NSNumber numberWithBool:[[self.commandDelegate.settings objectForKey:[@"DisableDeploy" lowercaseString]] boolValue]];
118118
NSString *host = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"IonApi"]];
119119
NSString *updateMethod = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"IonUpdateMethod"]];
120120
NSString *channel = [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"IonChannelName"]];
@@ -124,7 +124,7 @@ - (NSMutableDictionary*) getNativeConfig {
124124
// Build the preferences json object
125125
NSMutableDictionary *json = [[NSMutableDictionary alloc] init];
126126
json[@"appId"] = appId;
127-
json[@"debug"] = debug;
127+
json[@"disabled"] = disabled;
128128
json[@"channel"] = channel;
129129
json[@"host"] = host;
130130
json[@"updateMethod"] = updateMethod;
@@ -159,4 +159,4 @@ - (void) configure:(CDVInvokedUrlCommand *)command {
159159
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newConfig] callbackId:command.callbackId];
160160
}
161161

162-
@end
162+
@end

tests/test_common.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function callbackMock(returnValue: any, succeed: boolean) {
2525

2626
const pluginConfig = {
2727
appId: 'myapp',
28-
debug: 'false',
28+
disabled: false,
2929
host: 'https://myhost.com',
3030
channel: 'mychannel',
3131
updateMethod: 'auto',
@@ -122,7 +122,7 @@ describe('IonicCordova', () => {
122122
expect(await pluginBase.deploy._pluginConfig).toEqual(pluginConfig);
123123
const newConfig = {
124124
appId: 'newappid',
125-
debug: 'true',
125+
disabled: true,
126126
host: 'http://newhost.com',
127127
channel: 'newchannel',
128128
}
@@ -191,7 +191,7 @@ describe('IonicCordova', () => {
191191
const pluginBase = IonicCordova;
192192
const newConfig = {
193193
appId: 'newappid',
194-
debug: 'true',
194+
disabled: true,
195195
host: 'http://newhost.com',
196196
channel: 'newchannel',
197197
}
@@ -234,7 +234,7 @@ describe('IonicCordova', () => {
234234
expect(pluginBase.deploy._pluginConfig).resolves.toBe(pluginConfig);
235235
const newConfig = {
236236
appId: 'newappid',
237-
debug: 'true',
237+
disabled: true,
238238
host: 'http://newhost.com',
239239
channel: 'newchannel',
240240
}
@@ -249,7 +249,7 @@ describe('IonicCordova', () => {
249249
const pluginBase = IonicCordova;
250250
const newConfig = {
251251
appId: 'newappid',
252-
debug: 'true',
252+
disabled: true,
253253
host: 'http://newhost.com',
254254
channel: 'newchannel',
255255
}

types/IonicCordova.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ interface ICurrentConfig {
202202
binaryVersionCode: string;
203203

204204
/**
205-
* Whether the plugin is in debug mode or not.
205+
* Whether the user disabled deploy updates or not.
206206
*/
207-
debug: string;
207+
disabled: boolean;
208208

209209
/**
210210
* The host API the plugin is configured to check for updates from.

www/common.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ class IonicDeploy implements IDeployPluginAPI {
620620
private fetchIsAvailable: boolean;
621621
private lastPause = 0;
622622
private minBackgroundDuration = 10;
623+
private disabled = false;
623624

624625
constructor(parent: IPluginBaseAPI) {
625626
this.parent = parent;
@@ -632,14 +633,19 @@ class IonicDeploy implements IDeployPluginAPI {
632633
await this.platformReady();
633634
const preferences = await this._initPreferences();
634635
this.minBackgroundDuration = preferences.minBackgroundDuration;
636+
this.disabled = preferences.disabled || !this.fetchIsAvailable;
635637
const appInfo = await this.parent.getAppDetails();
636638
preferences.binaryVersionName = appInfo.binaryVersionName;
637639
preferences.binaryVersionCode = appInfo.binaryVersionCode;
638640
preferences.binaryVersion = appInfo.binaryVersionName;
639641
const delegate = new IonicDeployImpl(appInfo, preferences);
640-
// Only initialize start the plugin if fetch is available
641-
if (!this.fetchIsAvailable) {
642-
console.warn('Fetch is unavailable so cordova-plugin-ionic has been disabled.');
642+
// Only initialize start the plugin if fetch is available and DisableDeploy preference is false
643+
if (this.disabled) {
644+
let disabledMessage = 'cordova-plugin-ionic has been disabled.';
645+
if (!this.fetchIsAvailable) {
646+
disabledMessage = 'Fetch is unavailable so ' + disabledMessage;
647+
}
648+
console.warn(disabledMessage);
643649
await new Promise<string>( (resolve, reject) => {
644650
cordova.exec(resolve, reject, 'IonicCordovaCommon', 'clearSplashFlag');
645651
});
@@ -695,7 +701,7 @@ class IonicDeploy implements IDeployPluginAPI {
695701
}
696702

697703
async onResume() {
698-
if (this.fetchIsAvailable && this.lastPause && this.minBackgroundDuration && Date.now() - this.lastPause > this.minBackgroundDuration * 1000) {
704+
if (!this.disabled && this.lastPause && this.minBackgroundDuration && Date.now() - this.lastPause > this.minBackgroundDuration * 1000) {
699705
await (await this.delegate)._handleInitialPreferenceState();
700706
}
701707
}
@@ -714,15 +720,15 @@ class IonicDeploy implements IDeployPluginAPI {
714720

715721
async checkForUpdate(): Promise<CheckDeviceResponse> {
716722
await this.platformReady();
717-
if (this.fetchIsAvailable) {
723+
if (!this.disabled) {
718724
return (await this.delegate).checkForUpdate();
719725
}
720726
return {available: false};
721727
}
722728

723729
async configure(config: IDeployConfig): Promise<void> {
724730
await this.platformReady();
725-
if (this.fetchIsAvailable) return (await this.delegate).configure(config);
731+
if (!this.disabled) return (await this.delegate).configure(config);
726732
}
727733

728734
async getConfiguration(): Promise<ICurrentConfig> {
@@ -746,49 +752,49 @@ class IonicDeploy implements IDeployPluginAPI {
746752

747753
async deleteVersionById(version: string): Promise<boolean> {
748754
await this.platformReady();
749-
if (this.fetchIsAvailable) return (await this.delegate).deleteVersionById(version);
755+
if (!this.disabled) return (await this.delegate).deleteVersionById(version);
750756
return true;
751757
}
752758

753759
async downloadUpdate(progress?: CallbackFunction<number>): Promise<boolean> {
754760
await this.platformReady();
755-
if (this.fetchIsAvailable) return (await this.delegate).downloadUpdate(progress);
761+
if (!this.disabled) return (await this.delegate).downloadUpdate(progress);
756762
return false;
757763
}
758764

759765
async extractUpdate(progress?: CallbackFunction<number>): Promise<boolean> {
760766
await this.platformReady();
761-
if (this.fetchIsAvailable) return (await this.delegate).extractUpdate(progress);
767+
if (!this.disabled) return (await this.delegate).extractUpdate(progress);
762768
return false;
763769
}
764770

765771
async getAvailableVersions(): Promise<ISnapshotInfo[]> {
766772
await this.platformReady();
767-
if (this.fetchIsAvailable) return (await this.delegate).getAvailableVersions();
773+
if (!this.disabled) return (await this.delegate).getAvailableVersions();
768774
return [];
769775
}
770776

771777
async getCurrentVersion(): Promise<ISnapshotInfo | undefined> {
772778
await this.platformReady();
773-
if (this.fetchIsAvailable) return (await this.delegate).getCurrentVersion();
779+
if (!this.disabled) return (await this.delegate).getCurrentVersion();
774780
return;
775781
}
776782

777783
async getVersionById(versionId: string): Promise<ISnapshotInfo> {
778784
await this.platformReady();
779-
if (this.fetchIsAvailable) return (await this.delegate).getVersionById(versionId);
785+
if (!this.disabled) return (await this.delegate).getVersionById(versionId);
780786
throw Error(`No update available with versionId ${versionId}`);
781787
}
782788

783789
async reloadApp(): Promise<boolean> {
784790
await this.platformReady();
785-
if (this.fetchIsAvailable) return (await this.delegate).reloadApp();
791+
if (!this.disabled) return (await this.delegate).reloadApp();
786792
return false;
787793
}
788794

789795
async sync(syncOptions: ISyncOptions = {}): Promise<ISnapshotInfo | undefined> {
790796
await this.platformReady();
791-
if (this.fetchIsAvailable) return (await this.delegate).sync(syncOptions);
797+
if (!this.disabled) return (await this.delegate).sync(syncOptions);
792798
return;
793799
}
794800
}

www/guards.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function isPluginConfig(o: object): o is IDeployConfig {
22
const obj = <IDeployConfig>o;
3-
const allowedKeys = ['appId', 'channel', 'debug', 'host', 'maxVersions', 'minBackgroundDuration', 'updateMethod'];
3+
const allowedKeys = ['appId', 'channel', 'disabled', 'host', 'maxVersions', 'minBackgroundDuration', 'updateMethod'];
44
if (!obj) return false;
55
for (const key in obj) {
66
if (allowedKeys.indexOf(key) === -1) {

0 commit comments

Comments
 (0)