我正在开发一个 firefox for android addon 。我想要一个Home.panel。在主页面板中,我想有两个不同的观点。首先,我会有一个书签列表,其次是一个带有一些选项的网格。 我有这样做的非常好的原因。
到目前为止,我已经尝试了以下内容:
const {Cu} = require("chrome");
Cu.import("resource://gre/modules/Home.jsm");
Cu.import("resource://gre/modules/HomeProvider.jsm");
Cu.import("resource://gre/modules/Task.jsm");
const PANEL_ID = "aurora_suite_pannel@ats.com";
const BOOKMARKS_DATASET_ID = "as_bookmarks_dataset@ats.com";
const MAINMENU_DATASET_ID = "as_mainmenu_dataset@ats.com";
function syncData2() {
console.debug("Syncronizando ...");
var bookmarks = [
// An item
{
url: "http://example.com/",
title: "Example Web Site" ,
description: "This is an example of a bookmark",
image_url: "http://example.com/example.png"
}
];
var mainMenuItems = [
{
url: require("sdk/self").data.url("test.html"),
title: "Grid item",
description: "This is a Grid item",
image_url: "http://example.com/test.png"
}
];
Task.spawn(function() {
let bookmarksStorage = HomeProvider.getStorage(BOOKMARKS_DATASET_ID);
let mainMenuStorage = HomeProvider.getStorage(MAINMENU_DATASET_ID);
console.debug("Actual synching process. storage");
// New way to replace items in Firefox 31+
yield bookmarksStorage.save(bookmarks, { replace: true });
yield mainMenuStorage.save(mainMenuItems, { replace: true });
});
}
function optionsCallback() {
return {
title: "My Addon Panel",
views: [{
type: Home.panels.View.LIST,
dataset: BOOKMARKS_DATASET_ID,
// optional, only used if there's a filter applied after clicking on an item
backImageUrl: "myBackIcon.png",
// optional, defaults to BROWSER (can also specify INTENT to launch an intent)
itemType: Home.panels.Item.ARTICLE,
itemHandler: Home.panels.ItemHandler.BROWSER
}, {
type: Home.panels.View.GRID,
dataset: MAINMENU_DATASET_ID,
// optional, only used if there's a filter applied after clicking on an item
backImageUrl: "myBackIcon.png",
// optional, defaults to BROWSER (can also specify INTENT to launch an intent)
itemType: Home.panels.Item.IMAGE,
itemHandler: Home.panels.ItemHandler.BROWSER
}],
// optional, defaults to FRAME (only supported layout for v1)
layout: Home.panels.Layout.FRAME,
};
}
exports.load = function(){
console.debug("Loading addon Home Panel");
try{
Home.panels.uninstall(PANEL_ID);
Home.panels.unregister(PANEL_ID);
}catch(e){
console.error("Ocurrio un error al desintalar el panel" + e);
//console.exception(e);
}
Home.panels.register(PANEL_ID, optionsCallback);
Home.panels.install(PANEL_ID);
syncData2();
//HomeProvider.requestSync(PANEL_ID, syncData2); // this doesn't work either
Home.panels.update(PANEL_ID);
}
exports.unload = function(){
console.debug("Unloading Addon Panel");
Home.panels.uninstall(PANEL_ID);
Home.panels.unregister(PANEL_ID);
}
加载addon时会调用导出的加载函数。
根据https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/Home.jsm/panels这是可行的。
但是,我无法使用两个面板,只有第一个会加载。
到目前为止,我还无法找到有关此特定任务的任何信息。提前谢谢。
firefox附带的“TOP SITES”可以满足我的需求。它显示一个网格,然后是一个选择列表。 Firefox for Android TOP SITES panel