Skip to content

Commit 1c8ef20

Browse files
committed
update notifier (close #177)
1 parent 787cbe2 commit 1c8ef20

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

addon_files/redmatic/www/js/script.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ $(document).ready(() => {
7979
let psTimeout;
8080
let psInterval = 5000;
8181

82+
function checkUpdate() {
83+
$.getJSON(`update_check.cgi?cmd=versions&sid=${sid}`, (current, success) => {
84+
$.get(`update_check.cgi?sid=${sid}`, (available, success) => {
85+
if (current.redmatic !== $.trim(available)) {
86+
$('#update-link').html(`<a href="https://github.com/rdmtc/RedMatic/releases/latest" target="_blank">download version ${available}</a>`);
87+
$('#update-notify').show();
88+
}
89+
});
90+
});
91+
92+
}
93+
94+
checkUpdate();
95+
8296
function pkg() {
8397
let packages;
8498
$.get(`pkg.cgi?sid=${sid}&cmd=repo`, data => {

addon_files/redmatic/www/settings.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@
4646

4747
<div class="tab-content" id="myTabContent">
4848
<div class="tab-pane fade show" id="configuration" role="tabpanel" aria-labelledby="configuration-tab">
49+
50+
<div id="update-notify" class="card mb-4" style="border-color: orange; display: none;">
51+
<div class="card-body">
52+
RedMatic update available: <span id="update-link"></span>
53+
</div>
54+
</div>
55+
4956
<div class="card mb-4">
57+
5058
<div class="card-body">
5159
<a id="link-red" role="button" class="btn btn-sm btn-outline-info" target="_blank" href="/addons/red/"><i class="fa fa-external-link-alt"></i> Node-RED</a>
5260
<a id="link-ui" role="button" class="btn btn-sm btn-outline-info mr-3" target="_blank" href="/addons/red/ui/"><i class="fa fa-external-link-alt"></i> Dashboard</a>

addon_files/redmatic/www/update_check.cgi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ catch {
1313
}
1414
}
1515

16-
puts -nonewline "Content-Type: text/html; charset=utf-8\r\n\r\n"
1716

1817
if { [info exists cmd ] && $cmd == "download"} {
18+
puts -nonewline "Content-Type: text/html; charset=utf-8\r\n\r\n"
1919
puts "<html><head><meta http-equiv='refresh' content='0; url=$downloadURL' /></head></html>"
20+
} elseif { [info exists cmd ] && $cmd == "versions" } {
21+
puts -nonewline "Content-Type: application/json; charset=utf-8\r\n\r\n"
22+
puts [ exec /usr/local/addons/redmatic/bin/redmaticVersions ]
2023
} else {
24+
puts -nonewline "Content-Type: text/html; charset=utf-8\r\n\r\n"
2125
catch {
2226
[regexp "tag_name\": \"v(\[0-9\]+\.\[0-9\]+\.\[0-9\]+(-\[a-zA-Z\]+.\[0-9\]+)?)" [ exec /usr/bin/env wget -qO- --no-check-certificate $checkURL ] dummy newversion]
2327
}

0 commit comments

Comments
 (0)