From 7ad91a71613df363e4a9fde39ccfae218f8d8b94 Mon Sep 17 00:00:00 2001 From: "Michael P. Geraci" Date: Sun, 22 Jan 2017 12:02:49 -0500 Subject: [PATCH] add a hard-refresh option --- README.md | 3 +++ auto-hud.py | 2 ++ static/js/AutoHUD.coffee | 12 ++++++++++++ static/js/build.js | 11 ++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cffa5e6..4eeaa8e 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,9 @@ project root. You'll also need to obtain a free api key for # swap the css, js, or templates VERSION = "0.000" +# how often the entire page should hard refresh (0 for no refreshing) +REFRESH_TIME = 10000 + # your info for forecast.io FORECASTIO_API_KEY = "" FORECASTIO_LAT_LONG = "40.676423,-73.980488" diff --git a/auto-hud.py b/auto-hud.py index ec96ea6..8915941 100644 --- a/auto-hud.py +++ b/auto-hud.py @@ -7,6 +7,7 @@ # secret settings from localsettings import VERSION +from localsettings import REFRESH_TIME from localsettings import BIRTHDAYS from localsettings import CHORES from localsettings import FORECASTIO_API_KEY @@ -23,6 +24,7 @@ def index_route(params={}): return render_template('index.html', params = { 'version': VERSION, + 'refreshTime': REFRESH_TIME, 'C': C, 'forecastioApiKey': FORECASTIO_API_KEY, 'forecastioLatLong': FORECASTIO_LAT_LONG, diff --git a/static/js/AutoHUD.coffee b/static/js/AutoHUD.coffee index 37789ff..b61c184 100644 --- a/static/js/AutoHUD.coffee +++ b/static/js/AutoHUD.coffee @@ -24,6 +24,7 @@ window.AutoHUD = { @controller.init() @watchVersion(params) + @watchRefershTime(params.refreshTime) # versioning @@ -56,4 +57,15 @@ window.AutoHUD = { # if the version has updated, refresh the page if data.version != @version window.location.reload() + + + # hard refresher + ############################################################################# + + watchRefershTime: (time) -> + return if !time + + setTimeout(-> + window.location.reload() + , time) } diff --git a/static/js/build.js b/static/js/build.js index 06e307d..d572338 100644 --- a/static/js/build.js +++ b/static/js/build.js @@ -14,7 +14,8 @@ window.AutoHUD = { this.model.set(params); this.view.init(); this.controller.init(); - return this.watchVersion(params); + this.watchVersion(params); + return this.watchRefershTime(params.refreshTime); }, watchVersion: function(params) { if (params.version == null) { @@ -55,6 +56,14 @@ window.AutoHUD = { if (data.version !== this.version) { return window.location.reload(); } + }, + watchRefershTime: function(time) { + if (!time) { + return; + } + return setTimeout(function() { + return window.location.reload(); + }, time); } };