Add system for displaying device warnings

This commit is contained in:
Taylor Helsper 2020-09-10 22:21:24 -05:00
parent fb7a979525
commit 53b0cd047f
6 changed files with 186 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import string
# Globals
local_ip = "unknown"
cached_data = {}
warning_data = {}
#==================================
# Utilities

View File

@ -0,0 +1,93 @@
from device_info import *
import os
# Globals
warning_data = {}
#==================================
# Warning Functions
#==================================
def init_warning_data():
global warning_data
if len(warning_data) != 0:
return
# Add undervoltage warning
undervoltage_warning = {}
undervoltage_warning["name"] = "undervoltage"
undervoltage_warning["header"] = "Device Undervoltage"
undervoltage_warning["description"] = "Your device has had an undervoltage warning. This typically means \
your power supply is going bad or is not powerful enough. This can \
lead to data corruption and loss of data."
warning_data[undervoltage_warning["name"]] = undervoltage_warning
# Add throttled warning
undervoltage_warning = {}
undervoltage_warning["name"] = "throttled"
undervoltage_warning["header"] = "Device CPU Throttled"
undervoltage_warning["description"] = "Your device has had a throttling warning. This typically means there is \
not enough power being supplied to run your device at full speed. Your \
device may run slowly. A new power supply may help."
warning_data[undervoltage_warning["name"]] = undervoltage_warning
# Add capped warning
undervoltage_warning = {}
undervoltage_warning["name"] = "capped"
undervoltage_warning["header"] = "Device CPU Capped"
undervoltage_warning["description"] = "Your device has had a capped warning. This typically means your device has \
gotten quite hot and slowed the CPU down to try and lower the temperature. \
This can make your device run slowly and reduce the device's lifetime."
warning_data[undervoltage_warning["name"]] = undervoltage_warning
def is_warning_skipped(warning):
if os.path.isfile("/tmp/warning_skipped_{}".format(warning)):
return True
return False
def skip_warning(warning):
global warning_data
init_warning_data()
os.system("touch /tmp/warning_skipped_{}".format(warning))
def is_warning_present():
global warning_data
init_warning_data()
warning = get_current_warning()
if warning != "NONE":
return True
return False
def get_current_warning():
global warning_data
init_warning_data()
# Gather data
throttled_data = get_throttled_data()
# Check for undervoltage warning
if not is_warning_skipped("undervoltage"):
if throttled_data["RAW_DATA"] != "MISSING" and throttled_data["HAS_UNDERVOLTED"]:
return "undervoltage"
# Check for throttled warning
if not is_warning_skipped("throttled"):
if throttled_data["RAW_DATA"] != "MISSING" and throttled_data["HAS_THROTTLED"]:
return "throttled"
# Check for capped warning
if not is_warning_skipped("capped"):
if throttled_data["RAW_DATA"] != "MISSING" and throttled_data["HAS_CAPPED"]:
return "capped"
# No warnings!
return "NONE"
def get_warning_header(warning):
global warning_data
init_warning_data()
return warning_data[warning]["header"]
def get_warning_description(warning):
global warning_data
init_warning_data()
return warning_data[warning]["description"]

View File

@ -22,6 +22,7 @@ from messages import get_message
from thread_functions import *
from datetime import timedelta
from device_info import *
from device_warnings import *
import pam
import json
import random
@ -193,6 +194,17 @@ def index():
"ui_settings": read_ui_settings()
}
return render_template('state.html', **templateData)
elif is_warning_present():
warning = get_current_warning()
templateData = {
"title": "myNode Warning",
"header_text": "Warning",
"subheader_text": get_warning_header(warning),
"description_text": get_warning_description(warning),
"warning_name": warning,
"ui_settings": read_ui_settings()
}
return render_template('warning.html', **templateData)
elif status == STATE_DRIVE_MISSING:
# Drive may be getting repaired
if is_drive_being_repaired():
@ -670,6 +682,14 @@ def page_product_key():
return "Error"
@app.route("/ignore-warning")
def page_ignore_warning():
check_logged_in()
if request.method == 'GET':
warning = request.args.get('warning')
skip_warning(warning)
return redirect("/")
@app.route("/toggle-lndhub")
def page_toggle_lndhub():
check_logged_in()

View File

@ -68,6 +68,13 @@ a:active {
font-family: Arial, Helvetica, sans-serif;
}
.state_warning {
color: #555555;
text-align: center;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
}
.shutoff_warning {
font-size: 12px;
}
@ -563,6 +570,29 @@ a:active {
margin-top: 5px;
}
.warning_div {
width: 800px;
color: #444444;
margin: auto;
text-align: center;
font-size: 18px;
font-family: Arial, Helvetica, sans-serif;
margin-top: 10px;
margin-bottom: 40px;
}
.warning_button {
width: 500px;
margin-top: 5px;
}
.warning_divider {
width: 100%;
margin-top: 12px;
margin-bottom: 12px;
border-bottom: 3px dashed yellow;
margin-left: auto;
margin-right: auto;
}
#download-handle {
width: 6em;
height: 1.6em;

View File

@ -21,6 +21,8 @@ a:active {
.shutoff_warning,
.main_header,
.main_header_sub_text,
.warning_div,
.format_div,
.app_title,
.app_status,
.app_contents,

View File

@ -0,0 +1,40 @@
<!DOCTYPE html lang="en">
<head>
<title>{{ title }}</title>
{% include 'includes/head.html' %}
<meta http-equiv="refresh" content="30">
<script>
$(document).ready(function() {
$("#warning-continue").on("click", function() {
window.location.href="/ignore-warning?warning={{warning_name}}"
});
});
</script>
</head>
<body>
{% include 'includes/logo_header.html' %}
<div class="state_header">{{header_text}}</div>
<div class="warning_div">
<div class="warning_divider"></div>
<div class="state_subheader">{{ subheader_text }}</div>
<p>{{description_text}}</p>
<br/>
<div class="warning_divider"></div>
<br/>
<button id="warning-continue" value="Login" class="ui-button ui-widget ui-corner-all format_button">Continue</button>
<br/><br/>
</div>
<div style="height: 40px;">&nbsp;</div>
{% include 'includes/footer.html' %}
</body>
</html>