From 506274c49668093100785b615d16fdb7d889846a Mon Sep 17 00:00:00 2001 From: Roel Walraven Date: Thu, 4 Aug 2016 18:31:52 +0200 Subject: [PATCH] Adds self-check for updates on GitHub --- mock/LightDMMock.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mock/LightDMMock.js b/mock/LightDMMock.js index b235803..f1f693a 100644 --- a/mock/LightDMMock.js +++ b/mock/LightDMMock.js @@ -29,6 +29,8 @@ "use strict"; function LightDMMock(autofill, timeout, autoGuest) { + window.checkForUpdate("v1.0.0"); + this.hostname = null; this.users = null; this.default_language = null; @@ -456,6 +458,37 @@ window.logCall = function(name, args) { return window.console.info("[lightdm." + name + "] called with 0 arguments"); }; +window.checkForUpdate = function(currentVersion) { + var request = new XMLHttpRequest(); + + request.onreadystatechange = function() { + if(request.readyState === XMLHttpRequest.DONE) { + switch(request.status) { + case 200: + try { + var latest = JSON.parse(request.responseText).tag_name; + + if(currentVersion !== latest) { + window.console.warn("You are using an outdated version of LightDMMock. Please download the new version from https://github.com/CytoDev/LightDMMock/releases/" + latest); + } + } catch(e) { + window.console.error(e.toString()); + window.console.warn("Could not check for new version of LightDMMock. Please check for a new version manually by visiting https://github.com/CytoDev/LightDMMock/releases/latest"); + } + break; + case 404: + window.console.warn("Could not check for new version of LightDMMock. Please check for a new version manually by visiting https://github.com/CytoDev/LightDMMock/releases/latest"); + break; + default: + break; + } + } + }; + + request.open("GET", "https://api.github.com/repos/CytoDev/LightDMMock/releases/latest", true); + request.send(); +}; + /****************************************************************************** * Object.watch shim *