This repository has been archived by the owner on Mar 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from heb12/updater
Add Updating funtion
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,37 @@ | ||
// Update this version number for every release: | ||
const version = '0.1.0' | ||
let timesChecked = localStorage.getItem('timesChecked'); | ||
|
||
function checkUpdates() { | ||
console.log(timesChecked); | ||
url = 'https://heb12.github.io/updater/desktop/latest.json' + '?' + timesChecked; | ||
console.log(url); | ||
if (navigator.onLine) { | ||
console.log("Checking for updates..."); | ||
timesChecked = Number(timesChecked) + 1; | ||
localStorage.setItem('timesChecked', timesChecked); | ||
fetch(url) | ||
.then(response => response.text()) | ||
.then(result => { | ||
result = JSON.parse(result); | ||
if (result != '') { | ||
console.log(result); | ||
if (result.version != version) { | ||
console.log('This version is outdated. The newest version is ' + result.newest); | ||
document.getElementById('latestUpdate').innerHTML = 'Latest version: ' + result.version + ' (get the newest version from <span class="link">heb12.github.io/update</span>)'; | ||
document.getElementById('latestUpdate').style.display = 'block'; | ||
} else { | ||
console.log('Using latest version.'); | ||
document.getElementById('latestUpdate').innerHTML = 'Latest version: ' + result.version + ' (up to date)'; | ||
document.getElementById('latestUpdate').style.display = 'block'; | ||
} | ||
} else { | ||
// If for some reason the request returned as blank, it sends an error | ||
console.log('Error requesting information for program version ' + version); | ||
} | ||
}); | ||
} else { | ||
console.log('No internet connection!'); | ||
} | ||
return result; | ||
} |