Skip to content

Instantly share code, notes, and snippets.

@modeswitch

modeswitch/gist:9916280

Last active Aug 29, 2015
Embed
What would you like to do?
Cu.import("resource://services-cloudsync/main.js");
let service = Cc["@mozilla.org/cloudsync/service;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
service.whenLoaded().then(() => {
// Cloudsync is ready, do work
CloudSync.Local.id; // local device id
CloudSync.Local.name; // local device name
CloudSync.Tabs.{add,remove}EventListener("Change", callback); // listen for tab change events
CloudSync.Tabs.setRemoteTabs([...]);
* {
client: {
id:
name:
isMobile:
},
tabs: [ {title: , urlHistory: , icon: }, ... ]
timestamp:
}
CloudSync.getLocalTabs();
* {
title:
urlHistory:
icon:
lastUsed:
}
var folder = CloudSync.Bookmarks.getRootFolder("My Adapter");
CloudSync.Bookmarks.deleteRootFolder("My Adapter");
folder.{add,remove}EventListener("ChangeBookmark", callback(guid)); // listen for bookmark change events
folder.{add,remove}EventListener("RemoveBookmark", callback(guid)); // listen for bookmark remove events
folder.{add,remove}EventListener("AddBookmark", callback(guid)); // listen for bookmark add events
folder.{add,remove}EventListener("MoveBookmark", callback(guid)); // listen for bookmark move events
folder.{add,remove}EventListener("RemoveRootFolder", callback(guid)); // listen for bookmark root folder remove events
folder.getLocalBookmarks(); // returns a list of bookmarks
* {
id: // guid
parent: // guid
dateAdded:
lastModified:
uri: // null for FOLDER and SEPARATOR
title:
type: // should be one of folder.{BOOKMARK, FOLDER, SEPARATOR},
index: // must be unique among folder items
}
folder.getLocalBookmarksByGuid([guid, ...]); // returns a list of bookmarks corresponding to the list of guids
* {
id: // guid
parent: // guid
dateAdded:
lastModified:
uri: // null for FOLDER and SEPARATOR
title:
type: // should be one of folder.{BOOKMARK, FOLDER, SEPARATOR},
index: // must be unique among folder items
}
folder.mergeRemoteBookmarks([...]);
* {
id: // guid
parent: // guid
dateAdded:
lastModified:
uri: // null for FOLDER and SEPARATOR
title:
type: // should be one of folder.{BOOKMARK, FOLDER, SEPARATOR},
index: // must be unique among folder items
deleted:
}
* if id doesn't exist and !deleted, create bookmark
* if id exists and deleted, delete bookmark
* if id exists and !deleted, update bookmark
* only given fields are updated (omit fields to leave them unchanged)
CloudSync.Adapter.register("My Adapter"); // call once when addon is installed
CloudSync.Adapter.unregister("My Adapter"); // call once when addon is removed
});
@modeswitch

This comment has been minimized.

Copy link
Owner Author

@modeswitch modeswitch commented Apr 1, 2014

Possible additions to the API:

  • folder.clearLocalBookmarks();
  • folder.rename("Renamed Adapter");
@ckarlof

This comment has been minimized.

Copy link

@ckarlof ckarlof commented May 16, 2014

Can you give some idea of the recommended usage of this API?

@ckarlof

This comment has been minimized.

Copy link

@ckarlof ckarlof commented May 16, 2014

The functions that interact with the underlying data should be async.

@modeswitch

This comment has been minimized.

Copy link
Owner Author

@modeswitch modeswitch commented May 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment