Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit d7e4973

Browse files
author
Esteban Lopez
committed
Merge pull request #79 from manifoldjs/v0.3.1
Release v0.3.0
2 parents 2c42e4f + f448e4f commit d7e4973

File tree

8 files changed

+56
-21
lines changed

8 files changed

+56
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-hostedwebapp",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "Hosted Web App Plugin",
55
"cordova": {
66
"id": "cordova-plugin-hostedwebapp",

plugin.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
id="cordova-plugin-hostedwebapp"
4-
version="0.2.1">
4+
version="0.3.0">
55
<name>HostedWebApp</name>
66
<description>Hosted Web App Plugin</description>
77
<license>MIT License</license>
@@ -24,9 +24,9 @@
2424
<asset src="www/hostedapp-bridge.js" target="hostedapp-bridge.js" />
2525

2626
<engines>
27-
<engine name="cordova-windows" version="<=4.1.0" />
28-
<engine name="cordova-ios" version="<=3.9.2" />
29-
<engine name="cordova-android" version="<=4.1.1" />
27+
<engine name="cordova-windows" version="<=4.3.9" />
28+
<engine name="cordova-ios" version="<=4.1.9" />
29+
<engine name="cordova-android" version="<=5.1.9" />
3030
</engines>
3131

3232
<!-- android -->

readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,19 @@ To inject scripts into the hosted web content:
147147
The following [wiki article](https://github.com/manifoldjs/ManifoldJS/wiki/Using-Cordova-Plugins-in-Hosted-Web-Apps) provides additional information about these features.
148148
149149
### Offline Feature
150-
The plugin implements a basic offline feature that will show an offline page whenever network connectivity is lost. By default, the page shows a suitable message alerting the user about the loss of connectivity. To customize the offline experience, a page named **offline.html** can be placed in the **www** folder of the application and it will be used instead.
150+
The plugin implements an offline feature that will show an offline page whenever network connectivity is lost.
151+
152+
The feature is enabled by default, but can be disabled with the following property in the manifest.json file.
153+
154+
```
155+
{
156+
...
157+
"mjs_offline_feature": false
158+
...
159+
}
160+
```
161+
162+
By default, the page shows a suitable message informing the user about the loss of connectivity. To customize the offline experience, a page named **offline.html** can be placed in the **www** folder of the application and it will be used instead.
151163
152164
1. To test the offline feature, interrupt the network connection to show the offline page and reconnect it to hide it.
153165

scripts/updateConfigurationBeforePrepare.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,12 @@ module.exports = function (context) {
587587
var manifestPath = path.join(projectRoot, 'manifest.json');
588588
fs.readFile(manifestPath, function (err, data) {
589589
if (err) {
590-
logger.error('Failed to read manifest at \'' + manifestPath + '\'.');
591-
return task.reject(err);
590+
logger.warn('Failed to read manifest at \'' + manifestPath + '\'. Proceeding to point config.xml to sample url of https://www.npmjs.com/package/cordova-plugin-hostedwebapp.');
591+
data = JSON.stringify({ 'start_url': 'https://www.npmjs.com/package/cordova-plugin-hostedwebapp', 'short_name' : 'PlaceholderSite'});
592592
}
593593

594594
var manifestJson = data.toString().replace(/^\uFEFF/, '');
595+
595596
var appManifestPath = path.join(projectRoot, 'www', 'manifest.json');
596597
fs.writeFile(appManifestPath, manifestJson, function (err) {
597598
if (err) {

src/android/HostedWebApp.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class HostedWebApp extends CordovaPlugin {
4747

4848
private LinearLayout rootLayout;
4949
private WebView offlineWebView;
50-
private boolean offlineOverlayEnabled;
50+
private boolean offlineOverlayEnabled = true;
5151

5252
private boolean isConnectionError = false;
5353

@@ -69,6 +69,11 @@ public void pluginInitialize() {
6969

7070
this.loadingManifest = false;
7171

72+
if (!this.manifestObject.optBoolean("mjs_offline_feature", true)) {
73+
this.offlineOverlayEnabled = false;
74+
// Do not initialize offline overlay
75+
return;
76+
}
7277
// Initialize offline overlay
7378
this.activity.runOnUiThread(new Runnable() {
7479
@Override
@@ -547,7 +552,7 @@ public void run() {
547552
evaluateJavaScriptMethod.invoke(webView, scriptToInject, resultCallback);
548553
} catch (Exception e) {
549554
Log.v(LOG_TAG, String.format("WARNING: Webview does not support 'evaluateJavascript' method. Webview type: '%s'", webView.getClass().getName()));
550-
me.webView.getEngine().loadUrl("javascript:" + Uri.encode(scriptToInject), false);
555+
me.webView.getEngine().loadUrl("javascript:" + scriptToInject, false);
551556

552557
if (resultCallback != null) {
553558
resultCallback.onReceiveValue(null);

src/ios/CDVHostedWebApp.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "CDVHostedWebApp.h"
22
#import <Cordova/CDV.h>
3+
#import <Cordova/CDVAvailability.h>
34
#import "CDVConnection.h"
45

56
static NSString* const IOS_PLATFORM = @"ios";
@@ -54,9 +55,6 @@ - (void)pluginInitialize
5455
{
5556
[super pluginInitialize];
5657

57-
// creates the UI to show offline mode
58-
[self createOfflineView];
59-
6058
// observe notifications from network-information plugin to detect when device is offline
6159
[[NSNotificationCenter defaultCenter] addObserver:self
6260
selector:@selector(updateConnectivityStatus:)
@@ -92,8 +90,16 @@ - (void)pluginInitialize
9290

9391
// set the webview delegate to notify navigation events
9492
notificationDelegate = [[CVDWebViewNotificationDelegate alloc] init];
95-
notificationDelegate.wrappedDelegate = self.webView.delegate;
96-
[self.webView setDelegate:notificationDelegate];
93+
notificationDelegate.wrappedDelegate = ((UIWebView*)self.webView).delegate;
94+
[(UIWebView*)self.webView setDelegate:notificationDelegate];
95+
96+
id offlineFeature = [manifest objectForKey:@"mjs_offline_feature"];
97+
if (offlineFeature != nil && [offlineFeature boolValue] == NO) {
98+
self.enableOfflineSupport = NO;
99+
} else {
100+
// creates the UI to show offline mode
101+
[self createOfflineView];
102+
}
97103
}
98104

99105
// loads the specified W3C manifest
@@ -216,7 +222,7 @@ -(BOOL) injectScripts:(NSArray *)scriptList {
216222
}
217223
}
218224

219-
return[self.webView stringByEvaluatingJavaScriptFromString:content] != nil;
225+
return[(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:content] != nil;
220226
}
221227

222228
- (BOOL) isCordovaEnabled
@@ -299,7 +305,7 @@ -(BOOL) isMatchingRuleForPage:(NSDictionary*) rule withPlatformCheck: (BOOL) che
299305
if (match != nil)
300306
{
301307
CDVWhitelist *whitelist = [[CDVWhitelist alloc] initWithArray:match];
302-
NSURL* url = self.webView.request.URL;
308+
NSURL* url = ((UIWebView*)self.webView).request.URL;
303309
isURLMatch = [whitelist URLIsAllowed:url];
304310
}
305311
}
@@ -356,7 +362,7 @@ - (void)updateConnectivityStatus:(NSNotification*)notification
356362
}
357363
else {
358364
if (self.failedURL) {
359-
[self.webView loadRequest: [NSURLRequest requestWithURL: self.failedURL]];
365+
[(UIWebView*)self.webView loadRequest: [NSURLRequest requestWithURL: self.failedURL]];
360366
}
361367
else {
362368
[self.offlineView setHidden:YES];
@@ -412,7 +418,7 @@ - (void)webViewDidFinishLoad:(NSNotification*)notification
412418
}
413419

414420
NSString* javascript = [NSString stringWithFormat:@"window.hostedWebApp = { 'platform': '%@', 'pluginMode': '%@', 'cordovaBaseUrl': '%@'};", IOS_PLATFORM, pluginMode, cordovaBaseUrl];
415-
[self.webView stringByEvaluatingJavaScriptFromString:javascript];
421+
[(UIWebView*)self.webView stringByEvaluatingJavaScriptFromString:javascript];
416422

417423
NSMutableArray* scripts = [[NSMutableArray alloc] init];
418424
if ([pluginMode isEqualToString:@"client"])
@@ -468,6 +474,7 @@ - (void)didWebViewFailLoadWithError:(NSNotification*)notification
468474
}
469475
}
470476

477+
#ifndef __CORDOVA_4_0_0
471478
- (BOOL) shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
472479
{
473480
NSURL* url = [request URL];
@@ -483,6 +490,7 @@ - (BOOL) shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UI
483490

484491
return NO;
485492
}
493+
#endif
486494

487495
-(BOOL) shouldAllowNavigation:(NSURL*) url
488496
{

src/windows/HostedWebAppPluginProxy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ cordova.commandProxy.add('HostedWebApp', module.exports);
438438

439439
module.exports.loadManifest(
440440
function (manifest) {
441-
configureOfflineSupport('offline.html');
441+
if (manifest.mjs_offline_feature === false) {
442+
_enableOfflineSupport = false;
443+
} else {
444+
configureOfflineSupport('offline.html');
445+
}
442446
configureWhiteList(manifest);
443447
_mainView = configureHost(manifest ? manifest.start_url : 'about:blank', _zIndex);
444448
_mainView.addEventListener("MSWebViewDOMContentLoaded", domContentLoadedEvent, false);

www/hostedapp-bridge.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@
4040
}
4141

4242
// change bridge mode in iOS to avoid Content Security Policy (CSP) issues with 'gap://' frame origin
43+
// Note that all bridge modes except IFRAME_NAV were dropped starting from [email protected] (see
44+
// https://issues.apache.org/jira/browse/CB-9883), so plugins will *not* work correctly in pages that
45+
// restrict the gap:// origin
4346
if (platform === 'ios') {
4447
var exec = cordova.require('cordova/exec');
45-
exec.setJsToNativeBridgeMode(exec.jsToNativeModes.XHR_OPTIONAL_PAYLOAD);
48+
if (exec.setJsToNativeBridgeMode && exec.jsToNativeModes && exec.jsToNativeModes.XHR_OPTIONAL_PAYLOAD) {
49+
exec.setJsToNativeBridgeMode(exec.jsToNativeModes.XHR_OPTIONAL_PAYLOAD);
50+
}
4651
}
4752

4853
// override plugin loader to handle script injection

0 commit comments

Comments
 (0)