From 348c4ad3a3bdb27644dc575e8a6aed012bc1197a Mon Sep 17 00:00:00 2001 From: Matthew Crumley Date: Fri, 11 Oct 2019 18:44:58 -0400 Subject: [PATCH] Desktop: Resolves #1222: Truncate update changelog when it's too long (#1967) The changelong text is truncated if it's longer than 1000 characters, but avoids cutting off a partial line, unless that would lead to cutting off too much of the text. An ellipsis is added to mark the truncation. Additionally, when the changelong is truncated, it adds a "Full Release Notes" button that opens the GitHub release page in a browser window. --- ElectronClient/app/checkForUpdates.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ElectronClient/app/checkForUpdates.js b/ElectronClient/app/checkForUpdates.js index 7362f29be3..a6b8dfe4cc 100644 --- a/ElectronClient/app/checkForUpdates.js +++ b/ElectronClient/app/checkForUpdates.js @@ -93,6 +93,18 @@ async function fetchLatestRelease(options) { }; } +function truncateText(text, length) { + let truncated = text.substring(0, length); + const lastNewLine = truncated.lastIndexOf('\n'); + // Cut off at a line break unless we'd be cutting off half the text + if (lastNewLine > length / 2) { + truncated = `${truncated.substring(0, lastNewLine)}\n...`; + } else { + truncated = `${truncated.trim()}...`; + } + return truncated; +} + function checkForUpdates(inBackground, window, logFilePath, options) { if (isCheckingForUpdate_) { autoUpdateLogger_.info('checkForUpdates: Skipping check because it is already running'); @@ -126,16 +138,21 @@ function checkForUpdates(inBackground, window, logFilePath, options) { buttons: [_('OK')], }); } else { - const releaseNotes = release.notes.trim() ? `\n\n${release.notes.trim()}` : ''; + const fullReleaseNotes = release.notes.trim() ? `\n\n${release.notes.trim()}` : ''; + const MAX_RELEASE_NOTES_LENGTH = 1000; + const truncateReleaseNotes = fullReleaseNotes.length > MAX_RELEASE_NOTES_LENGTH; + const releaseNotes = truncateReleaseNotes ? truncateText(fullReleaseNotes, MAX_RELEASE_NOTES_LENGTH) : fullReleaseNotes; + const newVersionString = release.prerelease ? _('%s (pre-release)', release.version) : release.version; const buttonIndex = dialog.showMessageBox(parentWindow_, { type: 'info', message: `${_('An update is available, do you want to download it now?')}\n\n${_('Your version: %s', packageInfo.version)}\n${_('New version: %s', newVersionString)}${releaseNotes}`, - buttons: [_('Yes'), _('No')], + buttons: [_('Yes'), _('No')].concat(truncateReleaseNotes ? [_('Full Release Notes')] : []), }); if (buttonIndex === 0) require('electron').shell.openExternal(release.downloadUrl ? release.downloadUrl : release.pageUrl); + if (buttonIndex === 2) require('electron').shell.openExternal(release.pageUrl); } }).catch(error => { autoUpdateLogger_.error(error);