-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic update checking and an update README to reflect this
- Loading branch information
1 parent
c688ab1
commit 65f4d7e
Showing
5 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
const appversion = "1.2.1" | ||
const appversion = "1.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This file is not intended to run by itself, but is inserted into main.js | ||
|
||
async function fetchAsync(url) { | ||
let response = await fetch(url); | ||
let data = await response.json(); | ||
return data; | ||
} | ||
|
||
function semanticVersionCompare(a, b) { | ||
// from https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb | ||
if (a.startsWith(b + "-")) return -1 | ||
if (b.startsWith(a + "-")) return 1 | ||
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" }) | ||
} | ||
|
||
async function checkForUpdate() { | ||
tags = await fetchAsync("https://api.github.com/repos/fjwillemsen/NativeOverleaf/tags") | ||
latest_version = tags[0].name.replace('v', '') | ||
comparison = semanticVersionCompare(latest_version, appversion) | ||
if (comparison == 0 && comparison !== "") { | ||
console.log("Update check completed, no update available.") | ||
} else if (comparison == 1) { | ||
goToUpdate = confirm(`Update available! | ||
Current: ${appversion}, latest: ${latest_version}. | ||
Go to downloads page?`) | ||
if (goToUpdate) { | ||
window.open("https://github.com/fjwillemsen/NativeOverleaf/releases/tag/v1.2.0") | ||
} | ||
} else if (comparison == -1) { | ||
console.warn(`No update needed, current version (${appversion}) is newer than latest publicly available version (${latest_version}).`) | ||
} else { | ||
console.error(`Invalid semantic version comparison outcome: ${comparison}`) | ||
} | ||
} | ||
|
||
function setAutoUpdateChecking() { | ||
// check for updates straight away | ||
checkForUpdate() | ||
// check for updates every six hours | ||
setInterval(checkForUpdate, 6*60*60*1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters