Skip to content

Commit 18c8338

Browse files
authored
Merge pull request #4282 from nxdefiant/master
taglaunch: fastload
2 parents ec1f626 + badf4b2 commit 18c8338

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

apps/taglaunch/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
0.07: Clear cached app list when updating showClocks setting
99
0.08: Add haptic feedback option when selecting app or category in menu, increase vector size limit in settings
1010
0.09: Add option to set up to 3 shortcut apps that you can access straight from the tag menu for quicker access
11+
0.10: Fast load apps similar to launcher_utils library

apps/taglaunch/app.js

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if ("font" in settings){
3131
scaleval = (font.split("x")[1])/20;
3232
}
3333
}
34+
const appimgs = {};
3435

3536
let sort = (a, b) => {
3637
let n=(0|a.sortorder)-(0|b.sortorder);
@@ -42,7 +43,7 @@ let sort = (a, b) => {
4243

4344
// cache app list so launcher loads more quickly
4445
let launchCache = s.readJSON("taglaunch.cache.json", true)||{};
45-
let launchHash = require("Storage").hash(/\.info/);
46+
let launchHash = s.hash(/\.info/);
4647
if (launchCache.hash!=launchHash) {
4748
let appsByTag = Object.keys(tags).reduce((acc,curr)=> (acc[curr]=[],acc),{});
4849
s.list(/\.info$/).map(app=>s.readJSON(app,1))
@@ -86,7 +87,7 @@ const unload = () => {
8687

8788
let shortcuts=settings.shortcuts;
8889
let noShortcuts=shortcuts[0]==""&&shortcuts[1]==""&&shortcuts[2]=="";
89-
90+
9091
let loadShortcut=function(idx){
9192
if(shortcuts[idx]!=""){
9293
const p = settings.buzz ? Bangle.buzz(25) : Promise.resolve();
@@ -113,30 +114,41 @@ let showTagMenu = (tag) => {
113114
g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1));
114115
g.setFont(font).setFontAlign(-1,0).drawString(app.name,64*scaleval,r.y+(32*scaleval));
115116
if (app.icon) {
116-
if (!app.img) app.img = s.read(app.icon); // load icon if it wasn't loaded
117-
try {g.drawImage(app.img,8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){}
117+
if (!appimgs[app.id]) appimgs[app.id] = s.read(app.icon); // load icon if it wasn't loaded
118+
try {g.drawImage(appimgs[app.id],8*scaleval, r.y+(8*scaleval), {scale: scaleval});} catch(e){}
118119
}
119120
},
120121
select : i => {
121122
const loadApp = () => {
122123
let app = appsByTag[tag][i];
123124
if (!app) return;
124-
if (!app.src || require("Storage").read(app.src)===undefined) {
125+
if (!app.src || s.read(app.src)===undefined) {
125126
Bangle.setUI();
126127
E.showMessage(/*LANG*/"App Source\nNot found");
127128
setTimeout(showMainMenu, 2000);
128129
} else {
129-
load(app.src);
130+
if (app.wid===undefined) {
131+
// If we hadn't stored whether the app uses widgets before, check now
132+
let src = s.read(app.src);
133+
app.wid = (src!==undefined)&&src.includes("Bangle.loadWidgets");
134+
s.writeJSON("taglaunch.cache.json", launchCache);
135+
}
136+
if (app.wid || global.WIDGETS===undefined) Bangle.load(app.src); // if app uses widgets or we don't have any, we can fast load into it
137+
else if (Object.keys(WIDGETS).every(w=>!!WIDGETS[w].remove)) { // are widgets unloadable? !! needed before 2v29 fw
138+
Object.keys(WIDGETS).forEach(w=>WIDGETS[w].remove());
139+
delete global.WIDGETS;
140+
Bangle.load(app.src);
141+
} else load(app.src); // otherwise default to slow load
130142
}
131-
};
143+
};
132144
if(settings.buzz){
133145
Bangle.buzz(25);
134146
//let the buzz have effect
135147
setTimeout(loadApp,27);
136148
}else{
137149
loadApp();
138150
}
139-
151+
140152
},
141153
back : showMainMenu,
142154
remove: unload
@@ -149,7 +161,7 @@ let showMainMenu = () => {
149161
h : 64*scaleval, c : noShortcuts ? tagKeys.length : tagKeys.length+1,
150162
draw : (i, r) => {
151163
g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1));
152-
164+
153165
if(!noShortcuts)i-=1;
154166
if(i==-1){
155167
for(let j=0;j<3;j++){
@@ -161,7 +173,7 @@ let showMainMenu = () => {
161173
}
162174
}
163175

164-
176+
165177
}else{
166178
let tag = tagKeys[i]; g.setFont(font).setFontAlign(-1,0).drawString(tags[tag].name,64*scaleval,r.y+(32*scaleval));
167179

@@ -175,11 +187,11 @@ let showMainMenu = () => {
175187
if(!noShortcuts)i-=1;
176188
if(i==-1){
177189
if(e.x<g.getWidth()/3){
178-
loadShortcut(0)
179-
}else if(e.x<(g.getWidth()/3)*2){
180-
loadShortcut(1)
181-
}else{
182-
loadShortcut(2)
190+
loadShortcut(0);
191+
}else if(e.x<(g.getWidth()/3)*2){
192+
loadShortcut(1);
193+
}else{
194+
loadShortcut(2);
183195
}
184196
}else{
185197
if(settings.buzz)Bangle.buzz(25);

apps/taglaunch/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "taglaunch",
33
"name": "Tag Launcher",
44
"shortName": "Taglauncher",
5-
"version": "0.09",
5+
"version": "0.10",
66
"author": "nxdefiant",
77
"description": "Launcher that puts all applications into submenus based on their tag, with three customizable app shortcuts at the top. With many applications installed this can result in a faster application selection than the linear access from the default launcher.",
88
"readme": "README.md",

0 commit comments

Comments
 (0)