widbt: Added configuration option
parent
c99a0de9a9
commit
d83396036b
|
|
@ -10,3 +10,4 @@
|
||||||
0.11: Avoid too many notifications. Change disconnected colour to red.
|
0.11: Avoid too many notifications. Change disconnected colour to red.
|
||||||
0.12: Prevent repeated execution of `draw()` from the current app.
|
0.12: Prevent repeated execution of `draw()` from the current app.
|
||||||
0.13: Added "connection restored" notification. Fixed restoring of the watchface.
|
0.13: Added "connection restored" notification. Fixed restoring of the watchface.
|
||||||
|
0.14: Added configuration option
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
{
|
{
|
||||||
"id": "widbt_notify",
|
"id": "widbt_notify",
|
||||||
"name": "Bluetooth Widget with Notification",
|
"name": "Bluetooth Widget with Notification",
|
||||||
"version": "0.13",
|
"version": "0.14",
|
||||||
"description": "Show the current Bluetooth connection status in the top right of the clock and vibrate when disconnected.",
|
"description": "Show the current Bluetooth connection status in the top right of the clock and vibrate when disconnected.",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
"tags": "widget,bluetooth",
|
"tags": "widget,bluetooth",
|
||||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"widbt_notify.wid.js","url":"widget.js"}
|
{"name":"widbt_notify.wid.js","url":"widget.js"},
|
||||||
]
|
{"name":"widbt_notify.settings.js","url":"settings.js"}
|
||||||
|
],
|
||||||
|
"data": [
|
||||||
|
{"name":"widbt_notify.json"}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
(function(back) {
|
||||||
|
var FILE = "widbt_notify.json";
|
||||||
|
var settings = Object.assign({
|
||||||
|
secondsOnUnlock: false,
|
||||||
|
}, require('Storage').readJSON(FILE, true) || {});
|
||||||
|
|
||||||
|
function writeSettings() {
|
||||||
|
require('Storage').writeJSON(FILE, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper method which uses int-based menu item for set of string values
|
||||||
|
function stringItems(startvalue, writer, values) {
|
||||||
|
return {
|
||||||
|
value: (startvalue === undefined ? 0 : values.indexOf(startvalue)),
|
||||||
|
format: v => values[v],
|
||||||
|
min: 0,
|
||||||
|
max: values.length - 1,
|
||||||
|
wrap: true,
|
||||||
|
step: 1,
|
||||||
|
onchange: v => {
|
||||||
|
writer(values[v]);
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper method which breaks string set settings down to local settings object
|
||||||
|
function stringInSettings(name, values) {
|
||||||
|
return stringItems(settings[name], v => settings[name] = v, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
var mainmenu = {
|
||||||
|
"": {
|
||||||
|
"title": "Bluetooth Widget WN"
|
||||||
|
},
|
||||||
|
"< Back": () => back(),
|
||||||
|
"Show Widget": {
|
||||||
|
value: (settings.showWidget !== undefined ? settings.showWidget : true),
|
||||||
|
onchange: v => {
|
||||||
|
settings.showWidget = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Buzz on Connect": {
|
||||||
|
value: (settings.buzzOnConnect !== undefined ? settings.buzzOnConnect : true),
|
||||||
|
onchange: v => {
|
||||||
|
settings.buzzOnConnect = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Buzz on loss": {
|
||||||
|
value: (settings.buzzOnLoss !== undefined ? settings.buzzOnLoss : true),
|
||||||
|
onchange: v => {
|
||||||
|
settings.buzzOnLoss = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
E.showMenu(mainmenu);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -2,57 +2,92 @@ WIDGETS.bluetooth_notify = {
|
||||||
area: "tr",
|
area: "tr",
|
||||||
width: 15,
|
width: 15,
|
||||||
warningEnabled: 1,
|
warningEnabled: 1,
|
||||||
|
|
||||||
|
// ------------ Settings -------- very lame - need to improve
|
||||||
|
readshowWidget: function() {
|
||||||
|
var showWidget;
|
||||||
|
const SETTINGSFILE = "widbt_notify.json";
|
||||||
|
function def (value, def) {return value !== undefined ? value : def;}
|
||||||
|
var settings = require('Storage').readJSON(SETTINGSFILE, true) || {};
|
||||||
|
showWidget = def(settings.showWidget, true);
|
||||||
|
return showWidget;
|
||||||
|
},
|
||||||
|
|
||||||
|
readBuzzOnConnect: function() {
|
||||||
|
var buzzOnConnect;
|
||||||
|
const SETTINGSFILE = "widbt_notify.json";
|
||||||
|
function def (value, def) {return value !== undefined ? value : def;}
|
||||||
|
var settings = require('Storage').readJSON(SETTINGSFILE, true) || {};
|
||||||
|
buzzOnConnect = def(settings.buzzOnConnect, true);
|
||||||
|
return buzzOnConnect;
|
||||||
|
},
|
||||||
|
|
||||||
|
readBuzzOnLoss: function() {
|
||||||
|
var buzzOnLoss;
|
||||||
|
const SETTINGSFILE = "widbt_notify.json";
|
||||||
|
function def (value, def) {return value !== undefined ? value : def;}
|
||||||
|
var settings = require('Storage').readJSON(SETTINGSFILE, true) || {};
|
||||||
|
buzzOnLoss = def(settings.buzzOnLoss, true);
|
||||||
|
return buzzOnLoss;
|
||||||
|
},
|
||||||
|
// ------------ Settings --------
|
||||||
|
|
||||||
draw: function() {
|
draw: function() {
|
||||||
g.reset();
|
if (WIDGETS.bluetooth_notify.readshowWidget()){
|
||||||
if (NRF.getSecurityStatus().connected) {
|
g.reset();
|
||||||
g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f"));
|
if (NRF.getSecurityStatus().connected) {
|
||||||
} else {
|
g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f"));
|
||||||
// g.setColor(g.theme.dark ? "#666" : "#999");
|
} else {
|
||||||
g.setColor("#f00"); // red is easier to distinguish from blue
|
// g.setColor(g.theme.dark ? "#666" : "#999");
|
||||||
|
g.setColor("#f00"); // red is easier to distinguish from blue
|
||||||
|
}
|
||||||
|
g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y);
|
||||||
}
|
}
|
||||||
g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
redrawCurrentApp: function(){
|
redrawCurrentApp: function(){
|
||||||
if(typeof(draw)=='function'){
|
if(typeof(draw)=='function'){
|
||||||
g.clear();
|
g.clear();
|
||||||
draw();
|
draw();
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
}else{
|
}else{
|
||||||
load(); // fallback. This might reset some variables
|
load(); // fallback. This might reset some variables
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
connect: function() {
|
connect: function() {
|
||||||
if(WIDGETS.bluetooth_notify.warningEnabled == 1){
|
|
||||||
E.showMessage(/*LANG*/'Connection\n restored.', 'Bluetooth');
|
if(WIDGETS.bluetooth_notify.warningEnabled == 1){
|
||||||
setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'.
|
E.showMessage(/*LANG*/'Connection\nrestored.', 'Bluetooth');
|
||||||
|
setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'.
|
||||||
WIDGETS.bluetooth_notify.warningEnabled = 0;
|
|
||||||
setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds.
|
WIDGETS.bluetooth_notify.warningEnabled = 0;
|
||||||
|
setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 300); // don't buzz for the next 30 seconds.
|
||||||
var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet;
|
|
||||||
if(!quiet){
|
var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet;
|
||||||
Bangle.buzz(700, 1); // buzz on connection loss
|
if(!quiet && WIDGETS.bluetooth_notify.readBuzzOnConnect()){
|
||||||
}
|
Bangle.buzz(700, 1); // buzz on connection resume
|
||||||
}
|
}
|
||||||
WIDGETS.bluetooth_notify.draw();
|
}
|
||||||
|
WIDGETS.bluetooth_notify.draw();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect: function() {
|
disconnect: function() {
|
||||||
if(WIDGETS.bluetooth_notify.warningEnabled == 1){
|
if(WIDGETS.bluetooth_notify.warningEnabled == 1){
|
||||||
E.showMessage(/*LANG*/'Connection\nlost.', 'Bluetooth');
|
E.showMessage(/*LANG*/ 'Connection\nlost.', 'Bluetooth');
|
||||||
setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'.
|
setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'.
|
||||||
|
|
||||||
WIDGETS.bluetooth_notify.warningEnabled = 0;
|
WIDGETS.bluetooth_notify.warningEnabled = 0;
|
||||||
setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds.
|
setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 300); // don't buzz for the next 30 seconds.
|
||||||
|
|
||||||
var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet;
|
var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet;
|
||||||
if(!quiet){
|
if(!quiet && WIDGETS.bluetooth_notify.readBuzzOnLoss()){
|
||||||
Bangle.buzz(700, 1); // buzz on connection loss
|
Bangle.buzz(700, 1); // buzz on connection loss
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
WIDGETS.bluetooth_notify.draw();
|
WIDGETS.bluetooth_notify.draw();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue