Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Electron Projects
Electron Projects

Electron Projects: Build over 9 cross-platform desktop applications from scratch

eBook
€15.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Electron Projects

Building a Markdown Editor

In this chapter, we are going to build a minimal Markdown Editor application. This mini exercise is going to help you get an idea of how to build a web application that integrates with the Electron shell on desktops.

You are about to walk through the process of integrating a third-party editor component, learning how to support application menus, and establishing communication channels between the rendering (browser) and the main (Node.js) processes. We are doing this so that you become confident with Electron and can build more complex projects.

As part of this chapter, we will also create a new GitHub repository to store application releases, publish multiple versions of the Markdown Editor to GitHub, configure automatic updates, and see them in action.

In this chapter, we will cover the following topics:

  • Configuring a new project
  • Integrating the...

Technical requirements

To get started with this chapter, you will need a standard laptop or desktop running macOS, Windows, or Linux.

The software that you need to have installed for this chapter is as follows:

  • Git, a version control system
  • Node.js with node package manager (NPM)
  • Visual Studio Code, a free and open-source code editor

You can find the code files for this chapter in this book's GitHub repository: https://github.com/PacktPublishing/Electron-Projects/tree/master/Chapter02.

Configuring a new project

Let's start our journey by configuring a new Electron project and naming it markdown-editor since we are building a markdown editor application. You can create a corresponding folder with the following commands:

mkdir markdown-editor
cd markdown-editor

As you may recall from Chapter 1, Building Your First Electron Application, we need to initialize a new project with the npm init command. You should also install electron, the core library that provides an application shell. In addition, your project needs an electron-builder library, which allows you to publish and distribute features for multiple platforms. Let's get started:

  1. Run the following commands to set up a new project:
      npm init -y
npm i -D electron
npm i -D electron-builder

