From 8ff2418b028f9f5fe40ccbdb6ffc122c684e4164 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 11 Jan 2019 23:40:05 +0000 Subject: [PATCH] Desktop: Added support for pre-releases --- ElectronClient/app/app.js | 4 +-- ElectronClient/app/bridge.js | 4 +-- ElectronClient/app/checkForUpdates.js | 42 +++++++++++++++++++------ ReactNativeClient/lib/models/Setting.js | 1 + Tools/release-electron.js | 2 +- readme/prereleases.md | 9 ++++++ 6 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 readme/prereleases.md diff --git a/ElectronClient/app/app.js b/ElectronClient/app/app.js index fa294db9717..c3c41458804 100644 --- a/ElectronClient/app/app.js +++ b/ElectronClient/app/app.js @@ -589,7 +589,7 @@ class Application extends BaseApplication { }, { label: _('Check for updates...'), click: () => { - bridge().checkForUpdates(false, bridge().window(), this.checkForUpdateLoggerPath()); + bridge().checkForUpdates(false, bridge().window(), this.checkForUpdateLoggerPath(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') }); } }, { type: 'separator', @@ -772,7 +772,7 @@ class Application extends BaseApplication { if (shim.isWindows() || shim.isMac()) { const runAutoUpdateCheck = () => { if (Setting.value('autoUpdateEnabled')) { - bridge().checkForUpdates(true, bridge().window(), this.checkForUpdateLoggerPath()); + bridge().checkForUpdates(true, bridge().window(), this.checkForUpdateLoggerPath(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') }); } } diff --git a/ElectronClient/app/bridge.js b/ElectronClient/app/bridge.js index f98cc9d1071..ac2a122eb19 100644 --- a/ElectronClient/app/bridge.js +++ b/ElectronClient/app/bridge.js @@ -116,9 +116,9 @@ class Bridge { return require('electron').shell.openItem(fullPath) } - checkForUpdates(inBackground, window, logFilePath) { + checkForUpdates(inBackground, window, logFilePath, options) { const { checkForUpdates } = require('./checkForUpdates.js'); - checkForUpdates(inBackground, window, logFilePath); + checkForUpdates(inBackground, window, logFilePath, options); } } diff --git a/ElectronClient/app/checkForUpdates.js b/ElectronClient/app/checkForUpdates.js index 33877d65c67..9e0ecc92e93 100644 --- a/ElectronClient/app/checkForUpdates.js +++ b/ElectronClient/app/checkForUpdates.js @@ -29,15 +29,35 @@ function onCheckEnded() { isCheckingForUpdate_ = false; } -async function fetchLatestRelease() { - const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases/latest'); +async function fetchLatestRelease(options) { + options = Object.assign({}, { includePreReleases: false }, options); - if (!response.ok) { - const responseText = await response.text(); - throw new Error('Cannot get latest release info: ' + responseText.substr(0,500)); - } + let json = null; + + if (options.includePreReleases) { + // This end-point will include all releases, including pre-releases (but not draft), so we take + // whatever is the latest release. It might be the same as releases/latest, or it might be + // a pre-release. + const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases'); + + if (!response.ok) { + const responseText = await response.text(); + throw new Error('Cannot get latest release info: ' + responseText.substr(0,500)); + } + + json = await response.json(); + if (!json.length) throw new Error('Cannot get latest release info: ' + responseText.substr(0,500)); + json = json[0]; + } else { + const response = await fetch('https://api.github.com/repos/laurent22/joplin/releases/latest'); - const json = await response.json(); + if (!response.ok) { + const responseText = await response.text(); + throw new Error('Cannot get latest release info: ' + responseText.substr(0,500)); + } + + json = await response.json(); + } const version = json.tag_name.substr(1); let downloadUrl = null; @@ -69,10 +89,11 @@ async function fetchLatestRelease() { downloadUrl: downloadUrl, notes: json.body, pageUrl: json.html_url, + prerelease: json.prerelease, }; } -function checkForUpdates(inBackground, window, logFilePath) { +function checkForUpdates(inBackground, window, logFilePath, options) { if (isCheckingForUpdate_) { autoUpdateLogger_.info('checkForUpdates: Skipping check because it is already running'); return; @@ -91,9 +112,12 @@ function checkForUpdates(inBackground, window, logFilePath) { checkInBackground_ = inBackground; - fetchLatestRelease().then(release => { + autoUpdateLogger_.info('checkForUpdates: Checking with options ' + JSON.stringify(options)); + + fetchLatestRelease(options).then(release => { autoUpdateLogger_.info('Current version: ' + packageInfo.version); autoUpdateLogger_.info('Latest version: ' + release.version); + autoUpdateLogger_.info('Is Pre-release:', release.prerelease); if (compareVersions(release.version, packageInfo.version) <= 0) { if (!checkInBackground_) dialog.showMessageBox({ message: _('Current version is up-to-date.') }) diff --git a/ReactNativeClient/lib/models/Setting.js b/ReactNativeClient/lib/models/Setting.js index 21c2946de50..7e320c39363 100644 --- a/ReactNativeClient/lib/models/Setting.js +++ b/ReactNativeClient/lib/models/Setting.js @@ -105,6 +105,7 @@ class Setting extends BaseModel { 'style.editor.fontSize': {value: 12, type: Setting.TYPE_INT, public: true, appTypes: ['desktop'], label: () => _('Editor font size'), minimum: 4, maximum: 50, step: 1}, 'style.editor.fontFamily': {value: "", type: Setting.TYPE_STRING, public: true, appTypes: ['desktop'], label: () => _('Editor font family'), description: () => _('This must be *monospace* font or it will not work properly. If the font is incorrect or empty, it will default to a generic monospace font.')}, 'autoUpdateEnabled': { value: true, type: Setting.TYPE_BOOL, public: true, appTypes: ['desktop'], label: () => _('Automatically update the application') }, + 'autoUpdate.includePreReleases': { value: false, type: Setting.TYPE_BOOL, public: true, appTypes: ['desktop'], label: () => _('Get pre-releases when checking for updates'), description: () => _('See the pre-release page for more details: %s', 'https://joplin.cozic.net/prereleases') }, 'clipperServer.autoStart': { value: false, type: Setting.TYPE_BOOL, public: false }, 'sync.interval': { value: 300, type: Setting.TYPE_INT, isEnum: true, public: true, label: () => _('Synchronisation interval'), options: () => { return { diff --git a/Tools/release-electron.js b/Tools/release-electron.js index 4e055e6820f..833c75e122a 100644 --- a/Tools/release-electron.js +++ b/Tools/release-electron.js @@ -24,7 +24,7 @@ async function main() { const releaseOptions = { isDraft: true, isPreRelease: !!argv.beta }; - console.info('Release options: ' + releaseOptions); + console.info('Release options: ', releaseOptions); const release = await githubRelease('joplin', tagName, releaseOptions); diff --git a/readme/prereleases.md b/readme/prereleases.md new file mode 100644 index 00000000000..60ce80e38bd --- /dev/null +++ b/readme/prereleases.md @@ -0,0 +1,9 @@ +# Getting pre-releases + +Pre-releases are available for the desktop application. They are pretty much like regular releases, except that they have not yet been tested by many users, so it is possible that a bug or two went through. + +You can help the development of Joplin by choosing to receive these early releases when updating the application. If you find any bug or other issue, you may report it [on the forum](https://discourse.joplin.cozic.net/) or [GitHub](https://github.com/laurent22/joplin/issues). + +In general it is safe to use these pre-releases (they do not include any experimental or unstable features). In fact most pre-release eventually become regular releases after a few days. + +To have access to these pre-releases, simply go to **Configuration screen** and tick the box "**Also get pre-releases when checking for updates**". \ No newline at end of file