1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

BrowserStorage: Add support for a custom quota exceeded message

This commit is contained in:
Jermolene 2019-02-07 14:46:23 +00:00
parent 51b4f63c5c
commit 5577f7a4fe
2 changed files with 9 additions and 2 deletions

View File

@ -4,3 +4,6 @@ This filter determines which tiddlers will be saved to local storage. By default
<$link to="$:/config/BrowserStorage/SaveFilter">Browser Storage Save Filter</$link>: <$edit-text tiddler="$:/config/BrowserStorage/SaveFilter" default="" tag="input" size="50"/> <$link to="$:/config/BrowserStorage/SaveFilter">Browser Storage Save Filter</$link>: <$edit-text tiddler="$:/config/BrowserStorage/SaveFilter" default="" tag="input" size="50"/>
This setting allows a custom alert message to be displayed when an attempt to store a tiddler fails due to the storage quota being exceeded:
<$link to="$:/config/BrowserStorage/QuotaExceededAlert">Quota Exceeded Alert</$link>: <$edit-text tiddler="$:/config/BrowserStorage/QuotaExceededAlert" default="" tag="input" size="50"/>

View File

@ -18,7 +18,10 @@ exports.platforms = ["browser"];
exports.after = ["load-modules"]; exports.after = ["load-modules"];
exports.synchronous = true; exports.synchronous = true;
var SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter" var SAVE_FILTER_TITLE = "$:/config/BrowserStorage/SaveFilter",
QUOTA_EXCEEDED_ALERT_TITLE = "$:/config/BrowserStorage/QuotaExceededAlert",
DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX = "Quota exceeded attempting to store `",
DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX = "` in browser local storage";
exports.startup = function() { exports.startup = function() {
var self = this; var self = this;
@ -61,7 +64,8 @@ console.log("Filtered changes",filteredChanges)
} catch(e) { } catch(e) {
if(e.name === "QuotaExceededError") { if(e.name === "QuotaExceededError") {
// Complain if we failed // Complain if we failed
logger.alert("Quota exceeded trying to store '" + title + "' in browser local storage"); var msg = $tw.wiki.getTiddlerText(QUOTA_EXCEEDED_ALERT_TITLE,DEFAULT_QUOTA_EXCEEDED_ALERT_PREFIX + title + DEFAULT_QUOTA_EXCEEDED_ALERT_SUFFIX);
logger.alert(msg);
// No point in keeping old values around for this tiddler // No point in keeping old values around for this tiddler
window.localStorage.removeItem(prefix + title); window.localStorage.removeItem(prefix + title);
} else { } else {