fix: version diff
This commit is contained in:
parent
dabf0f13b1
commit
b043383ce1
@ -2,6 +2,7 @@
|
|||||||
const { app, Menu, dialog } = require("electron");
|
const { app, Menu, dialog } = require("electron");
|
||||||
const isMac = process.platform === "darwin";
|
const isMac = process.platform === "darwin";
|
||||||
const { autoUpdater } = require("electron-updater");
|
const { autoUpdater } = require("electron-updater");
|
||||||
|
import { compareSemanticVersions } from "./versionDiff";
|
||||||
|
|
||||||
const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
|
const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
|
||||||
...(isMac
|
...(isMac
|
||||||
@ -14,7 +15,13 @@ const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
|
|||||||
label: "Check for Updates...",
|
label: "Check for Updates...",
|
||||||
click: () =>
|
click: () =>
|
||||||
autoUpdater.checkForUpdatesAndNotify().then((e) => {
|
autoUpdater.checkForUpdatesAndNotify().then((e) => {
|
||||||
if (!e || e.updateInfo.files.length === 0)
|
if (
|
||||||
|
!e ||
|
||||||
|
compareSemanticVersions(
|
||||||
|
app.getVersion(),
|
||||||
|
e.updateInfo.version
|
||||||
|
) >= 0
|
||||||
|
)
|
||||||
dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
message: `There are currently no updates available.`,
|
message: `There are currently no updates available.`,
|
||||||
});
|
});
|
||||||
|
|||||||
21
electron/utils/versionDiff.ts
Normal file
21
electron/utils/versionDiff.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
export const compareSemanticVersions = (a: string, b: string) => {
|
||||||
|
|
||||||
|
// 1. Split the strings into their parts.
|
||||||
|
const a1 = a.split('.');
|
||||||
|
const b1 = b.split('.');
|
||||||
|
// 2. Contingency in case there's a 4th or 5th version
|
||||||
|
const len = Math.min(a1.length, b1.length);
|
||||||
|
// 3. Look through each version number and compare.
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
const a2 = +a1[ i ] || 0;
|
||||||
|
const b2 = +b1[ i ] || 0;
|
||||||
|
|
||||||
|
if (a2 !== b2) {
|
||||||
|
return a2 > b2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. We hit this if the all checked versions so far are equal
|
||||||
|
//
|
||||||
|
return b1.length - a1.length;
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user