Skip to content

Commit 7331dd3

Browse files
authored
Fix Safari iOS 16 compatibility and deprecate application cache manifest (#446)
* Fix for Vaadin 7.7.28 and new Jsoup version * Chnage Safari to use PWA approach, deprecate and inactive application cache manifest functionality as incompatible with modern browsers * Fix code formatting
1 parent 3841988 commit 7331dd3

File tree

5 files changed

+128
-125
lines changed

5 files changed

+128
-125
lines changed

vaadin-touchkit-agpl/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@
157157
<!-- May be overridden by the build system -->
158158
<license.short.name>agpl</license.short.name>
159159
<license.version>3.0</license.version>
160-
<vaadin.version.maven>[7.6.0.beta1,7.99.9999]</vaadin.version.maven>
161-
<vaadin.plugin.version>7.7.26</vaadin.plugin.version>
160+
<vaadin.version.maven>7.7.28</vaadin.version.maven>
161+
<vaadin.plugin.version>7.7.28</vaadin.plugin.version>
162162
<gpg.passphrase.file>empty.properties</gpg.passphrase.file>
163163
<gpg.skip>true</gpg.skip>
164164
<snapshot.repository.url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</snapshot.repository.url>

vaadin-touchkit-agpl/src/main/java/com/vaadin/addon/touchkit/annotations/CacheManifestEnabled.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import java.lang.annotation.Target;
2323

2424
/**
25-
* Disables o enable the manifest cache.
25+
* This annotation is no longer needed as service worker and local storage is
26+
* being used by Safari, Chrome and Firefox for now on.
2627
*/
28+
@Deprecated
2729
@Retention(RetentionPolicy.RUNTIME)
2830
@Target(ElementType.TYPE)
2931
public @interface CacheManifestEnabled {
30-
boolean value() default true;
32+
boolean value() default true;
3133
}

vaadin-touchkit-agpl/src/main/java/com/vaadin/addon/touchkit/gwt/client/offlinemode/CacheManifestStatusIndicator.java

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public class CacheManifestStatusIndicator implements EntryPoint {
3535
// TODO(manolo): should be configurable via offline connector
3636
private int updateCheckInterval = 1800000;
3737

38-
private static final Logger logger = Logger.getLogger(CacheManifestStatusIndicator.class.getName());
38+
private static final Logger logger = Logger
39+
.getLogger(CacheManifestStatusIndicator.class.getName());
3940

4041
private static boolean confirmationRequired = true;
4142

@@ -48,8 +49,8 @@ public void onModuleLoad() {
4849
}
4950

5051
/**
51-
* Let the indicator ask the user to reload the application
52-
* when a new version of the app has been downloaded.
52+
* Let the indicator ask the user to reload the application when a new
53+
* version of the app has been downloaded.
5354
*/
5455
public static void setConfirmationRequired(boolean b) {
5556
confirmationRequired = b;
@@ -59,15 +60,15 @@ public static void setConfirmationRequired(boolean b) {
5960
* return true if we are downloading a new version of the app.
6061
*/
6162
public static boolean isUpdating() {
62-
return updating || getStatus() == CHECKING || getStatus() == DOWNLOADING;
63+
return updating || getStatus() == CHECKING
64+
|| getStatus() == DOWNLOADING;
6365
}
6466

6567
/**
6668
* Initializes and starts the monitoring.
6769
*/
6870
public void init() {
6971
loadSettingsFromLocalStorage();
70-
hookAllListeners(this);
7172
scheduleUpdateChecker();
7273
if (getStatus() == CHECKING || getStatus() == DOWNLOADING) {
7374
showProgress();
@@ -79,8 +80,8 @@ public void init() {
7980

8081
private void pollForStatusOnAndroid() {
8182
if (BrowserInfo.get().isAndroid()) {
82-
Scheduler.get().scheduleFixedPeriod(
83-
new Scheduler.RepeatingCommand() {
83+
Scheduler.get()
84+
.scheduleFixedPeriod(new Scheduler.RepeatingCommand() {
8485
@Override
8586
public boolean execute() {
8687
if (updating) {
@@ -121,7 +122,8 @@ private void loadSettingsFromLocalStorage() {
121122
&& !updateCheckIntervalStr.isEmpty()) {
122123
// The value in local storage is in seconds, but we need
123124
// milliseconds.
124-
updateCheckInterval = Integer.valueOf(updateCheckIntervalStr) * 1000;
125+
updateCheckInterval = Integer.valueOf(updateCheckIntervalStr)
126+
* 1000;
125127
}
126128
}
127129
}
@@ -135,9 +137,8 @@ private void scheduleUpdateChecker() {
135137
public boolean execute() {
136138
// Don't try to update cache if already updating or app is
137139
// paused
138-
if (!isUpdating()
139-
&& OfflineModeEntrypoint.get().getNetworkStatus()
140-
.isAppRunning()) {
140+
if (!isUpdating() && OfflineModeEntrypoint.get()
141+
.getNetworkStatus().isAppRunning()) {
141142
updateCache();
142143
}
143144
return true;
@@ -210,7 +211,8 @@ protected void hideProgress() {
210211
* true to force reloading the site without asking the user.
211212
*/
212213
private void requestUpdate() {
213-
logger.info("Application cache updated, confirmationRequired=" + confirmationRequired);
214+
logger.info("Application cache updated, confirmationRequired="
215+
+ confirmationRequired);
214216
if (!confirmationRequired || Window.confirm(updateNowMessage)) {
215217
Window.Location.reload();
216218
}
@@ -219,48 +221,28 @@ private void requestUpdate() {
219221
/**
220222
* Hooks all listeners to the specified instance.
221223
*
224+
* @deprecated This is NOP as Safari, Chrome and Firefox do not need this
225+
* anymore.
226+
*
222227
* @param instance
223228
* the instance to hook the listeners to.
224229
*/
230+
@Deprecated
225231
protected final native void hookAllListeners(
226232
CacheManifestStatusIndicator instance)
227233
/*-{
228-
$wnd.applicationCache.addEventListener('cached',
229-
function(event) {
230-
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
231-
}, false);
232-
$wnd.applicationCache.addEventListener('checking',
233-
function(event) {
234-
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
235-
}, false);
236-
$wnd.applicationCache.addEventListener('downloading',
237-
function(event) {
238-
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
239-
}, false);
240-
$wnd.applicationCache.addEventListener('noupdate',
241-
function(event) {
242-
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
243-
}, false);
244-
$wnd.applicationCache.addEventListener('updateready',
245-
function(event) {
246-
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
247-
}, false);
248-
$wnd.applicationCache.addEventListener('error',
249-
function(event) {
250-
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onError(Lcom/google/gwt/user/client/Event;)(event);
251-
}, false);
252234
}-*/;
253235

254236
/**
255237
* @return The status of the application cache. See the constants in this
256-
* class for possible values. Return 99 if application cache does
238+
* class for possible values. Return 99 if application cache does
257239
* not exist.
258240
*/
259241
private static native int getStatus()
260242
/*-{
261-
if($wnd.applicationCache) {
243+
if($wnd.applicationCache) {
262244
return $wnd.applicationCache.status;
263-
}
245+
}
264246
return 99;
265247
}-*/;
266248

vaadin-touchkit-agpl/src/main/java/com/vaadin/addon/touchkit/settings/ApplicationCacheSettings.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@SuppressWarnings("serial")
2121
public class ApplicationCacheSettings implements BootstrapListener {
2222

23-
private boolean cacheManifestEnabled = true;
23+
private boolean cacheManifestEnabled = false;
2424
private boolean offlineModeEnabled = true;
2525

2626
@Override
@@ -38,17 +38,15 @@ public void modifyBootstrapPage(BootstrapPageResponse response) {
3838

3939
final VaadinService service = response.getSession().getService();
4040
final VaadinRequest request = response.getRequest();
41-
final String staticFilePath = service
42-
.getStaticFileLocation(request);
41+
final String staticFilePath = service.getStaticFileLocation(request);
4342
// VAADIN folder location
4443
final String vaadinDir = staticFilePath + "/VAADIN/";
4544
// Figure out widgetset
4645
final UICreateEvent event = new UICreateEvent(request,
4746
response.getUiClass());
4847
String widgetset = response.getUIProvider().getWidgetset(event);
4948
if (widgetset == null) {
50-
widgetset = request.getService()
51-
.getConfiguredWidgetset(request);
49+
widgetset = request.getService().getConfiguredWidgetset(request);
5250
}
5351
// Url for the widgetset
5452
final String widgetsetUrl = String.format(
@@ -67,8 +65,7 @@ public void modifyBootstrapPage(BootstrapPageResponse response) {
6765

6866
if (isCacheManifestEnabled()) {
6967
// Add cache manifest attribute to html tag
70-
document.getElementsByTag("html").attr(
71-
"manifest",
68+
document.getElementsByTag("html").attr("manifest",
7269
vaadinDir + "widgetsets/" + widgetset + "/"
7370
+ generateManifestFileName(response));
7471
}
@@ -113,21 +110,28 @@ protected String generateManifestFileName(BootstrapPageResponse response) {
113110
}
114111

115112
/**
113+
* @deprecated Safari, Chrome and Firefox use serviceworkerd and
114+
* localstorage, so this is allways false with them.
115+
*
116116
* @return true if the cache manifest (and thus application cache) is
117117
* enabled.
118118
*/
119+
@Deprecated
119120
public boolean isCacheManifestEnabled() {
120-
return cacheManifestEnabled && !TouchKitSettings.supportsGooglePWA();
121+
return false;
121122
}
122123

123124
/**
124125
* Enable or disable the cache manifest (and thus application cache).
125126
*
127+
* @deprecated Safari, Chrome and Firefox use serviceworkerd and
128+
* localstorage, so this is allways false with them.
129+
*
126130
* @param cacheManifestEnabled
127131
* true to enable.
128132
*/
133+
@Deprecated
129134
public void setCacheManifestEnabled(boolean cacheManifestEnabled) {
130-
this.cacheManifestEnabled = cacheManifestEnabled;
131135
}
132136

133137
/**
@@ -152,8 +156,8 @@ public void setOfflineModeEnabled(boolean offlineModeEnabled) {
152156
* cache (== new version of the widget set).
153157
*
154158
* @param message
155-
* The new message. The default is
156-
* "There are updates ready to be installed. Would you like to restart now?"
159+
* The new message. The default is "There are updates ready to be
160+
* installed. Would you like to restart now?"
157161
*/
158162
public void setUpdateNowMessage(String message) {
159163
LocalStorage.get().put(CacheManifestStatusIndicator.UPDATE_NOW_MSG_KEY,

0 commit comments

Comments
 (0)