✨ Add an offline indicator

If the connectivity check detects that OctoPrint cannot reach the
internet, this will now be reflected on the UI.

Implements #3840
This commit is contained in:
Gina Häußge committed 2021-03-23 17:17:17 +01:00
1 parent 8ddb51fc91
commit d4e47f9764
7 files changed
+41 -2

No files matched your search

+2 -1
View File
@@ -1277,7 +1277,7 @@ class Server(object):
self._logger.exception("Stacktrace follows:")
def _create_socket_connection(self, session):
global printer, fileManager, analysisQueue, userManager, eventManager
global printer, fileManager, analysisQueue, userManager, eventManager, connectivityChecker
return util.sockjs.PrinterStateConnection(
printer,
fileManager,
@@ -1286,6 +1286,7 @@ class Server(object):
groupManager,
eventManager,
pluginManager,
connectivityChecker,
session,
)
+3
View File
@@ -119,6 +119,7 @@ class PrinterStateConnection(
groupManager,
eventManager,
pluginManager,
connectivityChecker,
session,
):
if isinstance(session, octoprint.vendor.sockjs.tornado.session.Session):
@@ -145,6 +146,7 @@ class PrinterStateConnection(
self._groupManager = groupManager
self._eventManager = eventManager
self._pluginManager = pluginManager
self._connectivityChecker = connectivityChecker
self._remoteAddress = None
self._user = self._userManager.anonymous_user_factory()
@@ -223,6 +225,7 @@ class PrinterStateConnection(
"config_hash": config_hash,
"debug": octoprint.server.debug,
"safe_mode": octoprint.server.safe_mode,
"online": self._connectivityChecker.online,
"permissions": [permission.as_dict() for permission in Permissions.all()],
},
)
+8 -1
View File
@@ -321,7 +321,7 @@ def in_cache():
@app.route("/")
def index():
from octoprint.server import printer
from octoprint.server import connectivityChecker, printer
global _templates, _plugin_names, _plugin_vars
@@ -375,6 +375,7 @@ def index():
enable_webcam,
enable_temperature_graph,
sockjs_connect_timeout,
connectivityChecker.online,
wizard_active(_templates.get(locale)),
] + sorted(
[
@@ -597,6 +598,7 @@ def index():
"enableSdSupport": enable_sd_support,
"sockJsConnectTimeout": sockjs_connect_timeout * 1000,
"wizard": wizard,
"online": connectivityChecker.online,
"now": now,
}
)
@@ -868,6 +870,11 @@ def fetch_template_data(refresh=False):
# navbar
templates["navbar"]["entries"] = {
"offlineindicator": {
"template": "navbar/offlineindicator.jinja2",
"_div": "navbar_offlineindicator",
"custom_bindings": False,
},
"settings": {
"template": "navbar/settings.jinja2",
"_div": "navbar_settings",
@@ -173,6 +173,9 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
BRANCH = data["branch"];
$("span.version").text(DISPLAY_VERSION);
// update connectivity state
ONLINE = data["online"];
// update plugin hash
var oldPluginHash = self._pluginHash;
self._pluginHash = data["plugin_hash"];
@@ -413,6 +416,8 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
type: severity,
hide: false
});
} else if (type === "ConnectivityChanged") {
ONLINE = payload.new;
}
var legacyEventHandlers = {
@@ -9,6 +9,21 @@ $(function () {
self.system = parameters[4];
self.access = parameters[5];
self.offline = ko.observable(!ONLINE);
self.offlinePopoverContent = function () {
return (
"<p>" +
gettext(
"OctoPrint cannot reach the internet. If this is not " +
"intentional, please check OctoPrint's network settings and " +
"the connectivity check configuration. Updates, plugin repository " +
"and anything else requiring access to the public internet will not " +
"work."
) +
"</p>"
);
};
self.appearanceClasses = ko.pureComputed(function () {
var classes = self.appearance.color();
if (self.appearance.colorTransparent()) {
@@ -16,6 +31,10 @@ $(function () {
}
return classes;
});
self.onServerReconnect = self.onServerConnect = self.onEventConnectivityChanged = function () {
self.offline(!ONLINE);
};
}
OCTOPRINT_VIEWMODELS.push({
@@ -35,6 +35,7 @@
var SUPPORTED_EXTENSIONS = {{ supportedExtensions|tojson }};
var PERMISSIONS = {{ permissions|tojson }};
var ONLINE = {% if online -%}true{% else %}false{%- endif %};
var OCTOPRINT_VIEWMODELS = [];
var ADDITIONAL_VIEWMODELS = [];
@@ -0,0 +1,3 @@
<a href="https://faq.octoprint.org/connectivity-offline" target="_blank" title="{{ _('There is no connection to the internet') }}" rel="noopener noreferrer" data-bind="visible: offline(), popover: { placement: 'bottom', title: '{{ _('There is no connection to the internet')|esq }}', html: true, content: offlinePopoverContent, trigger: 'hover' }" style="display: none">
<i class="far fa-unlink"></i>
</a>