Minor refactorings
parent
af315be712
commit
96ae6140f0
|
|
@ -1,18 +1,21 @@
|
||||||
/************
|
/************************************************
|
||||||
* Includes
|
* Includes
|
||||||
*/
|
*/
|
||||||
const locale = require('locale');
|
const locale = require('locale');
|
||||||
const storage = require('Storage');
|
const storage = require('Storage');
|
||||||
const clock_info = require("clock_info");
|
const clock_info = require("clock_info");
|
||||||
|
|
||||||
/************
|
|
||||||
* Statics
|
/************************************************
|
||||||
|
* Globals
|
||||||
*/
|
*/
|
||||||
const SETTINGS_FILE = "bwclk.setting.json";
|
const SETTINGS_FILE = "bwclk.setting.json";
|
||||||
const W = g.getWidth();
|
const W = g.getWidth();
|
||||||
const H = g.getHeight();
|
const H = g.getHeight();
|
||||||
|
var lock_input = false;
|
||||||
|
|
||||||
/************
|
|
||||||
|
/************************************************
|
||||||
* Settings
|
* Settings
|
||||||
*/
|
*/
|
||||||
let settings = {
|
let settings = {
|
||||||
|
|
@ -28,9 +31,7 @@ for (const key in saved_settings) {
|
||||||
settings[key] = saved_settings[key]
|
settings[key] = saved_settings[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
var lock_input = false;
|
/************************************************
|
||||||
|
|
||||||
/************
|
|
||||||
* Assets
|
* Assets
|
||||||
*/
|
*/
|
||||||
// Manrope font
|
// Manrope font
|
||||||
|
|
@ -82,6 +83,9 @@ function imgLock(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************
|
||||||
|
* Menu
|
||||||
|
*/
|
||||||
// Custom bwItems menu - therefore, its added here and not in a clkinfo.js file.
|
// Custom bwItems menu - therefore, its added here and not in a clkinfo.js file.
|
||||||
var bwItems = {
|
var bwItems = {
|
||||||
name: null,
|
name: null,
|
||||||
|
|
@ -141,22 +145,35 @@ menu.forEach((menuItm, x) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function canRunMenuItem(){
|
||||||
|
if(settings.menuPosY == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/************
|
var menuEntry = menu[settings.menuPosX];
|
||||||
* Helper
|
var item = menuEntry.items[settings.menuPosY-1];
|
||||||
*/
|
return item.run !== undefined;
|
||||||
function isFullscreen(){
|
}
|
||||||
var s = settings.screen.toLowerCase();
|
|
||||||
if(s == "dynamic"){
|
|
||||||
return Bangle.isLocked()
|
function runMenuItem(){
|
||||||
} else {
|
if(settings.menuPosY == 0){
|
||||||
return s == "full"
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var menuEntry = menu[settings.menuPosX];
|
||||||
|
var item = menuEntry.items[settings.menuPosY-1];
|
||||||
|
try{
|
||||||
|
item.run();
|
||||||
|
Bangle.buzz(300, 0.6).then(() => {});
|
||||||
|
} catch (ex) {
|
||||||
|
// Simply ignore it...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/************
|
/************************************************
|
||||||
* DRAW
|
* Draw
|
||||||
*/
|
*/
|
||||||
function draw() {
|
function draw() {
|
||||||
// Queue draw again
|
// Queue draw again
|
||||||
|
|
@ -279,32 +296,6 @@ function drawMenuAndTime(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function canRunItem(){
|
|
||||||
if(settings.menuPosY == 0){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var menuEntry = menu[settings.menuPosX];
|
|
||||||
var item = menuEntry.items[settings.menuPosY-1];
|
|
||||||
return item.run !== undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function runItem(){
|
|
||||||
if(settings.menuPosY == 0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var menuEntry = menu[settings.menuPosX];
|
|
||||||
var item = menuEntry.items[settings.menuPosY-1];
|
|
||||||
try{
|
|
||||||
item.run();
|
|
||||||
Bangle.buzz(300, 0.6).then(() => {});
|
|
||||||
} catch (ex) {
|
|
||||||
// Simply ignore it...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function drawLock(){
|
function drawLock(){
|
||||||
if(settings.showLock && Bangle.isLocked()){
|
if(settings.showLock && Bangle.isLocked()){
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
|
|
@ -322,9 +313,19 @@ function drawWidgets(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isFullscreen(){
|
||||||
|
var s = settings.screen.toLowerCase();
|
||||||
|
if(s == "dynamic"){
|
||||||
|
return Bangle.isLocked()
|
||||||
|
} else {
|
||||||
|
return s == "full"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Draw timeout
|
|
||||||
|
/************************************************
|
||||||
|
* Listener
|
||||||
*/
|
*/
|
||||||
// timeout used to update every minute
|
// timeout used to update every minute
|
||||||
var drawTimeout;
|
var drawTimeout;
|
||||||
|
|
@ -424,8 +425,8 @@ Bangle.on('touch', function(btn, e){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_center){
|
if(is_center){
|
||||||
if(canRunItem()){
|
if(canRunMenuItem()){
|
||||||
runItem();
|
runMenuItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -440,9 +441,10 @@ E.on("kill", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/************************************************
|
||||||
* Draw clock the first time
|
* Startup Clock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// The upper part is inverse i.e. light if dark and dark if light theme
|
// The upper part is inverse i.e. light if dark and dark if light theme
|
||||||
// is enabled. In order to draw the widgets correctly, we invert the
|
// is enabled. In order to draw the widgets correctly, we invert the
|
||||||
// dark/light theme as well as the colors.
|
// dark/light theme as well as the colors.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue