Skip to content

Commit

Permalink
Merge pull request #27 from derekantrican/Updater
Browse files Browse the repository at this point in the history
Updater
  • Loading branch information
derekantrican committed Feb 15, 2019
2 parents 572965d + f53fb77 commit d34fb61
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function Install(){
var vtimezone;

function main(){
CheckForUpdate();

//Get URL items
var response = UrlFetchApp.fetch(sourceCalendarURL).getContentText();
Expand Down Expand Up @@ -311,3 +312,26 @@ function ParseNotificationTime(notificationString){
function sameEvent(x){
return x.id == this;
}

function CheckForUpdate(){
var alreadyAlerted = PropertiesService.getScriptProperties().getProperty("alertedForNewVersion");
if (alreadyAlerted == null){
try{
var thisVersion = 2.0;
var html = UrlFetchApp.fetch("https://github.com/derekantrican/GAS-ICS-Sync/releases");
var regex = RegExp("<a.*title=\"\\d\\.\\d\">","g");
var latestRelease = regex.exec(html)[0];
regex = RegExp("\"(\\d.\\d)\"", "g");
var latestVersion = Number(regex.exec(latestRelease)[1]);

if (latestVersion > thisVersion){
if (email != ""){
GmailApp.sendEmail(email, "New version of GAS-ICS-Sync is available!", "There is a new version of \"GAS-ICS-Sync\". You can see the latest release here: https://github.com/derekantrican/GAS-ICS-Sync/releases");

PropertiesService.getScriptProperties().setProperty("alertedForNewVersion", true);
}
}
}
catch(e){}
}
}

0 comments on commit d34fb61

Please sign in to comment.