mirror of https://github.com/espruino/BangleApps
Try new JSON settings format
parent
60a8c487ad
commit
d4ddf22399
|
@ -35,8 +35,9 @@ const otpAuthUrl = 'otpauth://';
|
||||||
|
|
||||||
const tokentypes = ['TOTP (Timed)', 'HOTP (Counter)'];
|
const tokentypes = ['TOTP (Timed)', 'HOTP (Counter)'];
|
||||||
|
|
||||||
/* Array of TOTP tokens */
|
/* Settings */
|
||||||
var tokens=[];
|
var settings = {tokens:[], misc:{}};
|
||||||
|
var tokens = settings.tokens;
|
||||||
|
|
||||||
/* Remove any non-base-32 characters from the given string and collapses
|
/* Remove any non-base-32 characters from the given string and collapses
|
||||||
* whitespace to a single space. Optionally removes all whitespace from
|
* whitespace to a single space. Optionally removes all whitespace from
|
||||||
|
@ -319,23 +320,21 @@ function doScan() {
|
||||||
*/
|
*/
|
||||||
function loadTokens() {
|
function loadTokens() {
|
||||||
Util.showModal('Loading...');
|
Util.showModal('Loading...');
|
||||||
Puck.eval(`require('Storage').read(${JSON.stringify('authentiwatch.json')})`,data=>{
|
Puck.eval(`require('Storage').readJSON(${JSON.stringify('authentiwatch.json')})`,data=>{
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
try {
|
if (data.data ) settings.tokens = data.data ; /* v0.02 settings */
|
||||||
let load = JSON.parse(data);
|
if (data.tokens) settings.tokens = data.tokens; /* v0.03+ settings */
|
||||||
tokens = load.data;
|
if (data.misc ) settings.misc = data.misc ; /* v0.03+ settings */
|
||||||
updateTokens();
|
tokens = settings.tokens;
|
||||||
} catch {
|
updateTokens();
|
||||||
tokens = [];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/* Save settings as a JSON file on the watch.
|
/* Save settings as a JSON file on the watch.
|
||||||
*/
|
*/
|
||||||
function saveTokens() {
|
function saveTokens() {
|
||||||
Util.showModal('Saving...');
|
Util.showModal('Saving...');
|
||||||
let save={data:tokens,count:tokens.length};
|
let newsettings={tokens:tokens,misc:settings.misc};
|
||||||
Puck.write(`\x10require('Storage').write(${JSON.stringify('authentiwatch.json')},${JSON.stringify(save)})\n`,()=>{
|
Puck.write(`\x10require('Storage').writeJSON(${JSON.stringify('authentiwatch.json')},${JSON.stringify(newsettings)})\n`,()=>{
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue