Skip to content

Fixes nathanp/crypto-price-widget#67 #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ul {
.coin-list li span.draggable {
width: 100%;
}
.coin-list input[type="number"] {
.coin-list input[type="number"], .update-interval {
border: none;
padding: 5px;
background: rgba(0, 0, 0, 0);
Expand Down
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ <h3>Choose Your Base Currency</h3>
</label>
</div>

<div class="checkbox-wrapper">
<input id="update-interval" class="update-interval" name="update-interval" min="5" max="1000" step="1" value="5" type="number">
<label class="">
Update interval in seconds
<div></div>
</label>
</div>

<h3>Tip Jar</h3>
<ul id="tips">
<li>BTC: 17iENfaJkEpxGXW7mgdFh9hGMZV65R2zVL</li>
Expand Down
32 changes: 30 additions & 2 deletions js/app_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ const remote = require("electron").remote;
//user settings
const settings = require("electron-settings");

// update interval
var appRefresh; // refresh timer handle
var update_interval = 5;
var update_interval_element = document.getElementById("update-interval")
if (settings.has("user.updateInterval")) {
update_interval = settings.get("user.updateInterval");
update_interval_element.value = update_interval;
} else {
settings.set("user.updateInterval", update_interval); // 5 seconds by default
}

//default coins
if (settings.has("user.coins")) {
//do nothing because coins already set
Expand Down Expand Up @@ -311,10 +322,15 @@ function updateData() {
}); //response.json().then
} //function(response)
); //then
refreshUpdateInterval()
} //updateData()

function refreshUpdateInterval () { // clears timeout and reload prices page
clearTimeout(appRefresh); // clears older timeout
appRefresh = setTimeout(function () {
updateData();
}, 5000); // run this once every 5 seconds
} //updateData()
}, update_interval * 1000); // run this once every user assigned seconds
}

// Let's do this thing!
initData();
Expand Down Expand Up @@ -474,6 +490,18 @@ pinCheck.onclick = function (event) {
}
};

/***********
* UPDATE INTERVAL
*************/
update_interval_element.onchange = function (event) { // saves user update interval
let input = event.target;
input.value = Math.round(input.value);
input.value = Math.max(5, Math.min(input.value, 1000)); // clamps between 5 and 1000
settings.set("user.updateInterval", input.value);
update_interval = input.value;
refreshUpdateInterval()
}

/*******
* APP UI
********/
Expand Down