You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ dependencies {
30
30
31
31
Previously, I’ve already told you about our experience with Vaadin in the blog post: https://vaadin.com/blog/cuba-studio-how-we-use-vaadin-for-our-web-development-tool
32
32
33
-
For me, It is battleproven Java framework that enables us to build complex UI without a single line of HTML and JS. Let’s employ it as a basis for our UI.
33
+
For me, it is battle-proven Java framework that enables us to build complex UI without a single line of HTML and JS. Let’s employ it as a basis for our UI.
34
34
35
35
I will create a simple Vaadin application from scratch. First, we need to add necessary dependencies to build.gradle script, enable `war` and `gretty` plugins:
36
36
```java
@@ -100,7 +100,7 @@ Open http://localhost:8080/app in your favorite web browser. That was easy!
100
100
101
101

102
102
103
-
At the moment we have pretty standard web application, it can be deployed to server or we can give it to Desktop users along with servlet container (Tomcat, for instance) and make them use it from a web browser.
103
+
At the moment we have a pretty standard web application, it can be deployed to server or we can give it to Desktop users along with a servlet container (Tomcat, for instance) and make them use it from a web browser.
I’ve added jetty jars to the project dependencies and replaced `war` and `gretty` plugins with `application` plugin. The only thing left to do is to implement `demo.Launcher` class.
136
136
137
-
That’s quite easy task because the process of Jetty embedding is already described in the official manual: http://www.eclipse.org/jetty/documentation/current/embedding-jetty.html
137
+
That’s quite an easy task because the process of Jetty embedding is already described in the official manual: http://www.eclipse.org/jetty/documentation/current/embedding-jetty.html
138
138
139
139
Thus, our Launcher will look as follows:
140
140
```java
@@ -183,7 +183,7 @@ At this stage, we will create simple electron application without our server sid
183
183
}
184
184
```
185
185
186
-
We will show stub HTML page `src/main/electron/index.html`:
186
+
We will show the stub HTML page `src/main/electron/index.html`:
187
187
188
188
```html
189
189
<h1>
@@ -239,7 +239,7 @@ NPM will download and install electron to your PC. Let’s start it!
239
239
240
240

241
241
242
-
At the moment, we got all the pieces of the puzzle sitting right there on the table. Now all we have to do is put them in the right order.
242
+
At the moment, we've got all the pieces of the puzzle sitting right there on the table. Now all we have to do is put them in the right order.
243
243
244
244
## Bring all together
245
245
@@ -309,11 +309,11 @@ const startUp = function () {
309
309
startUp();
310
310
```
311
311
312
-
Here we use `minimal-request-promise` package to check if an application has started, install it using NPM (we call npm/npx commands from `src/main/electron` directory):
312
+
Here we use the `minimal-request-promise` package to check if an application has started, install it using NPM (we call npm/npx commands from `src/main/electron` directory):
313
313
314
314
> npm install minimal-request-promise
315
315
316
-
In order to stop the Java part we will use `tree-kill` package. Install it:
316
+
In order to stop the Java part, we will use `tree-kill` package. Install it:
317
317
318
318
> npm install tree-kill
319
319
@@ -345,7 +345,7 @@ In fact, any Java application can be started using this approach, you can run yo
345
345
346
346
Well, it seems that this really simple example does work, but how we can employ peripheral devices or communicate with OS?
347
347
348
-
Since we have fullfeatured Java process we can easily write/read local files and use all the features of OS. For instance, let’s print OS info to a local printer.
348
+
Since we have full-featured Java process, we can easily write/read local files and use all the features of OS. For instance, let’s print OS info to a local printer.
349
349
350
350
1) First, we create a text document with OS information
Moreover, there are well-known APIs in Java for calling functions from native libraries, such as JNI or JNA. Thus, there are no restrictions for our application in comparison with web-only apps.
428
428
429
-
Implementation of the offline mode for this application essentially the same as for any Desktop application - cache data locally using an embedded database, e.g. HSQL, route business logic calls to local data in case of unavailable network and voila!
429
+
Implementation of the offline mode for this application essentially the same as for any Desktop application - cache data locally using an embedded database, e.g. HSQL, route business logic calls to local data in case of unavailable network, and voila!
430
430
431
431
The full code of the tutorial is available on GitHub: https://github.com/cuba-labs/java-electron-tutorial
### Use WebSocket for UI to speed up communication and strip useless HTTP headers.
471
471
472
-
Each time our application handles user event it sends and receives HTTP headers. They are almost useless in our application. Besides, it opens/closes HTTP connection between UI and Java part. We can speed up the communication between browser part and Java UI using WebSocket protocol.
472
+
Each time our application handles a user event, it sends and receives HTTP headers. They are almost useless in our application. Besides, it opens/closes HTTP connection between UI and Java part. We can speed up the communication between browser part and Java UI using WebSocket protocol.
473
473
474
474
Add org.eclipse.jetty.websocket:websocket-server dependency to build.gradle:
475
475
@@ -495,15 +495,15 @@ Thanks to Vaadin, that is really easy!
495
495
496
496
Our application still sends all the static resources through Java servlets using network layer. We can make Electron read them from a file system directly!
497
497
498
-
As it is described here: https://github.com/electron/electron/blob/master/docs/api/protocol.md we can register custom protocol handler that will intercept requests to /VAADIN/ static files and read them from disk. Remember to unpack static files from jars on build stage!
498
+
As it is described here: https://github.com/electron/electron/blob/master/docs/api/protocol.md We can register custom protocol handler that will intercept requests to /VAADIN/ static files and read them from disk. Remember to unpack static files from jars on build stage!
### Use Gradle Node.JS plugin com.moowork.node instead of manual Node installation
505
505
506
-
It is much easier to manage Node.js from build script than maintaining separate installation of it on developer machines. See example in: https://github.com/jreznot/electron-java-app/blob/master/build.gradle
506
+
It is much easier to manage Node.js from build script than maintaining separate installation of it on developer machines. See example on: https://github.com/jreznot/electron-java-app/blob/master/build.gradle
0 commit comments