-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flow initial pwa #4334
Merged
Merged
Flow initial pwa #4334
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
74ccbf0
Adds automatic PWA -initialization for all Flow-projects.
mikotin 110a643
Renamed Manifest to PWA.
mikotin b03bdb0
Added missing type from icons
mikotin 1953c59
Added missing href setting
mikotin 3538cbf
Changed pwa handlers to a single handler with pre-calculated responses.
mikotin 8908c3b
Fixed icon inject for offline page.
mikotin fc2a561
Updated pwa properties to better support add to home screen -function…
mikotin f52538a
Cleared up the code and added comments.
mikotin 5b0b1cc
Added support for custom offline resources.
mikotin 10c19f1
Added missing documentation, moved PWARegistry to server -package.
mikotin 97d580c
Added required docs and fixed minor issues reported by bot.
mikotin efeb58e
Added meta tags for better PWA support.
mikotin e19249a
Fixed commented issues.
mikotin b942b51
Fixed comments.
mikotin 45f9931
Fixed comments.
mikotin 96451c3
Refactored Icon class and added missing copyright headers.
mikotin 11454ad
Moved PWA scanning to route registry initializer.
mikotin 3c4a794
Fixed reported issues
mikotin e0ab2da
Changed general exception to a named exception.
mikotin 067fb12
Removed unused import.
mikotin 2185806
Replaced repeated strings with constants.
mikotin a5ab9fe
Minor code style change. Added tesource stream close handling.
mikotin c8b77e2
Changed resource reading as informed by bot.
mikotin a73ebe4
Added missing copyright header.
mikotin 9a44794
Added tests for PWA annotation.
mikotin f7ad12c
Changed default logo for pwa
mikotin d5d926f
Default display changed to standalone and updated default resources.
mikotin ec3e500
Fixed theme-color meta tag.
mikotin eb57b39
Fixed pwa meta tags and tests for those.
mikotin 3a74bd5
Changed the copyright year to 2018. (Came back to the future)
mikotin d8adc3f
Changed the copyright year and added constant for repeated string.
mikotin ca2d2f4
Merge branch 'master' into flow-initial-pwa
6c4b20a
Styling fixes. (#4365)
SomeoneToIgnore 15a789f
Remove unneeded CSS property.
663cd54
Added local serving of needed Workbox -files.
mikotin c71e058
Merge branch 'flow-initial-pwa' of ssh://github.com/vaadin/flow into …
mikotin 682c3ad
Removed enabled from PWA annotation.
mikotin 0d67035
Cleared silly issues that were left in the code.
mikotin efb7050
Moved fixed value out of if clause.
mikotin b2bd0cd
Replaced getCurrent() with proper way.
mikotin 3612a12
Added synchronized for to lazy initializator.
mikotin 38c0460
Removed unused import.
mikotin e1fe75d
Changed private field to AtomitRefence.
mikotin b4c69d0
Updated version.
mikotin ff85742
Fixed constant.
mikotin 34eeaa7
Merge branch 'master' into flow-initial-pwa
6af74cd
Fix sonar issues.
4da44a9
Code review fixes.
689730a
Fix NPE.
a55390a
Replace string concatenation with append.
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
flow-server/src/main/java/com/vaadin/flow/server/PWA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright 2000-2018 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.server; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Defines application PWA properties. | ||
* | ||
* Annotation activates automatic | ||
* <a href="https://developer.mozilla.org/en-US/Apps/Progressive">PWA</a> | ||
* injecting. | ||
* <p> | ||
* Only one annotation for application is supported. Annotation must be placed | ||
* to master layout. | ||
* | ||
* Application annotated the annotation will add following capabilities to Flow | ||
* application: | ||
* | ||
* <ul> | ||
* <li>handle manifest.json | ||
* <li>handle sw.js (service worker), which will enable simple offline fallback | ||
* and file caching | ||
* <li>handle default (static) offline html page | ||
* <li>handle different versions (sizes) of the given logo | ||
* <li>inject needed tags to the app's page header | ||
* </ul> | ||
* | ||
* Any of the handled resources can be explicitly overridden with static file in | ||
* public resources. For example, if {@literal manifest.json} is available in | ||
* webapp root folder it will be served instead of generated | ||
* {@literal manifest.json}. Same applies for service worker and generated | ||
* icons. | ||
* | ||
* @see <a href= | ||
* "https://developer.mozilla.org/en-US/Apps/Progressive">https://developer.mozilla.org/en-US/Apps/Progressive</a> | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface PWA { | ||
|
||
/** | ||
* Path to the static offline html file. | ||
* | ||
* Defaults to (relative) {@literal offline.html} with default configuration | ||
* that is {@literal webapp/offline.html} | ||
* | ||
* If offline file is not found, falls back to default offline page. | ||
* | ||
* @return path to the static offline html file | ||
*/ | ||
String offlinePath() default PwaConfiguration.DEFAULT_OFFLINE_PATH; | ||
|
||
/** | ||
* Path to the manifest file. | ||
* | ||
* Defaults to (relative) {@literal manifest.json} with default | ||
* configuration that is {@literal webapp/manifest.json} | ||
* | ||
* @return path to the manifest file | ||
*/ | ||
String manifestPath() default PwaConfiguration.DEFAULT_PATH; | ||
|
||
/** | ||
* Path to the application logo file. | ||
* | ||
* Defaults to (relative) {@literal icons/logo.png} with default | ||
* configuration that is {@literal webapp/manifest.json} | ||
* | ||
* If the specified logo file is not found, the default one will be used. | ||
* The file is also used to create different sizes of logo. | ||
* | ||
* @return path to the application logo file | ||
*/ | ||
String logoPath() default PwaConfiguration.DEFAULT_LOGO; | ||
|
||
/** | ||
* Name of the application. | ||
* | ||
* @return name of the application | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* Short name for the application. Maximum of 12 characters. | ||
* | ||
* @return short name for the application | ||
*/ | ||
String shortName(); | ||
|
||
/** | ||
* Description of the application. | ||
* | ||
* @return description of the application | ||
*/ | ||
String description() default ""; | ||
|
||
/** | ||
* Theme color of the application. | ||
* | ||
* The theme color sets the color of the application's tool bar and | ||
* application's color in the task switcher. | ||
* | ||
* @return theme color of the application | ||
*/ | ||
String themeColor() default PwaConfiguration.DEFAULT_THEME_COLOR; | ||
|
||
/** | ||
* Background color of the application. | ||
* | ||
* The background color property is used on the splash screen when the | ||
* application is first launched. | ||
* | ||
* @return Background color of the application | ||
*/ | ||
String backgroundColor() default PwaConfiguration.DEFAULT_BACKGROUND_COLOR; | ||
|
||
/** | ||
* Defines the developers’ preferred display mode for the website. | ||
* | ||
* Possible values: fullscreen, standalone, minimal-ui, browser | ||
* | ||
* @return display mode of application | ||
*/ | ||
String display() default PwaConfiguration.DEFAULT_DISPLAY; | ||
|
||
/** | ||
* Offline resources to be cached using the service worker. | ||
* | ||
* @return offline resources to be cached | ||
*/ | ||
String[] offlineResources() default {}; | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of methods (attributes) in this annotation.
So in the worst case the usage of this annotation will look like
@PWA(offlinePath="abc", manifestPath="foo", logoPath="bar", name="sdfsdf", shortName="cccc",...........................)
Looks inconvenient to me.
I'm not sure exactly how it may be improved.
But may be use
PWA
as an enabler and delegate all the properties to the class like it's done for@Theme
annotation?I would change in this case
PWA
toEnablePWA
and add class or interface which contains all the methods from here (let's say its name isPWAConfig
).Then
EnablePWA
would be:Then there will be an additional responsibility to instantiate the provided class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye, there are quite a lot of those properties. But I like the developer experience of having all that in that annotation: that way adding values and/or checking default values is supported directly with IDE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok