Skip to content

Commit 5436722

Browse files
authored
Merge pull request #81 from RKBoss6/master
Add 1 favorite locally when you favorite an app
2 parents a4d1ea6 + f95dcc9 commit 5436722

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

js/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
let appJSON = []; // List of apps and info from apps.json
22
let appSortInfo = {}; // list of data to sort by, from appdates.csv { created, modified }
33
let appCounts = {};
4-
let files = []; // list of files on the Espruimo Device
4+
let files = []; // list of files on the Espruino Device
55
const DEFAULTSETTINGS = {
66
pretokenise : true,
77
minify : false, // disabled by default due to https://github.com/espruino/BangleApps/pull/355#issuecomment-620124162
88
settime : false, // Always update time when we connect
99
favourites : ["launch"],
1010
language : "",
11+
appsFavoritedThisSession : [], // list of apps favourited before database was updated
1112
bleCompat: false, // 20 byte MTU BLE Compatibility mode
1213
sendUsageStats: true, // send usage stats to banglejs.com
13-
alwaysAllowUpdate : false, // Always show "reinstall app" buttonregardless of the version
14+
alwaysAllowUpdate : false, // Always show "reinstall app" button regardless of the version
1415
autoReload: false, // Automatically reload watch after app App Loader actions (removes "Hold button" prompt)
1516
noPackets: false, // Enable File Upload Compatibility mode (disables binary packet upload)
1617
};
@@ -502,8 +503,10 @@ function handleAppInterface(app) {
502503

503504
function changeAppFavourite(favourite, app) {
504505
if (favourite) {
506+
SETTINGS.appsFavoritedThisSession.push({"id":app.id,"favs":appSortInfo[app.id]&&appSortInfo[app.id].favourites?appSortInfo[app.id].favourites:0});
505507
SETTINGS.favourites = SETTINGS.favourites.concat([app.id]);
506508
} else {
509+
SETTINGS.appsFavoritedThisSession = SETTINGS.appsFavoritedThisSession.filter(obj => obj.id !== app.id);
507510
SETTINGS.favourites = SETTINGS.favourites.filter(e => e != app.id);
508511
}
509512
saveSettings();
@@ -556,11 +559,21 @@ function getAppHTML(app, appInstalled, forInterface) {
556559
infoTxt.push(`${info.installs} reported installs (${percentText})`);
557560
}
558561
if (info.favourites) {
562+
let favsThisSession = SETTINGS.appsFavoritedThisSession.find(obj => obj.id === app.id);
559563
let percent=(info.favourites / info.installs * 100).toFixed(0);
560564
let percentText=percent>100?"More than 100% of installs":percent+"% of installs";
561565
if(!info.installs||info.installs<1) {infoTxt.push(`${info.favourites} users favourited`)}
562566
else {infoTxt.push(`${info.favourites} users favourited (${percentText})`)}
563567
appFavourites = info.favourites;
568+
if(favsThisSession){
569+
if(info.favourites!=favsThisSession.favs){
570+
//database has been updated, remove app from favsThisSession
571+
SETTINGS.appsFavoritedThisSession = SETTINGS.appsFavoritedThisSession.filter(obj => obj.id !== app.id);
572+
}
573+
else{
574+
appFavourites += 1; //add one to give the illusion of immediate database changes
575+
}
576+
}
564577
}
565578
if (infoTxt.length)
566579
versionTitle = `title="${infoTxt.join("\n")}"`;
@@ -1350,6 +1363,8 @@ function loadSettings() {
13501363
} catch (e) {
13511364
console.error("Invalid settings");
13521365
}
1366+
// upgrade old settings
1367+
if(!SETTINGS.appsFavoritedThisSession) SETTINGS.appsFavoritedThisSession = [];
13531368
}
13541369
/// Save settings
13551370
function saveSettings() {

0 commit comments

Comments
 (0)