mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
config: Catch exceptions from localStorage usage
localStorage may not be available e.g. in incognito sessions.
This commit is contained in:
parent
8e57250047
commit
9560744930
1 changed files with 16 additions and 3 deletions
19
src/config.c
19
src/config.c
|
@ -54,7 +54,11 @@ SYMBOL_EXPORT void SetConfigOption(struct Game* game, char* section, char* name,
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
EM_ASM({
|
EM_ASM({
|
||||||
var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1);
|
var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1);
|
||||||
window.localStorage.setItem(key, UTF8ToString($2));
|
try {
|
||||||
|
window.localStorage.setItem(key, UTF8ToString($2));
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
section, name, value);
|
section, name, value);
|
||||||
#endif
|
#endif
|
||||||
|
@ -65,7 +69,12 @@ SYMBOL_EXPORT const char* GetConfigOption(struct Game* game, char* section, char
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
char* buf = (char*)EM_ASM_INT({
|
char* buf = (char*)EM_ASM_INT({
|
||||||
var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1);
|
var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1);
|
||||||
var value = window.localStorage.getItem(key);
|
var value;
|
||||||
|
try {
|
||||||
|
value = window.localStorage.getItem(key);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
if (value) {
|
if (value) {
|
||||||
var buf = _malloc(255);
|
var buf = _malloc(255);
|
||||||
stringToUTF8(value, buf, 255);
|
stringToUTF8(value, buf, 255);
|
||||||
|
@ -92,7 +101,11 @@ SYMBOL_EXPORT void DeleteConfigOption(struct Game* game, char* section, char* na
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
EM_ASM({
|
EM_ASM({
|
||||||
var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1);
|
var key = '[' + UTF8ToString($0) + '] ' + UTF8ToString($1);
|
||||||
window.localStorage.removeItem(key);
|
try {
|
||||||
|
window.localStorage.removeItem(key);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
section, name);
|
section, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue