From cafd0073f0a5a0fce8d3ef1c9b19b132338aa8c7 Mon Sep 17 00:00:00 2001
From: Agnibho Mondal <mail@agnibho.com>
Date: Mon, 5 Dec 2016 16:27:04 +0530
Subject: [PATCH] Version code correction

---
 index.html       |  2 +-
 src/Settings.vue |  2 +-
 src/routine.js   | 21 ++++++++++++++++++++-
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/index.html b/index.html
index 0cab821..2f1f5cb 100755
--- a/index.html
+++ b/index.html
@@ -32,7 +32,7 @@
 	<meta charset="utf-8">
 	<meta name="viewport" content="width=device-width, initial-scale=1.0">
 	<script>
-	 var VERSION=2.1;
+	 var VERSION="2.1.0";
 	</script>
 	<style>
 	 .loader {
diff --git a/src/Settings.vue b/src/Settings.vue
index b8732f8..fe87f12 100644
--- a/src/Settings.vue
+++ b/src/Settings.vue
@@ -61,7 +61,7 @@
 			    </div>
 			    <div id="about-text" class="panel-collapse collapse">
 				<div class="panel-body">
-				    <p><strong>ObsCalc 2.0</strong></p>
+				    <p><strong>ObsCalc <span class="version"></span></strong></p>
 				    <p>ObsCalc is a free and open source software published under GPL v3. It has been developed by Agnibho Mondal &lt;mail@agnibho.com&gt;.</p>
 				    <p><a href="https://code.agnibho.com/obscalc/">https://code.agnibho.com/obscalc/</a></p>
 				    <p>Copyright &copy; <span class="copyright" data-start="2016">2016</span> Agnibho Mondal</p>
diff --git a/src/routine.js b/src/routine.js
index bed583b..33be1c2 100644
--- a/src/routine.js
+++ b/src/routine.js
@@ -29,6 +29,9 @@ $(document).ready(function(){
     $(".loader").remove();
     $(".container").fadeIn();
 
+    //Insert version code
+    $(".version").text(VERSION);
+
     //Update copyright
     $(".copyright").each(function(){
 	if(new Date().getFullYear()>$(this).data("start")){
@@ -86,7 +89,23 @@ $(document).ready(function(){
 	$("#notify").width($(".container").width()-20);
     });
     $.get("https://code.agnibho.com/obscalc/info.json", function(data){
-	if(data.latest > VERSION){
+	var vCurr=VERSION.split(".").map(Number);
+	var vLtst=data.latest.split(".").map(Number);
+	function isBiggerThan(v1, v2){
+	    while(v1.length<v2.length){
+		v1.push(0);
+	    }
+	    while(v2.length<v1.length){
+		v2.push(0);
+	    }
+	    for(var i=0; i<v1.length; i++){
+		if(v1[i]>v2[i]){
+		    return true;
+		}
+	    }
+	    return false;
+	}
+	if(isBiggerThan(data.latest, VERSION)){
 	    $("#notify").slideDown();
 	    $("#notify").width($(".container").width()-20);
 	    $("#notify-text").text("A new version of ObsCalc is available.");
-- 
2.39.5