Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
flatsiedatsie committed Nov 14, 2022
1 parent 93a7d0c commit ad50a85
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 109 deletions.
66 changes: 66 additions & 0 deletions images/menu-icon-old.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/menu-icon-yellow.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 1 addition & 66 deletions images/menu-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 73 additions & 22 deletions js/extension.js
Expand Up @@ -4,8 +4,10 @@
super('Candle-manager-addon');
this.addMenuEntry('Candle manager');

this.content = '<p style="color:white;font-family:arial,sans-serif; margin:4rem auto"><strong>Failed to load Candle Manager add-on</strong><br/><br/>- The gateway did not respond. Perhaps it crashed? You could try rebooting it.<br/><br/>- You can try to reload this webpage.</p>';

this.content = '<p style="color:white;font-family:arial,sans-serif; margin:4rem auto"><strong>Failed to load Candle Manager add-on</strong><br/><br/>- The gateway did not respond. Perhaps it crashed? You could try rebooting it.<br/><br/>- You can try to reload this page.</p>';

this.debug = false;

fetch(`/extensions/Candle-manager-addon/views/content.html`)
.then((res) => res.text())
.then((text) => {
Expand All @@ -20,6 +22,8 @@

this.view.innerHTML = this.content;

this.warning_needed = true;

var attachFuncEvent = "message";
var attachFunc = window.addEventListener ;
if (! window.addEventListener) {
Expand All @@ -29,7 +33,8 @@

attachFunc(attachFuncEvent, function(event) {
if (event.data == 'iframeIsDone') { // iframe has succesfully loaded the Candle manager callback
//console.log("Candle manager loaded in iframe succesfully");
console.log("Candle manager loaded in iframe succesfully");
this.warning_needed = false;
const ssl_frame_warning = document.getElementById('extension-Candle-manager-addon-ssl-frame-warning');
if(ssl_frame_warning != null){
ssl_frame_warning.parentNode.removeChild(ssl_frame_warning); // remove the warning if the Candle manager loaded succesfully
Expand All @@ -45,19 +50,27 @@
this.view.innerHTML = this.content;
//console.log(this.content);


const iframe_el = document.getElementById('extension-Candle-manager-addon-iframe');
//var full_lan_path = "http://gateway.local:8686"

//console.log("window.location.protocol: ", window.location.protocol);

/*
var the_protocol = "https://";
if (location.protocol == 'http:'){
var http_local_address = window.location.protocol + '//' + window.location.hostname + ':8686'; // this is only used as a backup guess for where the flask server may be

/*
//var the_protocol = "https://";
if (window.location.protocol == 'http:'){
// If the connection is unsecured, we assume it's a local lan connection, and can simply load the Candle Manager into the iframe. Perhaps a more thorough check would be if `mozilla-iot` is in the URL bar string.
//the_protocol = "http://";
document.getElementById('extension-Candle-manager-addon-iframe').src = 'http://' + window.location.hostname + ':8686';
if(iframe_el != null){
iframe_el.src = http_local_address;
}
}
else{
*/
console.log("Candle manager: seems to be a HTTPS connection");
}
*/

var https_in_url = 0;
if (location.protocol == 'https:'){
Expand All @@ -67,38 +80,76 @@

// If the user is using https and/or the tunneling feature, find out what the actual local IP address is from the controller.

//console.log("https_in_url : ", https_in_url );

window.API.postJson(
`/extensions/${this.id}/api/full_lan_path`,
{'ssl':https_in_url,'hostname':window.location.hostname}
).then((body) => {
//full_lan_path = body['full_lan_path'];
//console.log("API response:");
//console.log(body);
//if( 'https://' + window.location.hostname + ':8686' != body['full_lan_path'] ){
// document.getElementById('extension-Candle-manager-addon-iframe').src = 'data:text/html,\'<p style="color:white;font-family:arial,sans-serif; margin:4rem auto"><strong>The manager cannot be displayed (yet)</strong><br/><br/> - It might still be starting up. You can try reloading the page in a few seconds.<br/><br/>- Alternatively, you can try to visit <a target="_blank" href="' + body['full_lan_path'] + '">directly</a>. There you may have to create a security exception.</p>\'';
//}
document.getElementById('extension-Candle-manager-addon-iframe').src = body['full_lan_path'];
document.getElementById('extension-Candle-manager-addon-support-link').href = body['full_lan_path'];


this.debug = body['debug'];

if(this.debug){
console.log("Candle manager full_lan_path API response:");
console.log(body);
}


var flask_protocol = 'http';
if( body['ssl_certificate_detected'] ){
flask_protocol = 'https';
}


if(document.getElementById('extension-Candle-manager-addon-iframe') != null){
if(this.debug){
console.log("candle manager debug: setting iframe to:", flask_protocol + "://" + body['full_lan_path']);
}
document.getElementById('extension-Candle-manager-addon-iframe').src = flask_protocol + "://" + body['full_lan_path'];
}
else{
console.log('error, candle manager iframe_el was null while trying to set candle manager iframe to : ', flask_protocol + "://" + body['full_lan_path']);
}

//iframe_el.src = ;
document.getElementById('extension-Candle-manager-addon-support-link').href = flask_protocol + "://" + body['full_lan_path'];
//console.log(body['full_lan_path']);
//console.log(body['ssl_enabled']);


setTimeout(function() {
//console.log("timeout is now");
try {
document.getElementById('extension-Candle-manager-addon-ssl-frame-warning').classList.remove("extension-Candle-manager-addon-hidden");
}
catch(err) {
//
if(this.warning_needed){
try {
document.getElementById('extension-Candle-manager-addon-ssl-frame-warning').classList.remove("extension-Candle-manager-addon-hidden");
}
catch(err) {
if(this.debug){
console.log("debug: candle manager timeout error: ", err);
}
}
}
else{
console.log("candle manager: iframe loaded succesfully, no need to show warning");
}
}, 3000);

}).catch((e) => {
var error_string = e.toString();
console.log("Error calling API, will try backup option");
console.log(error_string);
document.getElementById('extension-Candle-manager-addon-iframe').src = "https://gateway.local:8686";
if(this.debug){
console.log("Error calling API, will try backup option. Error was: ", e);
}
if(document.getElementById('extension-Candle-manager-addon-iframe') != null){
document.getElementById('extension-Candle-manager-addon-iframe').src = http_local_address;
}
else{
console.log('error, iframe_el was null while trying to set candle manager iframe to backup address: ', http_local_address);
}

});
//}
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -70,7 +70,7 @@
}
},
"short_name": "Candle Mgr",
"version": "1.2.7",
"version": "1.3.0",
"web_accessible_resources": [
"css/*.css",
"images/*.svg",
Expand Down

0 comments on commit ad50a85

Please sign in to comment.