Electron Desktop App Development · レッスン

Electronアプリの自動更新

electron-updater、更新チャネル、洗練された更新フローを使って、ユーザーにシームレスな更新を届けます。

レッスン 4/413 ステップ

「Electronアプリの自動更新」はCoddyKit上の無料Electron Desktop App Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElectron Desktop App Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Electron Desktop App Developmentコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Auto-Update Matters

Desktop apps are not auto-refreshed like web pages. Once a user installs your Electron app, you need a way to push new versions without asking them to re-download manually.

An auto-update system lets you ship bug fixes and features continuously, keeping every user on a recent, secure build.

  • Reduces support burden from stale versions
  • Delivers security patches fast
  • Improves retention with new features

The electron-updater Library

The most common solution is electron-updater, part of the electron-builder ecosystem. It handles checking, downloading, and installing updates across Windows, macOS, and Linux.

Install it as a runtime dependency, not a dev dependency, because it ships inside your app.

npm install electron-updater

Configuring the Publish Target

electron-updater reads a publish block in your build config to know where to fetch new versions. A common target is a generic HTTP server or a GitHub release.

"build": {
  "publish": [{
    "provider": "generic",
    "url": "https://updates.example.com/myapp"
  }]
}

Triggering an Update Check

In your main process, call autoUpdater.checkForUpdates() after the app is ready. This contacts your publish URL and compares versions.

Run this from the main process only, never the renderer.

const { autoUpdater } = require('electron-updater')

app.whenReady().then(() => {
  createWindow()
  autoUpdater.checkForUpdates()
})

Listening to Update Events

autoUpdater emits events you can hook into to drive your UI and logging.

  • update-available — a newer version exists
  • download-progress — bytes transferred
  • update-downloaded — ready to install
autoUpdater.on('update-available', () => {
  console.log('New version found')
})

autoUpdater.on('download-progress', (p) => {
  console.log('Progress: ' + Math.round(p.percent) + '%')
})

Installing the Downloaded Update

When update-downloaded fires, the new version is staged. Call quitAndInstall() to restart the app onto the new version.

It is good practice to prompt the user first instead of restarting unexpectedly.

autoUpdater.on('update-downloaded', () => {
  autoUpdater.quitAndInstall()
})

Update Channels

Channels let you ship pre-release builds to a subset of users. Common channels are latest, beta, and alpha.

Set the channel so testers receive early builds while everyone else stays on stable.

autoUpdater.channel = 'beta'
autoUpdater.allowPrerelease = true

Communicating Progress to the UI

Because autoUpdater lives in the main process, forward its events to the renderer through your preload bridge so the UI can show a progress bar.

autoUpdater.on('download-progress', (p) => {
  mainWindow.webContents.send('update-progress', p.percent)
})

Handling Errors Gracefully

Network failures and signature mismatches happen. Always listen for the error event so a failed update never crashes the app or blocks the user.

autoUpdater.on('error', (err) => {
  console.error('Update failed:', err == null ? 'unknown' : err.message)
})

Code Signing Requirements

On macOS and Windows, auto-updates only work if your app is code signed. Unsigned builds will fail the signature check on install.

  • macOS: Apple Developer ID certificate
  • Windows: Authenticode certificate

Signing also protects users from tampered update payloads.

Manual vs Silent Updates

You can disable automatic downloading and let users decide when to update by setting autoDownload = false, then calling downloadUpdate() on demand.

Choose silent background updates for consumer apps, manual control for enterprise tools.

autoUpdater.autoDownload = false

autoUpdater.on('update-available', () => {
  // ask user, then:
  autoUpdater.downloadUpdate()
})

Quick Check

Test your understanding of Electron auto-updates.

Recap

You learned how to ship seamless updates with electron-updater:

  • Configure a publish target
  • Call checkForUpdates() from the main process
  • React to update-available, download-progress, and update-downloaded
  • Use quitAndInstall() to apply
  • Code sign your builds and choose channels

A reliable update pipeline keeps your whole user base current and secure.

無料で開始

AI チューターと学ぶ JavaScript — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
47

よくある質問

「Electronアプリの自動更新」レッスンは無料ですか?

はい。「Electronアプリの自動更新」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Electron Desktop App Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Electron Desktop App Developmentコースには全4レッスンが含まれています。

「Electronアプリの自動更新」で何を学びますか?

electron-updater、更新チャネル、洗練された更新フローを使って、ユーザーにシームレスな更新を届けます。 ブラウザで直接実行するハンズオンコードでElectron Desktop App Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Electron Desktop App Developmentを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのElectron Desktop App Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「Electronアプリの自動更新」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このElectron Desktop App Developmentレッスンでコードを書いて実行できますか?

はい。すべてのElectron Desktop App Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. マルチウィンドウアーキテクチャ
  2. バックグラウンドプロセスとWorker
  3. クラウドサービスとの統合
  4. Electronアプリの自動更新
← Electron Desktop App Developmentに戻る