The npm init command should generate a package.json file with the following content:

      {
...

Integrating the editor component

For our project, we don't need to build everything from scratch, including the components that edit and format text in markdown format. There are lots of free, open source components you can use to save time and focus on building the application and delivering value to your users, rather than spending months reinventing the wheel.

For the sake of simplicity, we are going to use the SimpleMDE component, which stands for Simple Markdown Editor. You can find more details about the project on its home page: https://simplemde.com/. The project is open source and has an MIT license. Follow these steps to incorporate the component:

  1. Similarly to how we installed the Electron framework itself, you can use NPM commands to get SimpleMDE into your project:
      npm install simplemde
Don't forget to stop the application before installing a new...

Fitting the screen size

If you keep experimenting with your application at runtime, you may notice that the editor component doesn't fit the whole application area once you start resizing the window or maximizing it. To address this, we need to add some CSS styles to tell the component it needs to fit the parent width and height.

Please note that, at the lower level, SimpleMDE wraps another great component called CodeMirror.

CodeMirror is a versatile text editor that's implemented in JavaScript for the browser. It is specialized for editing code and comes with a number of language modes and addons that implement more advanced editing functionality.

Here, we are going to add flex layout features to the whole body of the HTML base and add some styling support for the CodeMirror part, which is part of SimpleMDE. Let's get started:

  1. Update the styles in the index.html...

Integrating the application menu

As you already know, your application is essentially an HTML5 stack running inside Chromium, and Electron provides all necessary integration with the underlying operating system, whether that's macOS, Windows, or Linux.

The concept of application menus is slightly different across platforms. macOS, for instance, provides a single application menu that reflects the active application and displays the corresponding menu items. The Windows system tends to provide a separate menu for each instance of the application window. Finally, Linux systems usually vary based on the window manager's implementations.

Handling every case would be quite cumbersome for developers; that is why the Electron framework provides a unified interface for building application menus from the JSON definition and takes care of integration details.

Let's take...

Adding drag and drop support

Another nice feature you can provide for your small markdown editor application is the ability to drag and drop files onto the window. Users of your application should have the ability to drop a markdown file onto the editor's surface and have the content of the file immediately available to them. This scenario also helps us address some extra features of the Electron framework that you may use later. Let's get started:

  1. The easiest way to enable drop support for an entire web page running in Electron is to set the ondrop event handler for the body element:
      <body ondrop="dropHandler(event);">
<!-- page content -->
</body>
  1. For now, the drop handler implementation can be as simple as putting a message into the browser console's output. The most important part here is to prevent the default...

Supporting automatic updates

The electron-builder project that we are using with our Electron application also provides support for automatic updates. In this section, we will learn how to set up a GitHub repository so that we can store and distribute application updates.

Our Markdown Editor application is going to check for new versions on each start-up and notify users if a new version is available. Let's set up automatic updates for Electron applications:

  1. First, let's create a new GitHub repository and call it electron-updates. Initialize it with the README file to save time cloning and setting up the initial content:
Please select Public mode for the new GitHub repository. This is going to simplify the entire configuration and update process significantly.
It is possible to use private GitHub repositories too. However, private updates require authentication tokens...

Changing the title of the application

Throughout the whole process of application development, you may have noticed that our window is called Document, as shown in the following screenshot:

This is not an issue with the Electron framework; the title of the page comes from the <title> tag inside the index.html file:

Change the value of the title to something more meaningful, for example, My Markdown Application, and restart the application. You should see the new title, as follows:

Feel free to provide a different value for the name. Usually, it is the same value you are going to have in the package.json file, inside the name property.

Summary

In this chapter, we have successfully created a minimalistic markdown editor. We have walked through the process of integrating third-party editor components, wiring keyboard combinations, and performing messaging between the browser and Node.js parts of the Electron application. You should now have a better understanding of application deployments and automatic updates, as well as simple release management via the GitHub repository.

Then, you learned how to build a basic desktop application with system menu integration and access to the local filesystem. This is essentially the bare bones of a typical Electron project you are going to work on in the future. However, the Electron framework provides you with a wrapper around your web application. You still need to decide whether to use plain JavaScript, HTML, and CSS or employ an existing web framework to move faster. This...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Use your web development skills with JavaScript and Node.js to build desktop applications for macOS and Windows
  • Develop desktop versions of popular mobile applications that are similar to Slack, Spotify, and more
  • Design desktop apps with automatic updates and real-time analytics capabilities

Description

The Electron framework allows you to use modern web technologies to build applications that share the same code across all operating systems and platforms. This also helps designers to easily transition from the web to the desktop. Electron Projects guides you through building cross-platform Electron apps with modern web technologies and JavaScript frameworks such as Angular, React.js, and Vue.js. You’ll explore the process of configuring modern JavaScript frameworks and UI libraries, real-time analytics and automatic updates, and interactions with the operating system. You’ll get hands-on with building a basic Electron app, before moving on to implement a Markdown Editor. In addition to this, you’ll be able to experiment with major JavaScript frameworks such as Angular and Vue.js, discovering ways to integrate them with Electron apps for building cross-platform desktop apps. Later, you’ll learn to build a screenshot snipping tool, a mini-game, and a music player, while also gaining insights into analytics, bug tracking, and licensing. You’ll then get to grips with building a chat app, an eBook generator and finally a simple digital wallet app. By the end of this book, you’ll have experience in building a variety of projects and project templates that will help you to apply your knowledge when creating your own cross-platform applications.

Who is this book for?

This book is for JavaScript developers who want to explore the Electron framework for building desktop apps. Working knowledge of modern frontend JavaScript frameworks and Node.js is assumed. No prior knowledge of desktop development is required.

What you will learn

  • Initialize Node.js, Node Package Manager (NPM), and JavaScript to set up your app
  • Integrate Phaser with Electron to build a simple 2D game
  • Improve app quality by adding an error tracking system and crash reports
  • Implement group chat features and event handling capabilities using Firebase
  • Integrate a WordPress-like rich-text editor into your app
  • Build Electron applications using a single codebase
Estimated delivery fee Deliver to Germany

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 29, 2019
Length: 436 pages
Edition : 1st
Language : English
ISBN-13 : 9781838552206
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Estimated delivery fee Deliver to Germany

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Publication date : Nov 29, 2019
Length: 436 pages
Edition : 1st
Language : English
ISBN-13 : 9781838552206
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 91.97
Electron Projects
€28.99
React Projects
€29.99
The JavaScript Workshop
€32.99
Total 91.97 Stars icon

Table of Contents

11 Chapters
Building Your First Electron Application Chevron down icon Chevron up icon
Building a Markdown Editor Chevron down icon Chevron up icon
Integrating with Angular, React, and Vue Chevron down icon Chevron up icon
Building a Screenshot Snipping Tool Chevron down icon Chevron up icon
Making a 2D Game Chevron down icon Chevron up icon
Building a Music Player Chevron down icon Chevron up icon
Analytics, Bug Tracking, and Licensing Chevron down icon Chevron up icon
Building a Group Chat Application with Firebase Chevron down icon Chevron up icon
Building an eBook Editor and Generator Chevron down icon Chevron up icon
Building a Digital Wallet for Desktops Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(3 Ratings)
5 star 33.3%
4 star 0%
3 star 33.3%
2 star 0%
1 star 33.3%
Derrekito Apr 01, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book walks the reader through creating multiple Electron Projects with the integration of modern frameworks such as React and Vue. It has example projects like games and even a music player. This is a pragmatic option to get started with software development using the Electron framework. I think it also provides valuable insight into alternative workflows for the experienced developer.
Amazon Verified review Amazon
Lukas Lingmann Sep 22, 2023
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
I bought the book because I wanted to build a cross-platform app that should include some functionality.I find the examples and topics covered in the book interesting and good.Unfortunately, as described in other reviews, most code sections don't work, so you have to look for a solution yourself or just leave it.
Amazon Verified review Amazon
JS May 24, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
This is the 3rd book about Electron that I've purchased by Packt Publishing where the code examples in the book don't work and the code in the book doesn't match the code in the GitHub repository. Packt does a horrible job of proofing their material and I will avoid them at all costs going forward.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela