commit
ef43eba307
|
|
@ -6,11 +6,11 @@
|
||||||
);
|
);
|
||||||
const iconWidth = 18;
|
const iconWidth = 18;
|
||||||
|
|
||||||
function draw(this: { x: number; y: number }) {
|
function draw(this: { x?: number; y?: number }) {
|
||||||
g.reset();
|
g.reset();
|
||||||
if (Bangle.isCharging()) {
|
if (Bangle.isCharging()) {
|
||||||
g.setColor('#FD0');
|
g.setColor('#FD0');
|
||||||
g.drawImage(icon, this.x + 1, this.y + 1, {
|
g.drawImage(icon, this.x! + 1, this.y! + 1, {
|
||||||
scale: 0.6875,
|
scale: 0.6875,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
0.01: First commit
|
0.01: First commit
|
||||||
|
0.02: Add tap-to-lock functionality
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"id": "widlockunlock",
|
"id": "widlockunlock",
|
||||||
"name": "Lock/Unlock Widget",
|
"name": "Lock/Unlock Widget",
|
||||||
"version": "0.01",
|
"version": "0.02",
|
||||||
"description": "On devices with always-on display (Bangle.js 2) this displays lock icon whenever the display is locked, or an unlock icon otherwise",
|
"description": "On devices with always-on display (Bangle.js 2) this displays lock icon whenever the display is locked, or an unlock icon otherwise. Tap to lock the lcd",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
"tags": "widget,lock",
|
"tags": "widget,lock",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,28 @@
|
||||||
Bangle.on("lockunlock", function() {
|
Bangle.on("lock", () => Bangle.drawWidgets());
|
||||||
Bangle.drawWidgets();
|
|
||||||
|
Bangle.on('touch', (_btn, xy) => {
|
||||||
|
const oversize = 5;
|
||||||
|
|
||||||
|
const w = WIDGETS.lockunlock;
|
||||||
|
|
||||||
|
const x = xy.x;
|
||||||
|
const y = xy.y;
|
||||||
|
|
||||||
|
if(w.x - oversize <= x && x < w.x + 14 + oversize
|
||||||
|
&& w.y - oversize <= y && y < w.y + 24 + oversize)
|
||||||
|
{
|
||||||
|
Bangle.setLocked(true);
|
||||||
|
|
||||||
|
const backlightTimeout = Bangle.getOptions().backlightTimeout; // ms
|
||||||
|
|
||||||
|
// seems to be a race/if we don't give the firmware enough time,
|
||||||
|
// it won't timeout the backlight and we'll restore it in our setTimeout below
|
||||||
|
Bangle.setOptions({ backlightTimeout: 100 });
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
Bangle.setOptions({ backlightTimeout });
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
WIDGETS["lockunlock"]={area:"tl",sortorder:10,width:14,draw:function(w) {
|
WIDGETS["lockunlock"]={area:"tl",sortorder:10,width:14,draw:function(w) {
|
||||||
g.reset().drawImage(atob(Bangle.isLocked() ? "DBGBAAAA8DnDDCBCBP////////n/n/n//////z/A" : "DBGBAAAA8BnDDCBABP///8A8A8Y8Y8Y8A8A//z/A"), w.x+1, w.y+3);
|
g.reset().drawImage(atob(Bangle.isLocked() ? "DBGBAAAA8DnDDCBCBP////////n/n/n//////z/A" : "DBGBAAAA8BnDDCBABP///8A8A8Y8Y8Y8A8A//z/A"), w.x+1, w.y+3);
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,10 @@ type WidgetArea = "tl" | "tr" | "bl" | "br";
|
||||||
type Widget = {
|
type Widget = {
|
||||||
area: WidgetArea;
|
area: WidgetArea;
|
||||||
width: number;
|
width: number;
|
||||||
draw: (this: { x: number; y: number }) => void;
|
sortorder?: number;
|
||||||
|
draw: (this: Widget, w: Widget) => void;
|
||||||
|
x?: number;
|
||||||
|
y?: number;
|
||||||
};
|
};
|
||||||
declare const WIDGETS: { [key: string]: Widget };
|
declare const WIDGETS: { [key: string]: Widget };
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue