Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use chrome.storage to sync data #2

Open
midenok opened this issue Oct 24, 2018 · 1 comment
Open

Use chrome.storage to sync data #2

midenok opened this issue Oct 24, 2018 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@midenok
Copy link
Member

midenok commented Oct 24, 2018

https://developer.chrome.com/extensions/storage

As per QUOTA_BYTES of chrome.storage.sync max data size is 100 KiB. That should be enough to store all styles data (possibly compressed) for most user needs. If there is not enough room, user should choose which styles to not sync.

Links

@midenok midenok added the enhancement New feature or request label Oct 24, 2018
@midenok midenok self-assigned this Oct 24, 2018
@midenok
Copy link
Member Author

midenok commented Jan 19, 2019

Currently data is stored in WebSQL (storage-websql.js, storage.js)

https://www.w3.org/TR/webdatabase/

function saveStyle(o, callback) {
	getDatabase(function(db) {
		var tx = db.transaction(["styles"], "readwrite");
		var os = tx.objectStore("styles");

		// Update
		if (o.id) {
			var request = os.get(Number(o.id));
			request.onsuccess = function(event) {
				var style = request.result || {};
				for (var prop in o) {
					if (prop == "id") {
						continue;
					}
					style[prop] = o[prop];
				}
				request = os.put(style);
				request.onsuccess = function(event) {
					notifyAllTabs({method: "styleUpdated", style: style});
					invalidateCache(true);
					if (callback) {
						callback(style);
					}
				};
			};
			return;
		}

The best way maybe is to imitate API (getDatabase, db, tx, os) for chrome.storage in storage-chrome.js.

TODO: look how it works in latest plugin version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant