Skip to content

Commit

Permalink
Fix Safari iOS 16 compatibility and deprecate application cache manif…
Browse files Browse the repository at this point in the history
…est (#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
  • Loading branch information
TatuLund authored Oct 7, 2022
1 parent 3841988 commit 7331dd3
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 125 deletions.
4 changes: 2 additions & 2 deletions vaadin-touchkit-agpl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
<!-- May be overridden by the build system -->
<license.short.name>agpl</license.short.name>
<license.version>3.0</license.version>
<vaadin.version.maven>[7.6.0.beta1,7.99.9999]</vaadin.version.maven>
<vaadin.plugin.version>7.7.26</vaadin.plugin.version>
<vaadin.version.maven>7.7.28</vaadin.version.maven>
<vaadin.plugin.version>7.7.28</vaadin.plugin.version>
<gpg.passphrase.file>empty.properties</gpg.passphrase.file>
<gpg.skip>true</gpg.skip>
<snapshot.repository.url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</snapshot.repository.url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import java.lang.annotation.Target;

/**
* Disables o enable the manifest cache.
* This annotation is no longer needed as service worker and local storage is
* being used by Safari, Chrome and Firefox for now on.
*/
@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface CacheManifestEnabled {
boolean value() default true;
boolean value() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class CacheManifestStatusIndicator implements EntryPoint {
// TODO(manolo): should be configurable via offline connector
private int updateCheckInterval = 1800000;

private static final Logger logger = Logger.getLogger(CacheManifestStatusIndicator.class.getName());
private static final Logger logger = Logger
.getLogger(CacheManifestStatusIndicator.class.getName());

private static boolean confirmationRequired = true;

Expand All @@ -48,8 +49,8 @@ public void onModuleLoad() {
}

/**
* Let the indicator ask the user to reload the application
* when a new version of the app has been downloaded.
* Let the indicator ask the user to reload the application when a new
* version of the app has been downloaded.
*/
public static void setConfirmationRequired(boolean b) {
confirmationRequired = b;
Expand All @@ -59,15 +60,15 @@ public static void setConfirmationRequired(boolean b) {
* return true if we are downloading a new version of the app.
*/
public static boolean isUpdating() {
return updating || getStatus() == CHECKING || getStatus() == DOWNLOADING;
return updating || getStatus() == CHECKING
|| getStatus() == DOWNLOADING;
}

/**
* Initializes and starts the monitoring.
*/
public void init() {
loadSettingsFromLocalStorage();
hookAllListeners(this);
scheduleUpdateChecker();
if (getStatus() == CHECKING || getStatus() == DOWNLOADING) {
showProgress();
Expand All @@ -79,8 +80,8 @@ public void init() {

private void pollForStatusOnAndroid() {
if (BrowserInfo.get().isAndroid()) {
Scheduler.get().scheduleFixedPeriod(
new Scheduler.RepeatingCommand() {
Scheduler.get()
.scheduleFixedPeriod(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
if (updating) {
Expand Down Expand Up @@ -121,7 +122,8 @@ private void loadSettingsFromLocalStorage() {
&& !updateCheckIntervalStr.isEmpty()) {
// The value in local storage is in seconds, but we need
// milliseconds.
updateCheckInterval = Integer.valueOf(updateCheckIntervalStr) * 1000;
updateCheckInterval = Integer.valueOf(updateCheckIntervalStr)
* 1000;
}
}
}
Expand All @@ -135,9 +137,8 @@ private void scheduleUpdateChecker() {
public boolean execute() {
// Don't try to update cache if already updating or app is
// paused
if (!isUpdating()
&& OfflineModeEntrypoint.get().getNetworkStatus()
.isAppRunning()) {
if (!isUpdating() && OfflineModeEntrypoint.get()
.getNetworkStatus().isAppRunning()) {
updateCache();
}
return true;
Expand Down Expand Up @@ -210,7 +211,8 @@ protected void hideProgress() {
* true to force reloading the site without asking the user.
*/
private void requestUpdate() {
logger.info("Application cache updated, confirmationRequired=" + confirmationRequired);
logger.info("Application cache updated, confirmationRequired="
+ confirmationRequired);
if (!confirmationRequired || Window.confirm(updateNowMessage)) {
Window.Location.reload();
}
Expand All @@ -219,48 +221,28 @@ private void requestUpdate() {
/**
* Hooks all listeners to the specified instance.
*
* @deprecated This is NOP as Safari, Chrome and Firefox do not need this
* anymore.
*
* @param instance
* the instance to hook the listeners to.
*/
@Deprecated
protected final native void hookAllListeners(
CacheManifestStatusIndicator instance)
/*-{
$wnd.applicationCache.addEventListener('cached',
function(event) {
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
}, false);
$wnd.applicationCache.addEventListener('checking',
function(event) {
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
}, false);
$wnd.applicationCache.addEventListener('downloading',
function(event) {
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
}, false);
$wnd.applicationCache.addEventListener('noupdate',
function(event) {
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
}, false);
$wnd.applicationCache.addEventListener('updateready',
function(event) {
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onCacheEvent(Lcom/google/gwt/user/client/Event;)(event);
}, false);
$wnd.applicationCache.addEventListener('error',
function(event) {
instance.@com.vaadin.addon.touchkit.gwt.client.offlinemode.CacheManifestStatusIndicator::onError(Lcom/google/gwt/user/client/Event;)(event);
}, false);
}-*/;

/**
* @return The status of the application cache. See the constants in this
* class for possible values. Return 99 if application cache does
* class for possible values. Return 99 if application cache does
* not exist.
*/
private static native int getStatus()
/*-{
if($wnd.applicationCache) {
if($wnd.applicationCache) {
return $wnd.applicationCache.status;
}
}
return 99;
}-*/;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@SuppressWarnings("serial")
public class ApplicationCacheSettings implements BootstrapListener {

private boolean cacheManifestEnabled = true;
private boolean cacheManifestEnabled = false;
private boolean offlineModeEnabled = true;

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

final VaadinService service = response.getSession().getService();
final VaadinRequest request = response.getRequest();
final String staticFilePath = service
.getStaticFileLocation(request);
final String staticFilePath = service.getStaticFileLocation(request);
// VAADIN folder location
final String vaadinDir = staticFilePath + "/VAADIN/";
// Figure out widgetset
final UICreateEvent event = new UICreateEvent(request,
response.getUiClass());
String widgetset = response.getUIProvider().getWidgetset(event);
if (widgetset == null) {
widgetset = request.getService()
.getConfiguredWidgetset(request);
widgetset = request.getService().getConfiguredWidgetset(request);
}
// Url for the widgetset
final String widgetsetUrl = String.format(
Expand All @@ -67,8 +65,7 @@ public void modifyBootstrapPage(BootstrapPageResponse response) {

if (isCacheManifestEnabled()) {
// Add cache manifest attribute to html tag
document.getElementsByTag("html").attr(
"manifest",
document.getElementsByTag("html").attr("manifest",
vaadinDir + "widgetsets/" + widgetset + "/"
+ generateManifestFileName(response));
}
Expand Down Expand Up @@ -113,21 +110,28 @@ protected String generateManifestFileName(BootstrapPageResponse response) {
}

/**
* @deprecated Safari, Chrome and Firefox use serviceworkerd and
* localstorage, so this is allways false with them.
*
* @return true if the cache manifest (and thus application cache) is
* enabled.
*/
@Deprecated
public boolean isCacheManifestEnabled() {
return cacheManifestEnabled && !TouchKitSettings.supportsGooglePWA();
return false;
}

/**
* Enable or disable the cache manifest (and thus application cache).
*
* @deprecated Safari, Chrome and Firefox use serviceworkerd and
* localstorage, so this is allways false with them.
*
* @param cacheManifestEnabled
* true to enable.
*/
@Deprecated
public void setCacheManifestEnabled(boolean cacheManifestEnabled) {
this.cacheManifestEnabled = cacheManifestEnabled;
}

/**
Expand All @@ -152,8 +156,8 @@ public void setOfflineModeEnabled(boolean offlineModeEnabled) {
* cache (== new version of the widget set).
*
* @param message
* The new message. The default is
* "There are updates ready to be installed. Would you like to restart now?"
* The new message. The default is "There are updates ready to be
* installed. Would you like to restart now?"
*/
public void setUpdateNowMessage(String message) {
LocalStorage.get().put(CacheManifestStatusIndicator.UPDATE_NOW_MSG_KEY,
Expand Down
Loading

0 comments on commit 7331dd3

Please sign in to comment.