🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: simplify updater config logic (#11636)
Innei5c645f09fdd6
diff --git a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts b/apps/desktop/src/main/core/infrastructure/UpdaterManager.tsindex 18ce5ae3cbc..ecbefef3a03 100644--- a/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts+++ b/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts@@ -14,10 +14,8 @@ import { createLogger } from '@/utils/logger';import type { App as AppCore } from '../App';-// Allow forcing dev update config via env (for testing updates in packaged app)const FORCE_DEV_UPDATE_CONFIG = getDesktopEnv().FORCE_DEV_UPDATE_CONFIG;-// Create loggerconst logger = createLogger('core:UpdaterManager');export class UpdaterManager {@@ -31,11 +29,10 @@ export class UpdaterManager {constructor(app: AppCore) {this.app = app;- // 设置日志log.transports.file.level = 'info';autoUpdater.logger = log;- logger.debug(`[Updater] Log file should be at: ${log.transports.file.getFile().path}`); // 打印路径+ logger.debug(`[Updater] Log file should be at: ${log.transports.file.getFile().path}`);}get mainWindow() {@@ -44,50 +41,36 @@ export class UpdaterManager {public initialize = async () => {logger.debug('Initializing UpdaterManager');- // If updates are disabled and in production environment, don't initialize updates- if (!updaterConfig.enableAppUpdate && !isDev) {++ if (!updaterConfig.enableAppUpdate) {logger.info('App updates are disabled, skipping updater initialization');return;}- // Configure autoUpdater- autoUpdater.autoDownload = false; // Set to false, we'll control downloads manually+ autoUpdater.autoDownload = false;autoUpdater.autoInstallOnAppQuit = false;autoUpdater.allowDowngrade = false;- // Enable test mode in development environment or when forced via env- // IMPORTANT: This must be set BEFORE channel configuration so that- // dev-app-update.yml takes precedence over programmatic configurationconst useDevConfig = isDev || FORCE_DEV_UPDATE_CONFIG;if (useDevConfig) {- // In dev mode, use dev-app-update.yml for all configuration including channel- // Don't set channel here - let dev-app-update.yml control it (defaults to "latest")autoUpdater.forceDevUpdateConfig = true;logger.info(`Using dev update config (isDev=${isDev}, FORCE_DEV_UPDATE_CONFIG=${FORCE_DEV_UPDATE_CONFIG})`,);logger.info('Dev mode: Using dev-app-update.yml for update configuration');} else {- // Only configure channel and update provider programmatically in production- // Note: channel is configured in configureUpdateProvider based on provider typeautoUpdater.allowPrerelease = channel !== 'stable';logger.info(`Production mode: channel=${channel}, allowPrerelease=${channel !== 'stable'}`);this.configureUpdateProvider();}- // Register eventsthis.registerEvents();- // If auto-check for updates is configured, set up periodic checksif (updaterConfig.app.autoCheckUpdate) {- // Delay update check by 1 minute after startup to avoid network instabilitysetTimeout(() => this.checkForUpdates(), 60 * 1000);-- // Set up periodic checkssetInterval(() => this.checkForUpdates(), updaterConfig.app.checkUpdateInterval);}- // Log the channel and allowPrerelease valueslogger.debug(`Initialized with channel: ${autoUpdater.channel}, allowPrerelease: ${autoUpdater.allowPrerelease}`,);@@ -105,15 +88,12 @@ export class UpdaterManager {this.checking = true;this.isManualCheck = manual;- // Ensure allowPrerelease is correctly set before each check- // This guards against any internal state reset by electron-updaterif (!isStableChannel) {autoUpdater.allowPrerelease = true;}logger.info(`${manual ? 'Manually checking' : 'Auto checking'} for updates...`);- // Log detailed updater configuration for debuggingconst inferredChannel =autoUpdater.channel ||(autoUpdater.currentVersion?.prerelease?.[0]@@ -133,7 +113,6 @@ export class UpdaterManager {logger.info('[Updater Config] usingFallbackProvider:', this.usingFallbackProvider);logger.info('[Updater Config] GitHub config:', JSON.stringify(githubConfig));- // If manual check, notify renderer process about check startif (manual) {this.mainWindow.broadcast('manualUpdateCheckStart');}@@ -143,7 +122,6 @@ export class UpdaterManager {} catch (error) {logger.error('Error checking for updates:', error.message);- // If manual check, notify renderer process about check errorif (manual) {this.mainWindow.broadcast('updateError', (error as Error).message);}@@ -162,7 +140,6 @@ export class UpdaterManager {this.downloading = true;logger.info(`${manual ? 'Manually downloading' : 'Auto downloading'} update...`);- // If manual download or manual check, notify renderer process about download startif (manual || this.isManualCheck) {this.mainWindow.broadcast('updateDownloadStart');}@@ -173,7 +150,6 @@ export class UpdaterManager {this.downloading = false;logger.error('Error downloading update:', error);- // If manual download or manual check, notify renderer process about download errorif (manual || this.isManualCheck) {this.mainWindow.broadcast('updateError', (error as Error).message);}@@ -186,14 +162,10 @@ export class UpdaterManager {public installNow = () => {logger.info('Installing update now...');- // Mark application for exitthis.app.isQuiting = true;- // Close all windows first to ensure clean exitlogger.info('Closing all windows before update installation...');const { BrowserWindow, app } = require('electron');- // do not close windows and quit first- // on Windows, window-all-closed -> app.quit()` can terminate the process before the timer firesif (!isWindows) {const allWindows = BrowserWindow.getAllWindows();allWindows.forEach((window) => {@@ -203,16 +175,10 @@ export class UpdaterManager {});}- // Release single instance lock before quitting- // This ensures the new instance can acquire the locklogger.info('Releasing single instance lock...');app.releaseSingleInstanceLock();- // Small delay to ensure windows are closed and lock is releasedsetTimeout(() => {- // quitAndInstall parameters:- // - isSilent: true (don't show installation UI)- // - isForceRunAfter: true (force start app after installation)logger.info('Calling autoUpdater.quitAndInstall...');autoUpdater.quitAndInstall(true, true);}, 100);@@ -224,10 +190,7 @@ export class UpdaterManager {public installLater = () => {logger.info('Update will be installed on next restart');- // Mark for installation on next launch, but don't exit applicationautoUpdater.autoInstallOnAppQuit = true;-- // Notify renderer process that update will be installed on next launchthis.mainWindow.broadcast('updateWillInstallLater');};@@ -241,7 +204,6 @@ export class UpdaterManager {logger.info('Simulating update available...');const mainWindow = this.mainWindow;- // Simulate a new version updateconst mockUpdateInfo = {releaseDate: new Date().toISOString(),releaseNotes: ` #### Version 1.0.0 Release Notes@@ -253,14 +215,11 @@ export class UpdaterManager {version: '1.0.0',};- // Set update available statethis.updateAvailable = true;- // Notify renderer processif (this.isManualCheck) {mainWindow.broadcast('manualUpdateAvailable', mockUpdateInfo);} else {- // In auto-check mode, directly simulate downloadthis.simulateDownloadProgress();}};@@ -276,7 +235,6 @@ export class UpdaterManager {const mainWindow = this.app.browserManager.getMainWindow();if (mainWindow) {- // Simulate a new version updateconst mockUpdateInfo = {releaseDate: new Date().toISOString(),releaseNotes: ` #### Version 1.0.0 Release Notes@@ -288,10 +246,7 @@ export class UpdaterManager {version: '1.0.0',};- // Set download statethis.downloading = false;-- // Notify renderer processmainWindow.broadcast('updateDownloaded', mockUpdateInfo);}};@@ -307,28 +262,22 @@ export class UpdaterManager {const mainWindow = this.app.browserManager.getMainWindow();- // Set download statethis.downloading = true;- // Only broadcast download start event if manual checkif (this.isManualCheck) {mainWindow.broadcast('updateDownloadStart');}- // Simulate progress updateslet progress = 0;const interval = setInterval(() => {progress += 10;- if (- progress <= 100 && // Only broadcast download progress if manual check- this.isManualCheck- ) {+ if (progress <= 100 && this.isManualCheck) {mainWindow.broadcast('updateDownloadProgress', {bytesPerSecond: 1024 * 1024,- percent: progress, // 1MB/s- total: 1024 * 1024 * 100, // 100MB- transferred: 1024 * 1024 * progress, // Progress * 1MB+ percent: progress,+ total: 1024 * 1024 * 100,+ transferred: 1024 * 1024 * progress,});}@@ -348,8 +297,6 @@ export class UpdaterManager {*/private configureUpdateProvider() {if (isStableChannel && UPDATE_SERVER_URL && !this.usingFallbackProvider) {- // Stable channel uses custom update server (generic HTTP) as primary- // S3 has stable-mac.yml, so we set channel to 'stable'autoUpdater.channel = 'stable';logger.info(`Configuring generic provider for stable channel (primary)`);logger.info(`Update server URL: ${UPDATE_SERVER_URL}`);@@ -360,9 +307,6 @@ export class UpdaterManager {url: UPDATE_SERVER_URL,});} else {- // GitHub provider:- // - stable: use default latest-mac.yml (GitHub uploads latest* only)- // - beta/nightly: leave channel unset so prerelease matching uses tag (e.g. next)const reason = this.usingFallbackProvider ? '(fallback from S3)' : '';logger.info(`Configuring GitHub provider for ${channel} channel ${reason}`);if (autoUpdater.channel !== null) {@@ -370,7 +314,6 @@ export class UpdaterManager {}logger.info('Channel left unset (defaults to latest-mac.yml for GitHub)');- // For beta/nightly channels, we need prerelease versionsconst needPrerelease = channel !== 'stable';autoUpdater.setFeedURL({@@ -379,8 +322,6 @@ export class UpdaterManager {repo: githubConfig.repo,});- // Ensure allowPrerelease is set correctly after setFeedURL- // setFeedURL may reset some internal statesautoUpdater.allowPrerelease = needPrerelease;logger.info(@@ -394,7 +335,6 @@ export class UpdaterManager {* Called when primary provider (S3) fails*/private switchToFallbackAndRetry = async () => {- // Only fallback if we're on stable channel with S3 configured and haven't already fallen backif (!isStableChannel || !UPDATE_SERVER_URL || this.usingFallbackProvider) {return false;}@@ -403,7 +343,6 @@ export class UpdaterManager {this.usingFallbackProvider = true;this.configureUpdateProvider();- // Retry update check with fallback providertry {await autoUpdater.checkForUpdates();return true;@@ -437,13 +376,11 @@ export class UpdaterManager {logger.info(`Update available: ${info.version}`);this.updateAvailable = true;- // Reset to primary provider for next check cyclethis.resetToPrimaryProvider();if (this.isManualCheck) {this.mainWindow.broadcast('manualUpdateAvailable', info);} else {- // If it's an automatic check, start downloading automaticallylogger.info('Auto check found update, starting download automatically...');this.downloadUpdate();}@@ -452,7 +389,6 @@ export class UpdaterManager {autoUpdater.on('update-not-available', (info) => {logger.info(`Update not available. Current: ${info.version}`);- // Reset to primary provider for next check cyclethis.resetToPrimaryProvider();if (this.isManualCheck) {@@ -462,7 +398,6 @@ export class UpdaterManager {autoUpdater.on('error', async (err) => {logger.error('Error in auto-updater:', err);- // Log configuration state when error occurs for debugginglogger.error('[Updater Error Context] Channel:', autoUpdater.channel);logger.error('[Updater Error Context] allowPrerelease:', autoUpdater.allowPrerelease);logger.error('[Updater Error Context] Build channel from config:', channel);@@ -471,12 +406,11 @@ export class UpdaterManager {logger.error('[Updater Error Context] usingFallbackProvider:', this.usingFallbackProvider);logger.error('[Updater Error Context] GitHub config:', JSON.stringify(githubConfig));- // Try fallback to GitHub if S3 failedif (!this.usingFallbackProvider && isStableChannel && UPDATE_SERVER_URL) {logger.info('Attempting fallback to GitHub provider...');const fallbackSucceeded = await this.switchToFallbackAndRetry();if (fallbackSucceeded) {- return; // Fallback initiated, don't report error yet+ return;}}@@ -497,7 +431,6 @@ export class UpdaterManager {autoUpdater.on('update-downloaded', (info) => {logger.info(`Update downloaded: ${info.version}`);this.downloading = false;- // Always notify about downloaded updatethis.mainWindow.broadcast('updateDownloaded', info);});diff --git a/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts b/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.tsindex e18a9ca7393..8686893f83b 100644--- a/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts+++ b/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts@@ -76,7 +76,6 @@ vi.mock('@/modules/updater/configs', () => ({checkUpdateInterval: 60 * 60 * 1000,},enableAppUpdate: true,- enableRenderHotUpdate: true,},}));diff --git a/apps/desktop/src/main/modules/updater/configs.ts b/apps/desktop/src/main/modules/updater/configs.tsindex dda4de7149c..7066aeb0543 100644--- a/apps/desktop/src/main/modules/updater/configs.ts+++ b/apps/desktop/src/main/modules/updater/configs.ts@@ -27,10 +27,6 @@ export const updaterConfig = {// Update check interval (milliseconds)checkUpdateInterval: 60 * 60 * 1000, // 1 hour},-// Whether to enable application updatesenableAppUpdate: !isDev,-- // 是否启用渲染层热更新- enableRenderHotUpdate: !isDev,};