Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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 eBook?

Product feature icon Instant access to your Digital eBook purchase
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

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 : 9781838553104
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
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

Product Details

Publication date : Nov 29, 2019
Length: 436 pages
Edition : 1st
Language : English
ISBN-13 : 9781838553104
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%
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
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
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.