1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Desktop: Fixed macOS version check so that it does not return the ARM64 version

This commit is contained in:
Laurent Cozic 2023-07-12 15:18:05 +01:00
parent 9ae4401564
commit 1abfb1cb0e
5 changed files with 4189 additions and 98 deletions

View File

@ -358,6 +358,8 @@ packages/app-desktop/services/sortOrder/notesSortOrderUtils.js
packages/app-desktop/services/sortOrder/notesSortOrderUtils.test.js packages/app-desktop/services/sortOrder/notesSortOrderUtils.test.js
packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.js packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.js
packages/app-desktop/tools/notarizeMacApp.js packages/app-desktop/tools/notarizeMacApp.js
packages/app-desktop/utils/checkForUpdatesUtils.js
packages/app-desktop/utils/checkForUpdatesUtils.test.js
packages/app-desktop/utils/markupLanguageUtils.js packages/app-desktop/utils/markupLanguageUtils.js
packages/app-mobile/PluginAssetsLoader.js packages/app-mobile/PluginAssetsLoader.js
packages/app-mobile/components/ActionButton.js packages/app-mobile/components/ActionButton.js

2
.gitignore vendored
View File

@ -343,6 +343,8 @@ packages/app-desktop/services/sortOrder/notesSortOrderUtils.js
packages/app-desktop/services/sortOrder/notesSortOrderUtils.test.js packages/app-desktop/services/sortOrder/notesSortOrderUtils.test.js
packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.js packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.js
packages/app-desktop/tools/notarizeMacApp.js packages/app-desktop/tools/notarizeMacApp.js
packages/app-desktop/utils/checkForUpdatesUtils.js
packages/app-desktop/utils/checkForUpdatesUtils.test.js
packages/app-desktop/utils/markupLanguageUtils.js packages/app-desktop/utils/markupLanguageUtils.js
packages/app-mobile/PluginAssetsLoader.js packages/app-mobile/PluginAssetsLoader.js
packages/app-mobile/components/ActionButton.js packages/app-mobile/components/ActionButton.js

View File

