Table of Contents
Electron operating principle
1. Chromium
2. Node.js
In order to provide
Because
Home Web Front-end Front-end Q&A Can javascript write desktop programs?

Can javascript write desktop programs?

Mar 28, 2022 pm 05:08 PM
javascript

Javascript can write desktop programs. In JavaScript, you can use the Electron software framework to develop desktop programs; Electron is an open source library for building cross-platform desktop applications. It provides a rich local API that enables developers to create desktop applications using pure JS.

Can javascript write desktop programs?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

What is a desktop application

Can javascript write desktop programs?

##Desktop application, also known as GUI program (Graphical User Interface), but there are some differences from GUI programs. Desktop applications transform GUI programs from GUI to "desktop", making the cold concept of a computer like a piece of wood more humane, more vivid and dynamic.

So can javascript write desktop programs?

javascript can write desktop programs. The world of JavaScript is getting more and more powerful, and you can use frameworks like Eletron to easily develop desktop applications.

Electron is a cross-platform javascript desktop development library.

Electron is an open source library developed by Github that uses HTML, CSS and JavaScript to build cross-platform desktop applications. Electron does this by merging Chromium and Node.js into the same runtime environment and packaging them as apps for Mac, Windows, and Linux systems.

Electron provides a rich native (operating system) API that enables you to create desktop applications using pure JavaScript. Unlike various other Node.js runtimes, Electron focuses on desktop applications rather than web servers.

Electron allows you to use pure JavaScript to call rich native APIs to create desktop applications. You can think of it as a variant of io.js focused on desktop applications rather than web servers.

Reason for using Electron for development:

  • Using Web technology with a strong ecology for development, the development cost is low, Strong scalability, cooler UI

  • Cross-platform, one set of code can be packaged into three sets of software for Windows, Linux, and Mac, and the compilation is fast

  • Can be directly extended on existing web applications to provide capabilities that browsers do not have

  • You are a front-end

Of course, we must also recognize its shortcomings: performance is lower than native desktop applications, and the final packaged application is much larger than native applications.

Development experience

Compatibility

Although you are still developing using WEB technology, But you no longer need to consider compatibility issues. You only need to care about the version of Chrome you are currently using. Generally speaking, it is new enough to allow you to use the latest API and syntax. You can also manually upgrade the Chrome version. . Likewise, you don’t have to worry about style and code compatibility issues with different browsers.

Node environment

This may be a feature that many front-end developers have dreamed of. Using the powerful API provided by Node.js in the WEB interface means that you You can directly operate files, call system APIs, and even operate databases on the WEB page. Of course, in addition to the full Node API, you can also use hundreds of thousands of additional npm modules.

Cross-domain

You can directly use the request module provided by Node to make network requests, which means you no longer need to be troubled by cross-domain.

Powerful scalability

Use node-ffi to provide powerful scalability for applications (will be introduced in detail in later chapters).

Who is using Electron

Can javascript write desktop programs?

There are already many applications on the market using it

Electron has been developed, including the familiar VS Code client, GitHub client, Atom client, etc. I was very impressed by Xunlei’s copywriting when it released Xunlei X10.1 last year:

Starting from Xunlei Thunder X using the new framework can perfectly support high-definition displays such as 2K and 4K, and the text rendering in the interface is also clearer and sharper. From a technical perspective, the new framework is more flexible and efficient than the old framework in terms of interface drawing and event processing, so the smoothness of the interface is also significantly better than that of the old framework Thunder. As for the specific improvement? You'll know once you try it.

You can open

VS Code and click [Help] [Switch Developer Tools] to debug the VS Code client interface.

Can javascript write desktop programs?

Electron operating principle

Can javascript write desktop programs?

Electron combines Chromium, Node.js and API that calls the operating system's native functions.

1. Chromium

Chromium is an open source project launched by Google to develop the Chrome browser, Chromium is equivalent to the engineering version or experimental version of Chrome. New features will be implemented first on Chromium and will be applied to Chrome after verification. Therefore, the functions of Chrome will be relatively backward but more stable.

Chromium provides Electron with powerful UI capabilities, allowing you to develop interfaces without considering compatibility.

2. Node.js

Node.js is a development platform that allows JavaScript to run on the server side, Node It uses an event-driven, non-blocking I/O model to be lightweight and efficient.

Chromium

alone cannot have the ability to directly operate the native GUI, Electron integrates Nodejs, this It allows it to develop the interface while also having the ability to have the underlying API of the operating system. The Path, fs, Crypto and other modules commonly used in Nodejs are in Electron can be used directly. 3. System API

In order to provide

GUI

support for the native system, Electron has a built-in native application program interface for calling some system functions. Provide support for calling system notifications and opening system folders. In development mode,

Electron

is developed separately from the calling system API and the drawing interface. Let’s take a look at Electron About How processes are divided. 4. Main process

Electron

distinguishes two processes: the main process and the rendering process, each of which is responsible for its own functions.

Can javascript write desktop programs?

Electron

The process that runs the main script of package.json is called the main process. An Electron application always has one and only one main process.

Responsibility:

Create rendering process (can be multiple)
  • Control the application life cycle (start, exit
  • APP
  • And do some event monitoring for APP)Call the underlying functions of the system and call native resources
Callable API:

    Node.js API
  • The main process
  • API provided by Electron (including some system functions and ElectronAdditional functions)
  • 5. Rendering process

Because

Electron

uses Chromium to displayweb page, so the multi-process architecture of Chromium is also used. Each web page in Electron runs in its own rendering process.

The main process uses a BrowserWindow instance to create the page. Each BrowserWindow instance runs the page in its own rendering process. When a BrowserWindow instance is destroyed, the corresponding rendering process will also be terminated.

You can think of the rendering process as a browser window. It can exist multiple and independent of each other, but unlike a browser, it can call
Node API

.

Responsibility:

Render the interface using
    HTML
  • and CSSUse
  • JavaScript
  • Do some interface interaction
Callable API:

    DOM API
  • Node.js API
  • Electron
  • Rendering process providedAPI
  • [Related recommendations:
javascript video tutorial

web front-end

The above is the detailed content of Can javascript write desktop programs?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

How to use insertBefore in javascript How to use insertBefore in javascript Nov 24, 2023 am 11:56 AM

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

See all articles