Skip to content

Commit

Permalink
Desktop: Added support for pre-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jan 11, 2019
1 parent f6640bc commit 8ff2418
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ElectronClient/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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') });
}
}

Expand Down
4 changes: 2 additions & 2 deletions ElectronClient/app/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down
42 changes: 33 additions & 9 deletions ElectronClient/app/checkForUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.') })
Expand Down
1 change: 1 addition & 0 deletions ReactNativeClient/lib/models/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Tools/release-electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions readme/prereleases.md
Original file line number Diff line number Diff line change
@@ -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**".

0 comments on commit 8ff2418

Please sign in to comment.