Update AppManager & app timer 91/160391/3
authorjaekuk, lee <juku1999@samsung.com>
Thu, 16 Nov 2017 04:01:43 +0000 (13:01 +0900)
committerjaekuk, lee <juku1999@samsung.com>
Thu, 16 Nov 2017 06:21:30 +0000 (15:21 +0900)
Change-Id: Id3d9ab73a4a9851024db9e95936bf826f08762c2
Signed-off-by: jaekuk, lee <juku1999@samsung.com>
wrt/wrt_support/extensions_repo/app_timer/contentscript.js
wrt/wrt_support/extensions_repo/app_timer/style.css
wrt/wrt_support/sample/wgt/AppManager.wgt

index c27a870..3f877bf 100755 (executable)
@@ -6,8 +6,19 @@ const EXIT_HTML = '\
 </div>';
 //"
 
-var defaultTime = {hours: 0, minutes: 0, seconds: 10};
-var jsonfile = require('jsonfile')
+const TIME_HTML = '\
+<div id="time-container"> \
+<center><div id="time-contents"> \
+<span id="hours-digit">00</span> \
+<span class="colon">:</span> \
+<span id="minutes-digit">00</span> \
+<span class="colon">:</span> \
+<span id="seconds-digit">00</span> \
+</div></center> \
+</div>';
+
+var jsonfile = require('jsonfile');
+var jsonobj = {timerStart: false, time:{hours: 0, minutes: 0, seconds: 0}};
 var filepath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('apps_repo'))+'apps_repo/AppManager/data/timer.json';
 var app_id = location.href.split('/');
 
@@ -19,6 +30,12 @@ port.onMessage.addListener(function(msg) {
   }
   else if (msg.background == "timer-update") {
     console.log('value, '+msg.value.time.hours+' : '+msg.value.time.minutes+' : '+msg.value.time.seconds);
+    jsonobj.time.hours = msg.value.time.hours;
+    jsonobj.time.minutes = msg.value.time.minutes;
+    jsonobj.time.seconds = msg.value.time.seconds;
+    document.getElementById('hours-digit').innerHTML = jsonobj.time.hours;
+    document.getElementById('minutes-digit').innerHTML = jsonobj.time.minutes;
+    document.getElementById('seconds-digit').innerHTML = jsonobj.time.seconds;
   }
   else if (msg.background == "timer-finish") {
     exitPopup();
@@ -34,22 +51,46 @@ jsonfile.readFile(filepath, function(err, obj) {
     return;
   }
   if (obj.timerStart==true) {
+    console.log('exitPopup: '+window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')));
+    jsonobj = obj;
+    if (obj.time.hours + obj.time.minutes + obj.time.seconds > 0) {
+      initialize();
+    }
+    else {
+      exitPopup();
+    }
+  }
+});
 
-       console.log('exitPopup: '+window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')));
-
+window.onbeforeunload = function() {
+  if (app_id[app_id.length - 2] == 'installer'
+    || app_id[app_id.length - 2] == 'launcher'
+    || app_id[app_id.length - 2] == 'extensions_settings'
+    || app_id[app_id.length - 2] == 'AppManager') {
+    console.log('Except for '+app_id[app_id.length - 2]);
+    return;
+  }
+  stop();
+}
 
-       
-    defaultTime = obj.time;
-    initialize();
+window.onkeydown = function(event) {
+  if (app_id[app_id.length - 2] == 'installer'
+    || app_id[app_id.length - 2] == 'launcher'
+    || app_id[app_id.length - 2] == 'extensions_settings'
+    || app_id[app_id.length - 2] == 'AppManager') {
+    console.log('Except for '+app_id[app_id.length - 2]);
+    return;
   }
-});
+  if (event.keyCode === 10009){   //esc
+    stop();
+  }
+}
 
 function exitPopup() {
   document.body.insertAdjacentHTML('beforeend', EXIT_HTML);
+  stop();
   document.getElementById('exit-img').onclick= function(event) {
     console.log('exitPopup: ');
-    reset();
-    stop();
     var launcher = require('electron').remote.getCurrentWindow();
     launcher.close();
   };
@@ -61,12 +102,10 @@ function initialize() {
 }
 
 function start() {
-  var time = defaultTime;
-  console.log('start, '+time.hours+' : '+time.minutes+' : '+time.seconds);
-  if (time.hours + time.minutes + time.seconds > 0) {
-    port.postMessage({contentscript: "timer-setTime", value:defaultTime});
-    port.postMessage({contentscript: "timer-start"});
-  }
+  console.log('start, '+jsonobj.time.hours+' : '+jsonobj.time.minutes+' : '+jsonobj.time.seconds);
+  document.body.insertAdjacentHTML('beforebegin', TIME_HTML);
+  port.postMessage({contentscript: "timer-setTime", value:jsonobj.time});
+  port.postMessage({contentscript: "timer-start"});
 }
 
 function reset() {
@@ -75,11 +114,14 @@ function reset() {
 
 function stop() {
   port.postMessage({contentscript: "timer-stop"});
+  jsonfile.writeFile(filepath, jsonobj, function (err) {
+    console.error(err);
+  });
 }
 
 function setTime(time) {
   console.log('setTime, '+time.defaultTime.hours+' : '+time.defaultTime.minutes+' : '+time.defaultTime.seconds);
-  defaultTime.hours = time.defaultTime.hours;
-  defaultTime.minutes = time.defaultTime.minutes;
-  defaultTime.seconds = time.defaultTime.seconds;
+  jsonobj.time.hours = time.defaultTime.hours;
+  jsonobj.time.minutes = time.defaultTime.minutes;
+  jsonobj.time.seconds = time.defaultTime.seconds;
 }
index f24b663..20f5417 100755 (executable)
   width: 400px;
   background-color: rgb(255,255,255);
   cursor: pointer;
-}
\ No newline at end of file
+}
+/*----------------------------------------------------*/
+#time-container {
+  margin-top: 2%;
+  margin-left: 2%;
+  height: auto;
+  width: 100px;
+  background: rgb(255,255,255);
+}
+
+#timer-contents {
+  font-weight: bold;
+  font-size: 20px;
+  padding: 5px;
+  text-align: center;
+}
+
+.colon {
+  display: inline-block;
+  vertical-align: top;
+}
+
+.digit {
+  vertical-align: middle;
+}
index b19d908..27f3e8d 100755 (executable)
Binary files a/wrt/wrt_support/sample/wgt/AppManager.wgt and b/wrt/wrt_support/sample/wgt/AppManager.wgt differ