update icon and default launcher to use the new 2v26 fonts if available

master
Gordon Williams 2025-03-07 17:07:30 +00:00
parent f01bfd5972
commit ca95ce03dd
6 changed files with 108 additions and 116 deletions

View File

@ -23,4 +23,5 @@
0.16: Use firmware provided E.showScroller method 0.16: Use firmware provided E.showScroller method
0.17: fix fullscreen with oneClickExit 0.17: fix fullscreen with oneClickExit
0.18: Better performance 0.18: Better performance
0.19: Remove 'jit' keyword as 'for(..of..)' is not supported (fix #2937) 0.19: Remove 'jit' keyword as 'for(..of..)' is not supported (fix #2937)
0.20: Use '28' font if installed (2v26+) and put it inside a rounded rect in the current theme

View File

@ -8,6 +8,7 @@
swipeExit: false, swipeExit: false,
timeOut:"Off" timeOut:"Off"
}, s.readJSON("iconlaunch.json", true) || {}); }, s.readJSON("iconlaunch.json", true) || {});
let font = g.getFonts().includes("28") ? "28" : "12x20";
if (!settings.fullscreen) { if (!settings.fullscreen) {
Bangle.loadWidgets(); Bangle.loadWidgets();
@ -56,12 +57,7 @@
let texted; let texted;
let drawItem = function(itemI, r) { let drawItem = function(itemI, r) {
let x = whitespace; let x = whitespace, i = itemI * appsN - 1, selectedApp, c, selectedRect, item = launchCache.items[itemI];
let i = itemI * appsN - 1;
let selectedApp;
let c;
let selectedRect;
let item = launchCache.items[itemI];
if (texted == itemI){ if (texted == itemI){
g.clearRect(r.x, r.y, r.x + r.w - 1, r.y + r.h - 1); g.clearRect(r.x, r.y, r.x + r.w - 1, r.y + r.h - 1);
texted = undefined; texted = undefined;
@ -89,20 +85,20 @@
}; };
let drawText = function(i, appY, selectedApp) { let drawText = function(i, appY, selectedApp) {
"jit";
const idy = (selectedItem - (selectedItem % 3)) / 3; const idy = (selectedItem - (selectedItem % 3)) / 3;
if (i != idy) return; if (i != idy) return;
appY = appY + itemSize/2; appY = appY + itemSize/2;
g.setFontAlign(0, 0, 0); g.setFontAlign(0, 0, 0).setFont(font);
g.setFont("12x20");
const rect = g.stringMetrics(selectedApp.name); const rect = g.stringMetrics(selectedApp.name);
g.clearRect( let r = {
R.w / 2 - rect.width / 2 - 2, x : (R.w - rect.width) / 2 - 7,
appY - rect.height / 2 - 2, y : appY - rect.height / 2 - 6,
R.w / 2 + rect.width / 2 + 1, w : rect.width + 15,
appY + rect.height / 2 + 1 h : rect.height + 10,
); r : 4
g.drawString(selectedApp.name, R.w / 2, appY); };
g.setBgColor(g.theme.bgH).clearRect(r);
g.setBgColor(g.theme.bg2).clearRect({x:r.x+2, y:r.y+2, w:r.w-4, h:r.h-4, r:3}).drawString(selectedApp.name, R.w / 2, appY).reset();
}; };
let selectItem = function(id, e) { let selectItem = function(id, e) {
@ -146,21 +142,15 @@
}; };
//work both the fullscreen and the oneClickExit //work both the fullscreen and the oneClickExit
if( settings.fullscreen && settings.oneClickExit) if( settings.fullscreen && settings.oneClickExit) {
{
idWatch=setWatch(function(e) { idWatch=setWatch(function(e) {
Bangle.showClock(); Bangle.showClock();
}, BTN, {repeat:false, edge:'rising' }); }, BTN, {repeat:false, edge:'rising' });
} } else if( settings.oneClickExit ) {
else if( settings.oneClickExit )
{
options.back=Bangle.showClock; options.back=Bangle.showClock;
} }
let scroller = E.showScroller(options); let scroller = E.showScroller(options);
let timeout; let timeout;

View File

@ -2,7 +2,7 @@
"id": "iconlaunch", "id": "iconlaunch",
"name": "Icon Launcher", "name": "Icon Launcher",
"shortName" : "Icon launcher", "shortName" : "Icon launcher",
"version": "0.19", "version": "0.20",
"icon": "app.png", "icon": "app.png",
"description": "A launcher inspired by smartphones, with an icon-only scrollable menu.", "description": "A launcher inspired by smartphones, with an icon-only scrollable menu.",
"tags": "tool,system,launcher", "tags": "tool,system,launcher",

View File

@ -21,3 +21,4 @@
0.19: Fix regression after back button added (returnToClock was called twice!) 0.19: Fix regression after back button added (returnToClock was called twice!)
0.20: Use Bangle.showClock for changing to clock 0.20: Use Bangle.showClock for changing to clock
0.21: Make the "App source not found" warning less buggy 0.21: Make the "App source not found" warning less buggy
0.22: Add less padding between launcher items, use new font if available in 2v26+

View File

@ -1,93 +1,93 @@
{ // must be inside our own scope here so that when we are unloaded everything disappears { // must be inside our own scope here so that when we are unloaded everything disappears
let s = require("Storage"); let s = require("Storage");
// handle customised launcher // handle customised launcher
let scaleval = 1; let scaleval = 1;
let vectorval = 20; let vectorval = 20;
let font = g.getFonts().includes("12x20") ? "12x20" : "6x8:2"; let font = g.getFonts().includes("12x20") ? "12x20" : "6x8:2";
let settings = Object.assign({ if (g.getFonts().includes("22")) font="22"; // 2v26+
showClocks: true, let settings = Object.assign({
fullscreen: false showClocks: true,
}, s.readJSON("launch.json", true) || {}); fullscreen: false
if ("vectorsize" in settings) }, s.readJSON("launch.json", true) || {});
vectorval = parseInt(settings.vectorsize); if ("vectorsize" in settings)
if ("font" in settings){ vectorval = parseInt(settings.vectorsize);
if(settings.font == "Vector"){ if ("font" in settings){
scaleval = vectorval/20; if(settings.font == "Vector"){
font = "Vector"+(vectorval).toString(); scaleval = vectorval/20;
} else{ font = "Vector"+(vectorval).toString();
font = settings.font; } else{
scaleval = (font.split("x")[1])/20; font = settings.font;
} scaleval = (font.split("x")[1])/20;
}
// cache app list so launcher loads more quickly
let launchCache = s.readJSON("launch.cache.json", true)||{};
let launchHash = require("Storage").hash(/\.info/);
if (launchCache.hash!=launchHash) {
launchCache = {
hash : launchHash,
apps : s.list(/\.info$/)
.map(app=>{var a=s.readJSON(app,1);return a&&{name:a.name,type:a.type,icon:a.icon,sortorder:a.sortorder,src:a.src};})
.filter(app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || !app.type))
.sort((a,b)=>{
var n=(0|a.sortorder)-(0|b.sortorder);
if (n) return n; // do sortorder first
if (a.name<b.name) return -1;
if (a.name>b.name) return 1;
return 0;
}) };
s.writeJSON("launch.cache.json", launchCache);
}
let apps = launchCache.apps;
// Now apps list is loaded - render
if (!settings.fullscreen)
Bangle.loadWidgets();
const drawMenu = () => {
E.showScroller({
h : 64*scaleval, c : apps.length,
draw : (i, r) => {
var app = apps[i];
if (!app) return;
g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1));
g.setFont(font).setFontAlign(-1,0).drawString(app.name,64*scaleval,r.y+(32*scaleval));
if (app.icon) {
if (!app.img) app.img = s.read(app.icon); // load icon if it wasn't loaded
try {g.drawImage(app.img,8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){}
}
},
select : i => {
var app = apps[i];
if (!app) return;
if (!app.src || require("Storage").read(app.src)===undefined) {
E.showScroller();
E.showMessage(/*LANG*/"App Source\nNot found");
setTimeout(drawMenu, 2000);
} else {
load(app.src);
}
},
back : Bangle.showClock, // button press or tap in top left shows clock now
remove : () => {
// cleanup the timeout to not leave anything behind after being removed from ram
if (lockTimeout) clearTimeout(lockTimeout);
Bangle.removeListener("lock", lockHandler);
} }
});
g.flip(); // force a render before widgets have finished drawing
// 10s of inactivity goes back to clock
Bangle.setLocked(false); // unlock initially
let lockTimeout;
let lockHandler = function(locked) {
if (lockTimeout) clearTimeout(lockTimeout);
lockTimeout = undefined;
if (locked)
lockTimeout = setTimeout(Bangle.showClock, 10000);
} }
Bangle.on("lock", lockHandler); // cache app list so launcher loads more quickly
}; let launchCache = s.readJSON("launch.cache.json", true)||{};
drawMenu(); let launchHash = require("Storage").hash(/\.info/);
if (launchCache.hash!=launchHash) {
launchCache = {
hash : launchHash,
apps : s.list(/\.info$/)
.map(app=>{var a=s.readJSON(app,1);return a&&{name:a.name,type:a.type,icon:a.icon,sortorder:a.sortorder,src:a.src};})
.filter(app=>app && (app.type=="app" || (app.type=="clock" && settings.showClocks) || !app.type))
.sort((a,b)=>{
var n=(0|a.sortorder)-(0|b.sortorder);
if (n) return n; // do sortorder first
if (a.name<b.name) return -1;
if (a.name>b.name) return 1;
return 0;
}) };
s.writeJSON("launch.cache.json", launchCache);
}
let apps = launchCache.apps;
// Now apps list is loaded - render
if (!settings.fullscreen)
Bangle.loadWidgets();
if (!settings.fullscreen) // finally draw widgets const drawMenu = () => {
Bangle.drawWidgets(); E.showScroller({
} h : 50*scaleval, c : apps.length,
draw : (i, r) => {
var app = apps[i];
if (!app) return;
g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1)).setFont(font).setFontAlign(-1,0).drawString(app.name,54*scaleval,r.y+(27*scaleval));
if (app.icon) {
if (!app.img) app.img = s.read(app.icon); // load icon if it wasn't loaded
try {g.drawImage(app.img,3*scaleval, r.y+(3*scaleval), {scale: scaleval});} catch(e){}
}
},
select : i => {
var app = apps[i];
if (!app) return;
if (!app.src || require("Storage").read(app.src)===undefined) {
E.showScroller();
E.showMessage(/*LANG*/"App Source\nNot found");
setTimeout(drawMenu, 2000);
} else {
load(app.src);
}
},
back : Bangle.showClock, // button press or tap in top left shows clock now
remove : () => {
// cleanup the timeout to not leave anything behind after being removed from ram
if (lockTimeout) clearTimeout(lockTimeout);
Bangle.removeListener("lock", lockHandler);
}
});
g.flip(); // force a render before widgets have finished drawing
// 10s of inactivity goes back to clock
Bangle.setLocked(false); // unlock initially
let lockTimeout;
let lockHandler = function(locked) {
if (lockTimeout) clearTimeout(lockTimeout);
lockTimeout = undefined;
if (locked)
lockTimeout = setTimeout(Bangle.showClock, 10000);
}
Bangle.on("lock", lockHandler);
};
drawMenu();
if (!settings.fullscreen) // finally draw widgets
Bangle.drawWidgets();
}

View File

@ -2,7 +2,7 @@
"id": "launch", "id": "launch",
"name": "Launcher", "name": "Launcher",
"shortName": "Launcher", "shortName": "Launcher",
"version": "0.21", "version": "0.22",
"description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.", "description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.",
"readme": "README.md", "readme": "README.md",
"icon": "app.png", "icon": "app.png",