0Pricing
Electron Desktop App Development · 강의

자동 업데이트 구현

`electron-updater`를 사용하여 Electron 앱에 자동 업데이트 기능을 통합하고 사용자에게 새 버전을 원활하게 제공합니다.

자동 업데이트 구현은(는) CoddyKit의 무료 Electron Desktop App Development 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Electron Desktop App Development 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Electron Desktop App Development 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Auto-Updates?

Keeping your desktop application up-to-date is crucial for user experience and security. Auto-updates ensure users always have the latest features and bug fixes.

  • Improved Security: Patches vulnerabilities quickly.
  • New Features: Delivers enhancements without manual effort.
  • Bug Fixes: Resolves issues seamlessly.
  • Better User Experience: Users enjoy a consistently fresh and stable app.

Introducing `electron-updater`

electron-updater is a powerful module that simplifies adding auto-update functionality to your Electron app. It handles the complex logic of checking for new versions, downloading them, and installing them.

It works by looking for new releases on a configured update server (like GitHub Releases, Amazon S3, or a custom server) and managing the update process.

Installation & Setup

First, you need to install electron-updater as a dependency in your Electron project. It's best to add it as a regular dependency, not a dev dependency, as it's part of your deployed application.

Open your terminal in your project's root directory and run:

npm install electron-updater

Initial Setup in `main.js`

To use electron-updater, you'll primarily work in your app's main process (usually main.js). You'll import autoUpdater and call its checkForUpdates() method when your app is ready.

Note: This code is part of an Electron app's main process and requires a full Electron environment to run. It won't execute in a standard JavaScript playground.

const { app, BrowserWindow } = require('electron');
const { autoUpdater } = require('electron-updater');

// ... other app setup ...

app.on('ready', () => {
  // createWindow(); // Your window creation function
  autoUpdater.checkForUpdates();
  console.log('Checking for updates...');
});

// ... other app lifecycle events ...

Understanding Update Events

electron-updater uses an event-driven model. This means you 'listen' for specific events that occur during the update process and react to them. This allows you to provide feedback to your users.

  • checking-for-update: Update check started.
  • update-available: New version found.
  • update-not-available: No new version.
  • download-progress: Update download progress.
  • update-downloaded: Update ready to install.
  • error: Something went wrong.

Handling `checking-for-update`

The checking-for-update event is fired as soon as checkForUpdates() is called. It's a good place to show a loading indicator or a message to the user.

Remember: This code needs to be in your Electron main.js file.

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

autoUpdater.on('checking-for-update', () => {
  console.log('App is now checking for updates...');
  // You might send a message to the renderer process
  // to update the UI here.
});

Handling `update-available`

When electron-updater finds a new version, it emits the update-available event. At this point, the update download usually begins automatically. You can use this event to notify the user that an update is being downloaded.

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

autoUpdater.on('update-available', (info) => {
  console.log(`Update available! Version: ${info.version}`);
  // Display a message to the user that an update is downloading.
});

Handling `update-downloaded` & Install

Once the update has been fully downloaded, the update-downloaded event is emitted. This is the critical moment! You should notify the user and ask them to restart the application to apply the update.

The autoUpdater.quitAndInstall() method will close all windows and install the update, then relaunch the app.

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

autoUpdater.on('update-downloaded', (info) => {
  console.log('Update downloaded. Restarting app to install...');
  // In a real app, you'd prompt the user here:
  // dialog.showMessageBox({ /* ... */ }).then(() => autoUpdater.quitAndInstall());
  autoUpdater.quitAndInstall();
});

Handling Errors & No Updates

It's important to handle cases where there are no updates or if an error occurs during the process. The update-not-available event lets you know when your app is already the latest version.

The error event is crucial for debugging and informing users if something went wrong during the update check or download.

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

autoUpdater.on('update-not-available', (info) => {
  console.log('No new updates available.');
});

autoUpdater.on('error', (err) => {
  console.error('Error during auto-update:', err);
  // You might display an error message to the user.
});

Update Flow Check

You've learned about the main events in the electron-updater lifecycle. Which of the following statements about auto-updates are generally true?

Recap: Keep Your App Fresh!

In this lesson, you've learned how to implement auto-update functionality in your Electron applications using the electron-updater module.

  • We covered its installation and basic setup in the main process.
  • You explored key events like checking-for-update, update-available, update-downloaded, and error.
  • Understanding these events allows you to build a robust and user-friendly update experience, ensuring your users always have the best version of your app.

자주 묻는 질문

“자동 업데이트 구현” 강의는 무료인가요?

네 — “자동 업데이트 구현” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Electron Desktop App Development 강의 전체를 잠금 해제할 수 있습니다. Electron Desktop App Development 강의에는 총 4개의 강의가 포함되어 있습니다.

“자동 업데이트 구현”에서 뭘 배우나요?

`electron-updater`를 사용하여 Electron 앱에 자동 업데이트 기능을 통합하고 사용자에게 새 버전을 원활하게 제공합니다. 브라우저에서 직접 실행하는 실습 코드로 Electron Desktop App Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Electron Desktop App Development을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Electron Desktop App Development은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“자동 업데이트 구현” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Electron Desktop App Development 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Electron Desktop App Development 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 앱 수명 주기 이벤트 관리
  2. 자동 업데이트 구현
  3. 충돌 보고
  4. 딥 링크와 프로토콜 처리기
← Electron Desktop App Development(으)로 돌아가기