mirror of https://github.com/espruino/BangleApps
popconlaunch: avoid polluting global scope
parent
1cbda278fe
commit
b4d46d5779
|
@ -1,29 +1,29 @@
|
|||
{
|
||||
var oldRead_1 = require("Storage").readJSON;
|
||||
var monthAgo_1 = Date.now() - 1000 * 86400 * 28;
|
||||
var cache_1;
|
||||
var ensureCache_1 = function () {
|
||||
if (!cache_1) {
|
||||
cache_1 = oldRead_1("popcon.cache.json", true);
|
||||
if (!cache_1)
|
||||
cache_1 = {};
|
||||
(function () {
|
||||
var oldRead = require("Storage").readJSON;
|
||||
var monthAgo = Date.now() - 1000 * 86400 * 28;
|
||||
var cache;
|
||||
var ensureCache = function () {
|
||||
if (!cache) {
|
||||
cache = oldRead("popcon.cache.json", true);
|
||||
if (!cache)
|
||||
cache = {};
|
||||
}
|
||||
return cache_1;
|
||||
return cache;
|
||||
};
|
||||
var saveCache_1 = function (orderChanged) {
|
||||
require("Storage").writeJSON("popcon.cache.json", cache_1);
|
||||
var saveCache = function (orderChanged) {
|
||||
require("Storage").writeJSON("popcon.cache.json", cache);
|
||||
if (orderChanged) {
|
||||
var info = oldRead_1("popcon.info", true);
|
||||
var info = oldRead("popcon.info", true);
|
||||
info.cacheBuster = !info.cacheBuster;
|
||||
require("Storage").writeJSON("popcon.info", info);
|
||||
}
|
||||
};
|
||||
var sortCache_1 = function () {
|
||||
var ents = Object.values(cache_1);
|
||||
var sortCache = function () {
|
||||
var ents = Object.values(cache);
|
||||
ents.sort(function (a, b) {
|
||||
var n;
|
||||
var am = (a.last > monthAgo_1);
|
||||
var bm = (b.last > monthAgo_1);
|
||||
var am = (a.last > monthAgo);
|
||||
var bm = (b.last > monthAgo);
|
||||
n = bm - am;
|
||||
if (n)
|
||||
return n;
|
||||
|
@ -51,31 +51,31 @@
|
|||
};
|
||||
require("Storage").readJSON = (function (fname, skipExceptions) {
|
||||
var _a;
|
||||
var j = oldRead_1(fname, skipExceptions);
|
||||
var j = oldRead(fname, skipExceptions);
|
||||
if (/\.info$/.test(fname)) {
|
||||
var cache_2 = ensureCache_1();
|
||||
var cache_1 = ensureCache();
|
||||
var so = void 0;
|
||||
if (j.src && (so = (_a = cache_2[j.src]) === null || _a === void 0 ? void 0 : _a.sortorder) != null)
|
||||
if (j.src && (so = (_a = cache_1[j.src]) === null || _a === void 0 ? void 0 : _a.sortorder) != null)
|
||||
j.sortorder = so;
|
||||
else
|
||||
j.sortorder = 99;
|
||||
}
|
||||
return j;
|
||||
});
|
||||
var oldLoad_1 = load;
|
||||
var oldLoad = load;
|
||||
global.load = function (src) {
|
||||
if (src) {
|
||||
var cache_3 = ensureCache_1();
|
||||
var ent = cache_3[src] || (cache_3[src] = {
|
||||
var cache_2 = ensureCache();
|
||||
var ent = cache_2[src] || (cache_2[src] = {
|
||||
pop: 0,
|
||||
last: 0,
|
||||
sortorder: -10,
|
||||
});
|
||||
ent.pop++;
|
||||
ent.last = Date.now();
|
||||
var orderChanged = sortCache_1();
|
||||
saveCache_1(orderChanged);
|
||||
var orderChanged = sortCache();
|
||||
saveCache(orderChanged);
|
||||
}
|
||||
return oldLoad_1(src);
|
||||
return oldLoad(src);
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
(() => {
|
||||
type Timestamp = number;
|
||||
|
||||
const oldRead = require("Storage").readJSON;
|
||||
|
@ -99,4 +99,4 @@ global.load = (src: string) => {
|
|||
|
||||
return oldLoad(src);
|
||||
};
|
||||
}
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue