Adding My World widgets
This guide assumes you already know about writing extensions for Flock.
The basics of getting your widget into My World is fairly straight forward. All you need to do is insert your widget into the list of available widgets.
var CC = Components.classes;
var CI = Components.interfaces;
var CR = Components.results;
const CU = Components.utils;
CU.import("resource://gre/modules/JSON.jsm");
const PREF_MYWORLD_WIDGETS_LAYOUT = "flock.myworld.widgets.layout";
var prefService = CC["@mozilla.org/preferences-service;1"]
.getService(CI.nsIPrefBranch);
if (prefService.getPrefType(PREF_MYWORLD_WIDGETS_LAYOUT)) {
var layoutString = prefService.getComplexValue(PREF_MYWORLD_WIDGETS_LAYOUT,
CI.nsIPrefLocalizedString).data;
var layoutObj = eval(JSON.fromString(layoutString));
layoutObj.push({
index: layoutObj.length,
label: "NewWidgetName",
url: "chrome://myWidgetExtension/content/myextension.xul",
show: "false"
});
var newLayoutString = JSON.toString(layoutObj);
prefService.setCharPref(PREF_MYWORLD_WIDGETS_LAYOUT, newLayoutString);
}
This will insert your widget's chrome URL into the widgets drop down on My World. My World will need to be manually refreshed or re-opened to reflect the changes.
Note: At present, this will not actually insert your widget. As explained in bug 12282, there's an issue with how MyWorld gets strings for displaying the widget that prevents extensions from adding widgets to display (though the code above does add them to the pref that the display code uses to find widgets). Until this bug is resolved, one has to hack a properties file within the build to get MyWorld widgets created by extensions to display.
Note: There is a MyWorld widget under development, codenamed "Hobo".