Coder Social home page Coder Social logo

electron-auto-update's Introduction

Generic Electron Auto Update Example

After struggling with this for few days I decided to write this guide, hopefully it will help someone.

I have to give credit to the guy who wrote made the initial guide. I updated his code to work with electron 10.1.5.

Here is the link to Matt Haggard and his electron-updater-example

This repo contains the bare minimum code to have an auto-updating Electron app using electron-updater.

Getting started

Clone the repo cd into project folder and execute these commands.

nvm install v14
nvm use v14
npm install
npm start

If everything went well, you can continue with this guide.

Code Signing Certificates

  • For macOS, you will need a code-signing certificate. Install Xcode (from the App Store), then follow these instructions to make sure you have a "Mac Developer" certificate. If you'd like to export the certificate (for automated building, for instance) you can. You would then follow these instructions.

  • On Windows, you can generate self-signed certificate for testing and development purposes. This certificate is required for electron-updater to work properly. You can generate this certificate by following steps below: Open Windows PowerShell with administrative privileges and execute these commands:

    $rootCert = New-SelfSignedCertificate -DnsName "martin" -Type CodeSigningCert -CertStoreLocation "C:\projects\nsis-test\certs\"
    [System.Security.SecureString]$rootcertPassword = ConvertTo-SecureString -String "some_password" -Force -AsPlainText
    [String]$rootCertPath = Join-Path -Path 'cert:\CurrentUser\My\' -ChildPath "$($rootcert.Thumbprint)"
    [String]$rootCertPath = Join-Path -Path 'cert:\LocalMachine\My\' -ChildPath "$($rootcert.Thumbprint)"
    Export-PfxCertificate -Cert $rootCertPath -FilePath 'RootCA.pfx' -Password $rootcertPassword
    Export-Certificate -Cert $rootCertPath -FilePath 'RootCA.crt'
    

    After successful creation of certificate files, make sure that they are in correct location. Open Certificate Manager by clicking on the Start button, type certmgr.msc in the search field and press Enter key.

    If your newly created certificate is not in Trusted Root Certification Authorities certificate folder, drag and drop it from Personal. Otherwise automatic updates will not work.

    Next, open package.json in your favorite text editor and modify these three lines.

    "publisherName": "Some Company", // when using self signed certs, enter a random string
    "certificateFile": "./certs/some_file.pfx",
    "certificatePassword": "some_password"
    

    Note: self-signed certificate can only be used for testing purposes. You can get more help on these websites:

Packaging And Testing

When you are done with code signing mess, it's time for building and testing. In package.json under scripts.dist key you can set your desired os. See the example below.

  • -m - Mac OS - I lost my microfiber cloth, it's gonna cost me a fortune
  • -w - Windows - Obscure, gimmicky gaming platform with built in spyware
  • -l - Linux - OS for the people
"scripts": {
    "dist": "electron-builder -mwl"
}

After configuring dist key for your OS, run the command below.

npm run dist

Testing Auto Update

When npm run dist finishes with the building process, open /dist folder and install the app on your system. After successful install, bump the version in package.json and and run the "npm run dist" command once again. When done, copy paste the contents of /dist folder to /wwwroot folder and run "npm run serve". Open the previous version that you installed on your system and voilà :)!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.