Skip to content

Commit

Permalink
get status on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonshineSG committed Jan 18, 2016
1 parent dc40519 commit 3592c5e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
8 changes: 7 additions & 1 deletion octoprint_title_status/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
import octoprint.plugin
import logging

class TitleStatusPlugin(octoprint.plugin.AssetPlugin):
from octoprint.events import eventManager, Events

class TitleStatusPlugin(octoprint.plugin.AssetPlugin, octoprint.plugin.EventHandlerPlugin):

def get_assets(self):
return dict(
js=["js/title_status.js"]
)

def on_event(self, event, payload):
if event == Events.CLIENT_OPENED:
self._plugin_manager.send_plugin_message(self._identifier, self._printer.get_state_id())

def get_version(self):
return self._plugin_version
Expand Down
28 changes: 18 additions & 10 deletions octoprint_title_status/static/js/title_status.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
$(function() {
function TitleStatusViewModel(viewModels) {
var self = this;

self.onAllBound = function () {
self.default_title = document.title;
//console.log(self.default_title);
self.default_title = document.title;
}

self.onDataUpdaterPluginMessage = function (plugin, data) {
if (plugin != "title_status") {
return;
}
self._update(data);
}

self.onEventPrinterStateChanged = function(payload) {
self._update(payload.state_id);
}

self.createTitle = function(text){
Expand All @@ -16,11 +26,9 @@ $(function() {
document.title = text;
}
}

self.onEventPrinterStateChanged = function(payload) {
//console.log(payload.state_id);

switch (payload.state_id) {

self._update = function (status) {
switch (status) {
case "OFFLINE":
self.createTitle("* ");
break;
Expand All @@ -45,8 +53,8 @@ $(function() {
self.createTitle("? ")
break;
}
};

}
}
ADDITIONAL_VIEWMODELS.push([TitleStatusViewModel, [], []]);
});

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-TitleStatus"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.0.1"
plugin_version = "0.0.2"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 3592c5e

Please sign in to comment.