|
1 | 1 | let appJSON = []; // List of apps and info from apps.json |
2 | 2 | let appSortInfo = {}; // list of data to sort by, from appdates.csv { created, modified } |
3 | 3 | let appCounts = {}; |
4 | | -let files = []; // list of files on the Espruimo Device |
| 4 | +let files = []; // list of files on the Espruino Device |
5 | 5 | const DEFAULTSETTINGS = { |
6 | 6 | pretokenise : true, |
7 | 7 | minify : false, // disabled by default due to https://github.com/espruino/BangleApps/pull/355#issuecomment-620124162 |
8 | 8 | settime : false, // Always update time when we connect |
9 | 9 | favourites : ["launch"], |
10 | 10 | language : "", |
| 11 | + appsFavoritedThisSession : [], // list of apps favourited before database was updated |
11 | 12 | bleCompat: false, // 20 byte MTU BLE Compatibility mode |
12 | 13 | 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 |
14 | 15 | autoReload: false, // Automatically reload watch after app App Loader actions (removes "Hold button" prompt) |
15 | 16 | noPackets: false, // Enable File Upload Compatibility mode (disables binary packet upload) |
16 | 17 | }; |
@@ -502,8 +503,10 @@ function handleAppInterface(app) { |
502 | 503 |
|
503 | 504 | function changeAppFavourite(favourite, app) { |
504 | 505 | if (favourite) { |
| 506 | + SETTINGS.appsFavoritedThisSession.push({"id":app.id,"favs":appSortInfo[app.id]&&appSortInfo[app.id].favourites?appSortInfo[app.id].favourites:0}); |
505 | 507 | SETTINGS.favourites = SETTINGS.favourites.concat([app.id]); |
506 | 508 | } else { |
| 509 | + SETTINGS.appsFavoritedThisSession = SETTINGS.appsFavoritedThisSession.filter(obj => obj.id !== app.id); |
507 | 510 | SETTINGS.favourites = SETTINGS.favourites.filter(e => e != app.id); |
508 | 511 | } |
509 | 512 | saveSettings(); |
@@ -556,11 +559,21 @@ function getAppHTML(app, appInstalled, forInterface) { |
556 | 559 | infoTxt.push(`${info.installs} reported installs (${percentText})`); |
557 | 560 | } |
558 | 561 | if (info.favourites) { |
| 562 | + let favsThisSession = SETTINGS.appsFavoritedThisSession.find(obj => obj.id === app.id); |
559 | 563 | let percent=(info.favourites / info.installs * 100).toFixed(0); |
560 | 564 | let percentText=percent>100?"More than 100% of installs":percent+"% of installs"; |
561 | 565 | if(!info.installs||info.installs<1) {infoTxt.push(`${info.favourites} users favourited`)} |
562 | 566 | else {infoTxt.push(`${info.favourites} users favourited (${percentText})`)} |
563 | 567 | 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 | + } |
564 | 577 | } |
565 | 578 | if (infoTxt.length) |
566 | 579 | versionTitle = `title="${infoTxt.join("\n")}"`; |
@@ -1350,6 +1363,8 @@ function loadSettings() { |
1350 | 1363 | } catch (e) { |
1351 | 1364 | console.error("Invalid settings"); |
1352 | 1365 | } |
| 1366 | + // upgrade old settings |
| 1367 | + if(!SETTINGS.appsFavoritedThisSession) SETTINGS.appsFavoritedThisSession = []; |
1353 | 1368 | } |
1354 | 1369 | /// Save settings |
1355 | 1370 | function saveSettings() { |
|
0 commit comments