mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Browser-storage: Handle quota exceeded error
This commit is contained in:
		| @@ -21,14 +21,32 @@ exports.synchronous = true; | ||||
| exports.startup = function() { | ||||
| 	// Compute our prefix for local storage keys | ||||
| 	var url = window.location.protocol === "file:" ? window.location.pathname : "", | ||||
| 		prefix = "tw5#" + url + "#" | ||||
| 		prefix = "tw5#" + url + "#"; | ||||
| 	// Make a logger | ||||
| 	var logger = new $tw.utils.Logger("browser-storage",{ | ||||
| 			colour: "cyan" | ||||
| 		}); | ||||
| 	// Track tiddler changes | ||||
| 	$tw.wiki.addEventListener("change",function(changes) { | ||||
| 		$tw.utils.each(changes,function(change,title) { | ||||
| 			// Get the tiddler | ||||
| 			var tiddler = $tw.wiki.getTiddler(title); | ||||
| 			if(tiddler) { | ||||
| 				// Get the JSON of the tiddler				 | ||||
| 				var json = JSON.stringify(tiddler.getFieldStrings()); | ||||
| 				window.localStorage.setItem(prefix + title,json); | ||||
| 				// Try to save it to local storage | ||||
| 				try { | ||||
| 					window.localStorage.setItem(prefix + title,json); | ||||
| 				} catch(e) { | ||||
| 					if(e.name === "QuotaExceededError") { | ||||
| 						// Complain if we failed | ||||
| 						logger.alert("Quota exceeded trying to store '" + title + "' in browser local storage"); | ||||
| 						// No point in keeping old values around for this tiddler | ||||
| 						window.localStorage.removeItem(prefix + title); | ||||
| 					} else { | ||||
| 						throw e; | ||||
| 					} | ||||
| 				} | ||||
| 				console.log("browser-storage: Saving",title); | ||||
| 			} else { | ||||
| 				window.localStorage.removeItem(prefix + title); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jermolene
					Jermolene