Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Electron Projects
Electron Projects

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

eBook
R$80 R$173.99
Paperback
R$217.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781838552206
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 681.97
The JavaScript Workshop
R$245.99
React Projects
R$217.99
Electron Projects
R$217.99
Total R$ 681.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
(4 Ratings)
5 star 25%
4 star 0%
3 star 50%
2 star 0%
1 star 25%
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
martin Feb 06, 2025
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
problem using the read function. just can control where is reads from
Subscriber review Packt
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 included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.