mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-10-31 03:53:34 +00:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			v2.2.0-bet
			...
			auto-updat
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 8ad74081c4 | ||
|  | 6163ad85e0 | ||
|  | cfc97c9b73 | ||
|  | 2e70b515da | 
| @@ -1,11 +1,11 @@ | ||||
| 'use strict'; | ||||
| const { app, dialog } = require('electron'); | ||||
| const { app, dialog, shell } = require('electron'); | ||||
| const { autoUpdater } = require('electron-updater'); | ||||
| const isDev = require('electron-is-dev'); | ||||
|  | ||||
| const ConfigUtil = require('./../renderer/js/utils/config-util.js'); | ||||
|  | ||||
| function appUpdater() { | ||||
| function appUpdater(updateFromMenu = false) { | ||||
| 	// Don't initiate auto-updates in development | ||||
| 	if (isDev) { | ||||
| 		return; | ||||
| @@ -17,6 +17,8 @@ function appUpdater() { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	let updateAvailable = false; | ||||
|  | ||||
| 	// Create Logs directory | ||||
| 	const LogsDir = `${app.getPath('userData')}/Logs`; | ||||
|  | ||||
| @@ -28,7 +30,58 @@ function appUpdater() { | ||||
| 	autoUpdater.logger = log; | ||||
|  | ||||
| 	// Handle auto updates for beta/pre releases | ||||
| 	autoUpdater.allowPrerelease = ConfigUtil.getConfigItem('betaUpdate') || false; | ||||
| 	const isBetaUpdate = ConfigUtil.getConfigItem('betaUpdate'); | ||||
|  | ||||
| 	autoUpdater.allowPrerelease = isBetaUpdate || false; | ||||
|  | ||||
| 	const eventsListenerRemove = ['update-available', 'update-not-available']; | ||||
| 	autoUpdater.on('update-available', info => { | ||||
| 		if (updateFromMenu) { | ||||
| 			dialog.showMessageBox({ | ||||
| 				message: `A new version ${info.version}, of Zulip Desktop is available`, | ||||
| 				detail: 'The update will be downloaded in the background. You will be notified when it is ready to be installed.' | ||||
| 			}); | ||||
|  | ||||
| 			updateAvailable = true; | ||||
|  | ||||
| 			// This is to prevent removal of 'update-downloaded' and 'error' event listener. | ||||
| 			eventsListenerRemove.forEach(event => { | ||||
| 				autoUpdater.removeAllListeners(event); | ||||
| 			}); | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| 	autoUpdater.on('update-not-available', () => { | ||||
| 		if (updateFromMenu) { | ||||
| 			dialog.showMessageBox({ | ||||
| 				message: 'No updates available', | ||||
| 				detail: `You are running the latest version of Zulip Desktop.\nVersion: ${app.getVersion()}` | ||||
| 			}); | ||||
| 			// Remove all autoUpdator listeners so that next time autoUpdator is manually called these | ||||
| 			// listeners don't trigger multiple times. | ||||
| 			autoUpdater.removeAllListeners(); | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| 	autoUpdater.on('error', error => { | ||||
| 		if (updateFromMenu) { | ||||
| 			const messageText = (updateAvailable) ? ('Unable to download the updates') : ('Unable to check for updates'); | ||||
| 			dialog.showMessageBox({ | ||||
| 				type: 'error', | ||||
| 				buttons: ['Manual Download', 'Cancel'], | ||||
| 				message: messageText, | ||||
| 				detail: (error).toString() + `\n\nThe latest version of Zulip Desktop is available at -\nhttps://zulipchat.com/apps/.\n | ||||
| Current Version: ${app.getVersion()}` | ||||
| 			}, response => { | ||||
| 				if (response === 0) { | ||||
| 					shell.openExternal('https://zulipchat.com/apps/'); | ||||
| 				} | ||||
| 			}); | ||||
| 			// Remove all autoUpdator listeners so that next time autoUpdator is manually called these | ||||
| 			// listeners don't trigger multiple times. | ||||
| 			autoUpdater.removeAllListeners(); | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| 	// Ask the user if update is available | ||||
| 	// eslint-disable-next-line no-unused-vars | ||||
|   | ||||
| @@ -161,7 +161,9 @@ app.on('ready', () => { | ||||
|  | ||||
| 	page.once('did-frame-finish-load', () => { | ||||
| 		// Initate auto-updates on MacOS and Windows | ||||
| 		appUpdater(); | ||||
| 		if (ConfigUtil.getConfigItem('autoUpdate')) { | ||||
| 			appUpdater(); | ||||
| 		} | ||||
| 		crashHandler(); | ||||
| 	}); | ||||
|  | ||||
|   | ||||
| @@ -4,6 +4,7 @@ const path = require('path'); | ||||
| const { app, shell, BrowserWindow, Menu, dialog } = require('electron'); | ||||
|  | ||||
| const fs = require('fs-extra'); | ||||
| const { appUpdater } = require('./autoupdater'); | ||||
|  | ||||
| const ConfigUtil = require(__dirname + '/../renderer/js/utils/config-util.js'); | ||||
| const DNDUtil = require(__dirname + '/../renderer/js/utils/dnd-util.js'); | ||||
| @@ -195,7 +196,12 @@ class AppMenu { | ||||
| 						AppMenu.sendAction('open-about'); | ||||
| 					} | ||||
| 				} | ||||
| 			}, { | ||||
| 			},	{ | ||||
| 				label: `Check for Update`, | ||||
| 				click() { | ||||
| 					AppMenu.checkForUpdate(); | ||||
| 				} | ||||
| 			},	{ | ||||
| 				type: 'separator' | ||||
| 			}, { | ||||
| 				label: 'Desktop App Settings', | ||||
| @@ -302,7 +308,12 @@ class AppMenu { | ||||
| 						AppMenu.sendAction('open-about'); | ||||
| 					} | ||||
| 				} | ||||
| 			}, { | ||||
| 			}, 	{ | ||||
| 				label: `Check for Update`, | ||||
| 				click() { | ||||
| 					AppMenu.checkForUpdate(); | ||||
| 				} | ||||
| 			},	{ | ||||
| 				type: 'separator' | ||||
| 			}, { | ||||
| 				label: 'Desktop App Settings', | ||||
| @@ -399,6 +410,9 @@ class AppMenu { | ||||
| 		win.webContents.send(action, ...params); | ||||
| 	} | ||||
|  | ||||
| 	static checkForUpdate() { | ||||
| 		appUpdater(true); | ||||
| 	} | ||||
| 	static resetAppSettings() { | ||||
| 		const resetAppSettingsMessage = 'By proceeding you will be removing all connected organizations and preferences from Zulip.'; | ||||
|  | ||||
|   | ||||
| @@ -89,6 +89,7 @@ class ServerManagerView { | ||||
| 			startMinimized: false, | ||||
| 			enableSpellchecker: true, | ||||
| 			showNotification: true, | ||||
| 			autoUpdate: true, | ||||
| 			betaUpdate: false, | ||||
| 			silent: false, | ||||
| 			lastActiveTab: 0, | ||||
|   | ||||
| @@ -48,7 +48,11 @@ class GeneralSection extends BaseSection { | ||||
| 					</div> | ||||
| 				</div> | ||||
| 				<div class="title">App Updates</div> | ||||
|                 <div class="settings-card"> | ||||
| 				<div class="settings-card"> | ||||
| 				<div class="setting-row" id="autoupdate-option"> | ||||
| 						<div class="setting-description">Enable auto updates</div> | ||||
| 						<div class="setting-control"></div> | ||||
| 					</div> | ||||
| 					<div class="setting-row" id="betaupdate-option"> | ||||
| 						<div class="setting-description">Get beta updates</div> | ||||
| 						<div class="setting-control"></div> | ||||
| @@ -104,7 +108,8 @@ class GeneralSection extends BaseSection { | ||||
| 		this.updateTrayOption(); | ||||
| 		this.updateBadgeOption(); | ||||
| 		this.updateSilentOption(); | ||||
| 		this.updateUpdateOption(); | ||||
| 		this.autoUpdateOption(); | ||||
| 		this.betaUpdateOption(); | ||||
| 		this.updateSidebarOption(); | ||||
| 		this.updateStartAtLoginOption(); | ||||
| 		this.updateResetDataOption(); | ||||
| @@ -160,14 +165,26 @@ class GeneralSection extends BaseSection { | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	updateUpdateOption() { | ||||
| 	autoUpdateOption() { | ||||
| 		this.generateSettingOption({ | ||||
| 			$element: document.querySelector('#autoupdate-option .setting-control'), | ||||
| 			value: ConfigUtil.getConfigItem('autoUpdate', true), | ||||
| 			clickHandler: () => { | ||||
| 				const newValue = !ConfigUtil.getConfigItem('autoUpdate'); | ||||
| 				ConfigUtil.setConfigItem('autoUpdate', newValue); | ||||
| 				this.autoUpdateOption(); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	betaUpdateOption() { | ||||
| 		this.generateSettingOption({ | ||||
| 			$element: document.querySelector('#betaupdate-option .setting-control'), | ||||
| 			value: ConfigUtil.getConfigItem('betaUpdate', false), | ||||
| 			clickHandler: () => { | ||||
| 				const newValue = !ConfigUtil.getConfigItem('betaUpdate'); | ||||
| 				ConfigUtil.setConfigItem('betaUpdate', newValue); | ||||
| 				this.updateUpdateOption(); | ||||
| 				this.betaUpdateOption(); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|   | ||||
| @@ -124,7 +124,7 @@ | ||||
|     "cp-file": "^5.0.0", | ||||
|     "devtron": "1.4.0", | ||||
|     "electron": "2.0.0", | ||||
|     "electron-builder": "20.11.1", | ||||
|     "electron-builder": "20.13.4", | ||||
|     "electron-connect": "0.6.2", | ||||
|     "electron-debug": "1.4.0", | ||||
|     "google-translate-api": "2.3.0", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user