@ -3,8 +3,8 @@ import Logger from '@joplin/lib/Logger';
import { _ } from '@joplin/lib/locale'; import { _ } from '@joplin/lib/locale';
import bridge from './services/bridge'; import bridge from './services/bridge';
import KvStore from '@joplin/lib/services/KvStore'; import KvStore from '@joplin/lib/services/KvStore';
const { fileExtension } = require('@joplin/lib/path-utils');
import * as ArrayUtils from '@joplin/lib/ArrayUtils'; import * as ArrayUtils from '@joplin/lib/ArrayUtils';
import { CheckForUpdateOptions, extractVersionInfo, GitHubRelease } from './utils/checkForUpdatesUtils';
const packageInfo = require('./packageInfo.js'); const packageInfo = require('./packageInfo.js');
const compareVersions = require('compare-versions'); const compareVersions = require('compare-versions');
@ -13,10 +13,6 @@ const logger = Logger.create('checkForUpdates');
let checkInBackground_ = false; let checkInBackground_ = false;
let isCheckingForUpdate_ = false; let isCheckingForUpdate_ = false;
interface CheckForUpdateOptions {
includePreReleases?: boolean;
}
function onCheckStarted() { function onCheckStarted() {
logger.info('Starting...'); logger.info('Starting...');
isCheckingForUpdate_ = true; isCheckingForUpdate_ = true;
@ -27,15 +23,7 @@ function onCheckEnded() {
isCheckingForUpdate_ = false; isCheckingForUpdate_ = false;
} }
function getMajorMinorTagName(tagName: string) { async function fetchLatestRelease() {
const s = tagName.split('.');
s.pop();
return s.join('.');
}
async function fetchLatestRelease(options: CheckForUpdateOptions) {
options = { includePreReleases: false, ...options };
const response = await shim.fetch('https://api.github.com/repos/laurent22/joplin/releases'); const response = await shim.fetch('https://api.github.com/repos/laurent22/joplin/releases');
if (!response.ok) { if (!response.ok) {
@ -43,89 +31,7 @@ async function fetchLatestRelease(options: CheckForUpdateOptions) {
throw new Error(`Cannot get latest release info: ${responseText.substr(0, 500)}`); throw new Error(`Cannot get latest release info: ${responseText.substr(0, 500)}`);
} }
const releases = await response.json(); return (await response.json()) as GitHubRelease[];
if (!releases.length) throw new Error('Cannot get latest release info (JSON)');
let release = null;
if (options.includePreReleases) {
release = releases[0];
} else {
for (const r of releases) {
if (!r.prerelease) {
release = r;
break;
}
}
}
if (!release) throw new Error('Could not get tag name');
const version = release.tag_name.substr(1);
// We concatenate all the release notes of the major/minor versions
// corresponding to the latest version. For example, if the latest version
// is 1.8.3, we concatenate all the 1.8.x versions. This is so that no
// matter from which version you upgrade, you always see the full changes,
// with the latest changes being on top.
const fullReleaseNotes = [];
const majorMinorTagName = getMajorMinorTagName(release.tag_name);
for (const release of releases) {
if (getMajorMinorTagName(release.tag_name) === majorMinorTagName) {
fullReleaseNotes.push(release.body.trim());
}
}
let downloadUrl = null;
const platform = process.platform;
for (let i = 0; i < release.assets.length; i++) {
const asset = release.assets[i];
let found = false;
const ext = fileExtension(asset.name);
if (platform === 'win32' && ext === 'exe') {
if (shim.isPortable()) {
found = asset.name === 'JoplinPortable.exe';
} else {
found = !!asset.name.match(/^Joplin-Setup-[\d.]+\.exe$/);
}
} else if (platform === 'darwin' && ext === 'dmg') {
found = true;
} else if (platform === 'linux' && ext === '.AppImage') {
found = true;
}
if (found) {
downloadUrl = asset.browser_download_url.replace('github.com/laurent22/joplin/releases/download', 'objects.joplinusercontent.com');
downloadUrl.concat('?source=DesktopApp&type=Update');
break;
}
}
function cleanUpReleaseNotes(releaseNotes: string[]) {
const lines = releaseNotes.join('\n\n* * *\n\n').split('\n');
const output = [];
for (const line of lines) {
const r = line
.replace(/\(#.* by .*\)/g, '') // Removes issue numbers and names - (#3157 by [@user](https://github.com/user))
.replace(/\([0-9a-z]{7}\)/g, '') // Removes commits - "sync state or data (a6caa35)"
.replace(/\(#[0-9]+\)/g, '') // Removes issue numbers - "(#4727)"
.replace(/ {2}/g, ' ')
.trim();
output.push(r);
}
return output.join('\n');
}
return {
version: version,
downloadUrl: downloadUrl,
notes: cleanUpReleaseNotes(fullReleaseNotes),
pageUrl: release.html_url,
prerelease: release.prerelease,
};
} }
function truncateText(text: string, length: number) { function truncateText(text: string, length: number) {
@ -170,7 +76,8 @@ export default async function checkForUpdates(inBackground: boolean, parentWindo
logger.info(`Checking with options ${JSON.stringify(options)}`); logger.info(`Checking with options ${JSON.stringify(options)}`);
try { try {
const release = await fetchLatestRelease(options); const releases = await fetchLatestRelease();
const release = extractVersionInfo(releases, process.platform, options);
logger.info(`Current version: ${packageInfo.version}`); logger.info(`Current version: ${packageInfo.version}`);
logger.info(`Latest version: ${release.version}`); logger.info(`Latest version: ${release.version}`);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,119 @@
import { fileExtension } from '@joplin/lib/path-utils';
import shim from '@joplin/lib/shim';
export interface CheckForUpdateOptions {
includePreReleases?: boolean;
}
export interface GitHubRelease {
tag_name: string;
prerelease: boolean;
body: string;
assets: {
name: string;
browser_download_url: string;
}[];
html_url: string;
}
interface Release {
version: string;
prerelease: boolean;
downloadUrl: string;
notes: string;
pageUrl: string;
}
function getMajorMinorTagName(tagName: string) {
const s = tagName.split('.');
s.pop();
return s.join('.');
}
export const extractVersionInfo = (releases: GitHubRelease[], platform: typeof process.platform, options: CheckForUpdateOptions) => {
options = { includePreReleases: false, ...options };
if (!releases.length) throw new Error('Cannot get latest release info (JSON)');
let release = null;
if (options.includePreReleases) {
release = releases[0];
} else {
for (const r of releases) {
if (!r.prerelease) {
release = r;
break;
}
}
}
if (!release) throw new Error('Could not get tag name');
const version = release.tag_name.substr(1);
// We concatenate all the release notes of the major/minor versions
// corresponding to the latest version. For example, if the latest version
// is 1.8.3, we concatenate all the 1.8.x versions. This is so that no
// matter from which version you upgrade, you always see the full changes,
// with the latest changes being on top.
const fullReleaseNotes = [];
const majorMinorTagName = getMajorMinorTagName(release.tag_name);
for (const release of releases) {
if (getMajorMinorTagName(release.tag_name) === majorMinorTagName) {
fullReleaseNotes.push(release.body.trim());
}
}
let downloadUrl = null;
for (let i = 0; i < release.assets.length; i++) {
const asset = release.assets[i];
let found = false;
const ext = fileExtension(asset.name);
if (platform === 'win32' && ext === 'exe') {
if (shim.isPortable()) {
found = asset.name === 'JoplinPortable.exe';
} else {
found = !!asset.name.match(/^Joplin-Setup-[\d.]+\.exe$/);
}
} else if (platform === 'darwin' && ext === 'dmg' && !asset.name.endsWith('arm64.dmg')) { // We don't return the arm64 version for now
found = true;
} else if (platform === 'linux' && ext === '.AppImage') {
found = true;
}
if (found) {
downloadUrl = asset.browser_download_url.replace('github.com/laurent22/joplin/releases/download', 'objects.joplinusercontent.com');
downloadUrl.concat('?source=DesktopApp&type=Update');
break;
}
}
function cleanUpReleaseNotes(releaseNotes: string[]) {
const lines = releaseNotes.join('\n\n* * *\n\n').split('\n');
const output = [];
for (const line of lines) {
const r = line
.replace(/\(#.* by .*\)/g, '') // Removes issue numbers and names - (#3157 by [@user](https://github.com/user))
.replace(/\([0-9a-z]{7}\)/g, '') // Removes commits - "sync state or data (a6caa35)"
.replace(/\(#[0-9]+\)/g, '') // Removes issue numbers - "(#4727)"
.replace(/ {2}/g, ' ')
.trim();
output.push(r);
}
return output.join('\n');
}
const output: Release = {
version: version,
downloadUrl: downloadUrl,
notes: cleanUpReleaseNotes(fullReleaseNotes),
pageUrl: release.html_url,
prerelease: release.prerelease,
};
return output;
};