Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/widapplebatt/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: New Widget!
Binary file added apps/widapplebatt/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions apps/widapplebatt/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "widapplebatt",
"name": "Apple Battery Widget",
"shortName":"Apple Battery",
"icon": "app.png",
"version":"0.01",
"type": "widget",
"supports": ["BANGLEJS", "BANGLEJS2"],
"author": "RKBoss6",
"description": "A simple battery widget in the style of iOS devices' battery icons, with a setting to show or hide the percent text.",
"tags": "widget,battery",
"provides_widgets" : ["battery"],
"storage": [
{"name":"widapplebatt.wid.js","url":"widget.js"},
{"name":"widapplebatt.settings.js","url":"settings.js"}
],
"data":[
{"name":"widapplebatt.settings.json"}
],
"screenshots": [{"url":"screenshot1.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"}]

}
Binary file added apps/widapplebatt/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/widapplebatt/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/widapplebatt/screenshot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions apps/widapplebatt/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function(back) {
const FILE = "widapplebatt.settings.json";
// Load settings
var settings = Object.assign({
showPercent: true,
}, require('Storage').readJSON(FILE, true) || {});

function writeSettings() {
require('Storage').writeJSON(FILE, settings);
}


// Show the menu
E.showMenu({
"" : { "title" : "Apple Battery" },
"< Back" : () => back(),
'Show Percent': {
value: !!settings.showPercent, // !! converts undefined to false
onchange: v => {
settings.showPercent = v;
writeSettings();
if(WIDGETS["applebatt"]) WIDGETS["applebatt"].reload()
if(WIDGETS["applebatt"]) WIDGETS["applebatt"].draw()

}
}
});
})
37 changes: 37 additions & 0 deletions apps/widapplebatt/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(function(){
const intervalLow = 120000;
const intervalHigh = 30000;
var id;
let settings;
function reload() {
settings=require("Storage").readJSON("widapplebatt.settings.json")||{showPercent:true}
}
function draw() {
g.reset("widget");
var x = this.x, y = this.y, w = this.width-5;
const l = E.getBattery();
const lw=(w)*(l/100)
g.setColor("#808080");
g.fillRect({x:x+2,y:y+2,w:w,h:16,r:6})
let col=g.theme.fg
if(l<25) col=g.theme.dark ? "#ff0" : "#FC6A03"
if(l<15) col="#f00"
if(Bangle.isCharging()) col="#0f0"
g.setColor(col)
.fillRect({x:x+2,y:y+2,w:lw,h:16,r:6})
.setFontAlign(0,0).setColor(g.theme.bg)
.setColor(g.theme.bg)
.drawRect({x:x+1,y:y+1,w:w+2,h:16+2,r:6})
.drawRect({x:x+0.5,y:y+1,w:w+3,h:16+2,r:6})
.drawRect({x:x,y:y,w:w+4,h:16+4,r:6})
if(settings.showPercent) g.setFont("14").drawString(l,x+2+(w/2),y+12)
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
else changeInterval(id, intervalLow);

}
reload()
Bangle.on('charging',function(charging) { draw(); });
id = setInterval(()=>WIDGETS["applebatt"].draw(), intervalLow);

WIDGETS["applebatt"]={area:"tr",width:32,draw:draw, reload:reload};
})();
Loading