Auto-Updater
Relevant source files
The following files were used as context for generating this wiki page:The Auto-Updater system for Skid-Inc provides a mechanism for the Electron application to automatically check for, download, and install updates. The system is designed to be integrated into the project via a one-time setup script, which generates the necessary modules for both the main and renderer processes, configures package.json, and sets up the required build configurations. It leverages electron-updater and electron-log for its core functionality, checking for new releases from the project's GitHub repository.
The system consists of a setup script, a main process handler (AutoUpdateManager), and a generated renderer process UI manager. It supports periodic background checks, manual update checks initiated by the user, and a clear user-facing notification flow for when updates are available, downloading, or ready to install.
Sources: scripts/README.md:39-51, scripts/auto-update.js:5-8, src/auto-updater.js:6-9
System Architecture
The Auto-Updater is composed of three main parts: a one-time setup script, a main process module that handles the update logic, and a renderer process module for the user interface.
- Setup Script (
scripts/auto-update.js): A Node.js script that injects the auto-update feature into the application. It installs dependencies, generates the coresrc/auto-updater.jsandsrc/renderer/update-manager.jsfiles, and modifiessrc/main.jsandpackage.jsonto integrate the system. - Main Process Module (
src/auto-updater.js): TheAutoUpdateManagerclass runs in the Electron main process. It useselectron-updaterto communicate with the update server (GitHub Releases). It manages the lifecycle of an update: checking, showing dialogs, downloading, and installing. - Renderer Process Module (
src/renderer/update-manager.js): A UI component generated by the setup script. It listens for events from the main process via IPC to display notifications and progress updates to the user. It also allows the user to manually initiate an update check.
Sources: scripts/auto-update.js, src/auto-updater.js, src/main.js
Component Interaction
The following diagram illustrates how the different components of the auto-update system interact.
Setup and Configuration
The auto-update system is added to the project by running the scripts/auto-update.js script. This script performs several automated steps to configure the project.
Sources: scripts/README.md:48-51, scripts/auto-update.js:615-626
Setup Process Flow
This flowchart shows the sequence of actions performed by the auto-update.js setup script.
Configuration
The setup script uses a predefined configuration and also sets up configuration files for the build and release process.
Script Configuration
The UPDATE_CONFIG object in scripts/auto-update.js defines the core behavior of the updater.
| Parameter | Type | Default Value | Description |
|---|---|---|---|
provider | String | 'github' | The update provider. |
owner | String | 'TotomInc' | The GitHub repository owner. |
repo | String | 'skid-inc' | The GitHub repository name. |
updateCheckInterval | Number | 86400000 (24 hours) | The interval in milliseconds for periodic update checks. |
allowPrerelease | Boolean | false | Whether to allow pre-release versions to be installed. |
allowDowngrade | Boolean | false | Whether to allow downgrading to an older version. |
Sources: scripts/auto-update.js:10-17, scripts/README.md:190-197
package.json Configuration
The script adds electron-updater and electron-log to the dependencies and configures the build.publish property, which is used by electron-builder to publish releases.
"dependencies": {
"electron-updater": "^6.1.7",
"electron-log": "^5.0.1"
},
"build": {
"publish": {
"provider": "github",
"owner": "TotomInc",
"repo": "skid-inc"
}
}
Sources: package.json:8-11, 201-205, scripts/auto-update.js:439-458
Main Process: AutoUpdateManager
The AutoUpdateManager class, located in src/auto-updater.js, is the heart of the update system in the main process. It is instantiated in src/main.js after the main browser window is created.
Sources: src/auto-updater.js, src/main.js:112-119
Class Structure
This diagram shows the key properties and methods of the AutoUpdateManager class.
Sources: src/auto-updater.js:12-20, 22-198
Update Lifecycle
The AutoUpdateManager handles the entire update lifecycle through a series of events from electron-updater.
- Check for Updates: Triggered automatically by
scheduleUpdateChecks(every 4 hours) or manually via an IPC call. - Update Available: If an update is found,
autoUpdateremitsupdate-available. The manager then shows a dialog to the user asking for confirmation to download. - Download: If the user agrees,
downloadUpdate()is called. Progress is monitored via thedownload-progressevent and sent to the renderer process. - Update Downloaded: Once complete, the
update-downloadedevent is fired. The manager shows another dialog asking the user to restart the application to install. - Install: If the user agrees,
installUpdate()callsautoUpdater.quitAndInstall(), which closes the application, installs the update, and restarts. - Error Handling: Any errors during the process are caught by the
errorevent handler, which displays an error dialog.
Sources: src/auto-updater.js:63-91, 93-122, 124-132, 134-198
Update Check Sequence Diagram
This diagram shows the sequence of events for a manual update check.
Renderer Process Integration
The setup script generates src/renderer/update-manager.js to handle UI notifications. While this file is not present in the repository, its intended structure and functionality are defined within scripts/auto-update.js. It creates a UI element to show update status and progress.
Integration with the main process is achieved through IPC channels, which are defined in src/main.js.
Sources: scripts/auto-update.js:464-599, src/main.js:347-400, 460-539
IPC Handlers
The following IPC channels are set up in src/main.js to allow the renderer process to interact with the AutoUpdateManager.
| IPC Channel | Direction | Description |
|---|---|---|
check-for-updates | Renderer -> Main (handle) | Manually triggers a check for updates. |
get-update-status | Renderer -> Main (handle) | Retrieves the current status (e.g., updateAvailable). |
download-update | Renderer -> Main (handle) | Starts the download of an available update. |
install-update | Renderer -> Main (handle) | Triggers the quitAndInstall process. |
update-download-progress | Main -> Renderer (send) | Sends download progress information to the renderer for UI updates. |
Sources: src/main.js:460-539, src/auto-updater.js:184-195
Summary
The Auto-Updater is a comprehensive feature integrated via an automated script. It provides a robust, user-friendly mechanism for keeping the Skid-Inc application up-to-date. The architecture cleanly separates the setup logic, main process update handling, and renderer UI, communicating between processes via Electron's IPC. Configuration is centralized in package.json and scripts/auto-update.js, making it straightforward to manage the update provider and behavior.
Sources: scripts/README.md, scripts/auto-update.js, src/auto-updater.js