diff --git a/CHANGELOG.md b/CHANGELOG.md index 5255232..e595839 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Added Start, Stop, Pause, and Resume methods to Animation interface * Added "transform" property and Transform interface * Added OpenRawResource function +* Added RemoveClientItem method to Session interface # v0.16.0 * Can use ListAdapter as "content" property value of ListLayout diff --git a/app_scripts.js b/app_scripts.js index 0b31b0a..afa0445 100644 --- a/app_scripts.js +++ b/app_scripts.js @@ -1982,7 +1982,15 @@ function getCanvasContext(elementId) { function localStorageSet(key, value) { try { - localStorage.setItem(key, value) + localStorage.setItem(key, value); + } catch (err) { + sendMessage("storageError{session=" + sessionID + ", error=`" + err + "`}") + } +} + +function localStorageRemove(key) { + try { + localStorage.removeItem(key); } catch (err) { sendMessage("storageError{session=" + sessionID + ", error=`" + err + "`}") } @@ -1990,7 +1998,7 @@ function localStorageSet(key, value) { function localStorageClear() { try { - localStorage.setItem(key, value) + localStorage.clear(); } catch (err) { sendMessage("storageError{session=" + sessionID + ", error=`" + err + "`}") } diff --git a/session.go b/session.go index be59c03..5ebe916 100644 --- a/session.go +++ b/session.go @@ -103,6 +103,8 @@ type Session interface { ClientItem(key string) (string, bool) // SetClientItem stores a key-value pair in the client-side storage SetClientItem(key, value string) + // RemoveClientItem removes a key-value pair in the client-side storage + RemoveClientItem(key string) // RemoveAllClientItems removes all key-value pair from the client-side storage RemoveAllClientItems() @@ -879,6 +881,11 @@ func (session *sessionData) SetClientItem(key, value string) { session.bridge.callFunc("localStorageSet", key, value) } +func (session *sessionData) RemoveClientItem(key string) { + delete(session.clientStorage, key) + session.bridge.callFunc("localStorageRemove", key) +} + func (session *sessionData) RemoveAllClientItems() { session.clientStorage = map[string]string{} session.bridge.callFunc("localStorageClear")