Files
SubMusic/source/Store/Store.mc
Memen 1f3fba2289 fixed settings storage having 0 Bytes
fixed some rare crashes on receiving invalid response
added setting to enable debug logging
removed default debug output (speed improvement)
2023-02-20 15:42:22 +01:00

40 lines
807 B
MonkeyC

using Toybox.Application;
using Toybox.System;
class Store {
private var d_key; // key to set/retrieve the stored data
private var d_value = null; // variable that is reflected in the Application.Storage
function initialize(key, value) {
if ($.debug) {
System.println("Store::initialize( key: " + key + " value: " + value + " )");
}
d_key = key;
var stored = Application.Storage.getValue(d_key);
if (stored != null) {
d_value = stored;
return;
}
d_value = value;
}
function value() {
return d_value;
}
function setValue(value) {
d_value = value;
}
function update() {
var success = true;
try {
Application.Storage.setValue(d_key, d_value);
} catch (exception instanceof Toybox.Lang.StorageFullException) {
success = false;
}
return success;
}
}