Confirmed users
188
edits
(Add Jono's awesome guide from hg to Wiki for easier editing and wider audience) |
No edit summary |
||
| Line 2: | Line 2: | ||
== Create your Engine == | == Create your Engine == | ||
To weave/modules/engines.js, add a new subclass of Engine. This is pretty simple: it just needs name(), logName(), and serverPrefix() methods that return strings; an attribute _core which is a SyncCore subclass object; | To weave/modules/engines.js, add a new subclass of Engine. This is pretty simple: it just needs name(), logName(), and serverPrefix() methods that return strings; an attribute _core which is a SyncCore subclass object; an attribute _store which is a Store subclass object; and finally _tracker which is a Tracker subclass object. Just take a look at the existing Engine subclasses in engines.js and you'll see how to add a new one pretty easily. | ||
Make sure to add the name of your new engine to EXPORTED_SYMBOLS at the top of engines.js. | Make sure to add the name of your new engine to EXPORTED_SYMBOLS at the top of engines.js. | ||
| Line 29: | Line 29: | ||
* '''_commandLike( a, b )''': is passed two command objects as arguments. It should return True if the two commands are determined to refer to the same thing. This is meant to eliminate duplicate or redundant commands. See the implementation of BookmarkSyncCore._commandLike() for inspiration. | * '''_commandLike( a, b )''': is passed two command objects as arguments. It should return True if the two commands are determined to refer to the same thing. This is meant to eliminate duplicate or redundant commands. See the implementation of BookmarkSyncCore._commandLike() for inspiration. | ||
== Create your Tracker == | |||
The Weave service periodically queries each of its registered engines via its tracker to decide whether that particular engine needs to be synced or not. In weave/modules/trackers.js, you'll need to create a a subclass of Tracker, and add it to EXPORTED_SYMBOLS. | |||
The Tracker object has a getter method '''score()''' that simply returns the ''_score'' property. In your subclass, you may either choose to override the getter, or simply update the ''_score'' property in an Observer. Which method you choose is dependent on the engine, but the idea is to return a number between 0 and 100 whenever the weave service uses the getter. 0 means there has been no change in your data source, 100 means that your engine really needs to sync ASAP. A special value of -1 is also recognized - it means the service doesn't need to sync unless the user explicitly requests it (useful for engines like Session/Tab restore). Note that a value of 0 means the service will not try to sync even if it was explicitly requested by the user (because there is nothing to sync). | |||
The other important method is '''resetScore()''', which is called immediately after the service has synced the engine. The default behavior of this method sets ''_score'' to 0, but you may choose to override it and do something else. | |||
You are encouraged take a look at the existing trackers to get an idea of how they are implemented. | |||
== Final touches == | == Final touches == | ||
Once you've created an engine, syncCore, and | Once you've created an engine, syncCore, store, and tracker, you'll need to make sure that your Engine is instantiated and registered in services.js, in the function WeaveSvc(). Look for where the existing engines are registered (to Engines.register) and add yours. | ||
The last thing is to add your new data type to the Weave preferences UI. Look in weave/chrome/content/preferences.xul for the boolean preferences called extensions.weave.bookmarks, extensions.weave.history, etc. They're boolean preferences because they're checkboxes which turn synchronization of a given datatype on or off. Add one for your datatype using the existing XUL tags as a model. | The last thing is to add your new data type to the Weave preferences UI. Look in weave/chrome/content/preferences.xul for the boolean preferences called extensions.weave.bookmarks, extensions.weave.history, etc. They're boolean preferences because they're checkboxes which turn synchronization of a given datatype on or off. Add one for your datatype using the existing XUL tags as a model. | ||