ads
HTML ,CSS AND JAVA.
ads
Can you build desktop applications using HTML, CSS and Javascript?
The answer is yes. 😄
This article primarily focuses on how to build desktop applications using Electron, using web technologies such as HTML, CSS, and Javascript.
Electron
Electron can be used to build desktop apps using HTML, CSS and Javascript. Also, these apps work on multiple platforms such as Windows, Mac, and Linux.
Electron combines Chromium and NodeJS in a single runtime environment. This allows you to run HTML, CSS, and Javascript code as desktop applications.
Electron Forge If you use
Electron directly, you need to set it up manually before building your application. Also, if you use Angular, React, Vue, or any other framework or library, you'll need to manually configure this.
Electron Forge makes the above task easier.
Provides templated applications using Angular, React, Vue, and other frameworks to avoid additional manual setup.
It also provides an easy way to build and package your application. It also provides many other features mentioned in the documentation.
Prerequisites
Make sure NodeJS is installed. You can install it from here.
Install Electron Forge globally using the following command: -desktop-app-electronjs is the name of your application
Execution of the above command will take some time.
Once the execution is finished, start the application with the following command:
cd simple-desktop-app-electronjs
npm start
This will open a window similar to the one shown below:
Existing folder Understanding Structure and Code
Applications have a specific folder structure. Here are some important things about this folder structure.
package.json
This contains information about the application being built, all dependencies required by the application, and some scripts. Some scripts are already preconfigured and new scripts can be added.
The config.forge path contains all configuration specific to ElectronJS. For example, make-targets is used to specify target makefiles for different platforms such as Windows, Mac, and Linux.
And package.json has "main": "src/index.js", indicating that src/index.js is the starting point of the application
src/index.js
package. According to json, index
js is the main script. The process that executes the main script is called the main process. So the main process runs the index.js script.
The main process is used to display GUI elements. This is done by creating a website.
Each web page created runs in a process called the renderer process.
Main Process and Renderer Process
The purpose of the main process is to render web pages using BrowserWindow instances.
The BrowserWindow instance uses a renderer process to run each web page.
Each app has only one main process, but many renderer processes.
It is also possible to communicate between the main and renderer processes. However, this is beyond the scope of this article.
Electron Architecture shows the main and renderer processes. File names may vary.
abc
html will be displayed as the second web page in the above architecture. But in our code there is no second web page.
src/index.html
index.js loads the index.html file into a new BrowserWindow instance.
This basically means that index.js will create a new GUI window and load the index.html web page. The index.html web page runs in its own renderer process.
Code Explained in index.js Most of the code written in
index.js has good comments explaining what it does. Here are some important points to consider in your index
js:
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// Load the app's index.html.
mainWindow.loadURL(`file://${__dirname}/index.html`);
The code snippet above basically creates a BrowserWindow instance and loads index.html into the BrowserWindow.
You can see that the app is heavily used in the code. For example, let's look at the following code snippet:
app.on('ready', createWindow);
-App is used to control the application's event lifecycle.
The above code snippet tells us to load the first window when the application is ready.
Similarly, the app can be used to perform other actions for different events. For example, it can be used to perform actions just before the application exits.
Let's Create a Temperature Conversion Desktop Application
Let's use the same application we used before, with a few modifications, to create a temperature conversion application.
First, let's install bootstrap with this command:
npm install bootstrap --save
Copy the following code into src/index.html:
./node_modules/bootstrap/dist/css/bootstrap.min.css">
Temperature converter
id=" Fahrenheit " onkeyup="FahrenheitToCelcius()">
above code does the following:
Creates a text field with ID Celsius Every time something is typed into this text field, the function celciusToFahrenheit() is called
Creates a text field with ID Fahrenheit every time something is entered in this text field called FahrenheitToCelcius() a new value called
is entered in the Celcius text box, the value of th T extfeld Fahrenheit gives the same temperature in Fahrenheit
If you enter a new value in the Fahrenheit text box, the Celsius text box value will display the same temperature in degrees Celsius,
. There are two functions in renderer.js that perform the temperature conversion.
Create a file named renderer.js in src. Paste the following code:
Can you build desktop applications using HTML, CSS and Javascript?
The answer is yes. 😄
This article primarily focuses on how to build desktop applications using Electron, using web technologies such as HTML, CSS, and Javascript.
Electron
Electron can be used to build desktop apps using HTML, CSS and Javascript. Also, these apps work on multiple platforms such as Windows, Mac, and Linux.
Electron combines Chromium and NodeJS in a single runtime environment. This allows you to run HTML, CSS, and Javascript code as desktop applications.
Electron Forge If you use
Electron directly, you need to set it up manually before building your application. Also, if you use Angular, React, Vue, or any other framework or library, you'll need to manually configure this.
Electron Forge makes the above task easier.
Provides templated applications using Angular, React, Vue, and other frameworks to avoid additional manual setup.
It also provides an easy way to build and package your application. It also provides many other features mentioned in the documentation.
Prerequisites
Make sure NodeJS is installed. You can install it from here.
Install Electron Forge globally using the following command: -desktop-app-electronjs is the name of your application
Execution of the above command will take some time.
Once the execution is finished, start the application with the following command:
cd simple-desktop-app-electronjs
npm start
This will open a window similar to the one shown below:
Existing folder Understanding Structure and Code
Applications have a specific folder structure. Here are some important things about this folder structure.
package.json
This contains information about the application being built, all dependencies required by the application, and some scripts. Some scripts are already preconfigured and new scripts can be added.
The config.forge path contains all configuration specific to ElectronJS. For example, make-targets is used to specify target makefiles for different platforms such as Windows, Mac, and Linux.
And package.json has "main": "src/index.js", indicating that src/index.js is the starting point of the application
src/index.js
package. According to json, index
js is the main script. The process that executes the main script is called the main process. So the main process runs the index.js script.
The main process is used to display GUI elements. This is done by creating a website.
Each web page created runs in a process called the renderer process.
Main Process and Renderer Process
The purpose of the main process is to render web pages using BrowserWindow instances.
The BrowserWindow instance uses a renderer process to run each web page.
Each app has only one main process, but many renderer processes.
It is also possible to communicate between the main and renderer processes. However, this is beyond the scope of this article.
Electron Architecture shows the main and renderer processes. File names may vary.
abc
html will be displayed as the second web page in the above architecture. But in our code there is no second web page.
src/index.html
index.js loads the index.html file into a new BrowserWindow instance.
This basically means that index.js will create a new GUI window and load the index.html web page. The index.html web page runs in its own renderer process.
Code Explained in index.js Most of the code written in
index.js has good comments explaining what it does. Here are some important points to consider in your index
js:
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// Load the app's index.html.
mainWindow.loadURL(`file://${__dirname}/index.html`);
The code snippet above basically creates a BrowserWindow instance and loads index.html into the BrowserWindow.
You can see that the app is heavily used in the code. For example, let's look at the following code snippet:
app.on('ready', createWindow);
-App is used to control the application's event lifecycle.
The above code snippet tells us to load the first window when the application is ready.
Similarly, the app can be used to perform other actions for different events. For example, it can be used to perform actions just before the application exits.
Let's Create a Temperature Conversion Desktop Application
Let's use the same application we used before, with a few modifications, to create a temperature conversion application.
First, let's install bootstrap with this command:
npm install bootstrap --save
Copy the following code into src/index.html:
./node_modules/bootstrap/dist/css/bootstrap.min.css">
Temperature converter
id=" Fahrenheit " onkeyup="FahrenheitToCelcius()">
above code does the following:
Creates a text field with ID Celsius Every time something is typed into this text field, the function celciusToFahrenheit() is called
Creates a text field with ID Fahrenheit every time something is entered in this text field called FahrenheitToCelcius() a new value called
is entered in the Celcius text box, the value of th T extfeld Fahrenheit gives the same temperature in Fahrenheit
If you enter a new value in the Fahrenheit text box, the Celsius text box value will display the same temperature in degrees Celsius,
. There are two functions in renderer.js that perform the temperature conversion.
Create a file named renderer.js in src. Paste the following code:

0 Comments