Add pull menu command, token auth to bangle requests
This commit is contained in:
parent
fc8894015a
commit
6bd1f2f05b
|
@ -11,6 +11,12 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
const STATE_GRID_OPEN = 2;
|
||||
const STATE_MENU_OPEN = 3;
|
||||
|
||||
let apiKey = require("Storage").readJSON("apikey.json", null);
|
||||
if (!apiKey) {
|
||||
require("Storage").writeJSON("apikey.json", "NEEDTOSET");
|
||||
}
|
||||
|
||||
|
||||
let watchState = STATE_IDLE;
|
||||
|
||||
let myMessage = "";
|
||||
|
@ -92,7 +98,8 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
}
|
||||
|
||||
if (Bangle.http){
|
||||
const options = {timeout:3000, method: "post", body: direction};
|
||||
const headers = {"Authorization": "Bearer " + apiKey};
|
||||
const options = {timeout:3000, method: "post", body: direction, headers: headers};
|
||||
Bangle.http("https://api.home.dns.t0.vc/bangle", options).then(event => {
|
||||
myMessage = "Sent " + direction;
|
||||
if (paintFace) paintFace();
|
||||
|
@ -185,7 +192,8 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
require("Storage").writeJSON("prevNum.json", prevNum);
|
||||
|
||||
if (Bangle.http){
|
||||
const options = {timeout:3000, method: "post", body: gridNum};
|
||||
const headers = {"Authorization": "Bearer " + apiKey};
|
||||
const options = {timeout:3000, method: "post", body: gridNum, headers: headers};
|
||||
Bangle.http("https://api.home.dns.t0.vc/grid", options).then(event => {
|
||||
myMessage = "ok";
|
||||
if (paintFace) paintFace();
|
||||
|
@ -200,7 +208,8 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
myMessage = grid[prevNum];
|
||||
|
||||
if (Bangle.http){
|
||||
const options = {timeout:3000, method: "post", body: prevNum};
|
||||
const headers = {"Authorization": "Bearer " + apiKey};
|
||||
const options = {timeout:3000, method: "post", body: prevNum, headers: headers};
|
||||
Bangle.http("https://api.home.dns.t0.vc/grid", options).then(event => {
|
||||
myMessage = "ok";
|
||||
if (paintFace) paintFace();
|
||||
|
@ -266,7 +275,7 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
quad = 3;
|
||||
}
|
||||
}
|
||||
console.log("quad:", quad);
|
||||
//console.log("quad:", quad);
|
||||
|
||||
if (watchState == STATE_IDLE && pressed) {
|
||||
watchState = STATE_MENU_OPEN;
|
||||
|
@ -279,7 +288,7 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
subMenu = subMenu[key];
|
||||
menuCommand += key + ",";
|
||||
|
||||
console.log("submenu:", subMenu);
|
||||
//console.log("submenu:", subMenu);
|
||||
|
||||
if (subMenu) {
|
||||
drawMenu(subMenu);
|
||||
|
@ -289,8 +298,15 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
Bangle.drawWidgets();
|
||||
Bangle.buzz(100, 0.2);
|
||||
|
||||
if (menuCommand == "commands,util,pull menu,") {
|
||||
console.log("Pulling new menu...");
|
||||
menu = null;
|
||||
require("Storage").writeJSON("menu.json", menu);
|
||||
}
|
||||
|
||||
if (Bangle.http){
|
||||
const options = {timeout:3000, method: "post", body: menuCommand};
|
||||
const headers = {"Authorization": "Bearer " + apiKey};
|
||||
const options = {timeout:3000, method: "post", body: menuCommand, headers: headers};
|
||||
Bangle.http("https://api.home.dns.t0.vc/menu", options).then(event => {
|
||||
myMessage = "ok";
|
||||
if (paintFace) paintFace();
|
||||
|
@ -300,7 +316,7 @@ Graphics.prototype.setFontAnton = function(scale) {
|
|||
});
|
||||
}
|
||||
|
||||
myMessage = "sent";
|
||||
myMessage = key;
|
||||
if (paintFace) paintFace();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user