繁体   English   中英

addon.port.on无法接收来自插件的消息

[英]addon.port.on not recieving message from addon

main.js内部,我创建了一个Panel
ui.html包含一个js源文件,并且在其中侦听来自Panel消息。
我从没见过restoring到控制台,为什么从未调用此函数?

panel = PanelAPI.Panel({
        width: 300,
        height: 400,
        contentURL: Data.get("html/ui.html")
    });

    panel.port.emit('previousHistory', SimpleStorage.getHistory(), SimpleStorage.getCurrentHistoricalEntry());

    panel.port.on("historyUpdate", function (history, currentHistoricalEntry) {
        SimpleStorage.setHistory(history);
        SimpleStorage.setCurrentHistoricalEntry(currentHistoricalEntry);
    });

contentURL: Data.get("html/ui.html")js文件包括此内容以侦听消息。

addon.port.on("previousHistory", function(history, currentHistoricalEntry) {
    console.log("restoring");
    Namespace.restoreHistory(history, currentHistoricalEntry);
});

SimpleStorage.js是我处理对simple-storage api的访问的地方。

var ss = require("sdk/simple-storage");

exports.getHistory = function(){
    console.log("retrieving ss: " + ss.storage.history)
    return ss.storage.history;
}

exports.setHistory = function(history){
    ss.storage.history = history;
    console.log("history in ss is now: " + ss.storage.history)
}

exports.setCurrentHistoricalEntry = function(currentHistoricalEntry){
    ss.storage.currentHistoricalEntry = currentHistoricalEntry;
    console.log("currhisent is now" + ss.storage.currentHistoricalEntry);
}

exports.getCurrentHistoricalEntry = function(){
    console.log("retrieving ss.currentr: " + ss.storage.currentHistoricalEntry);
    return ss.storage.currentHistoricalEntry;
}

移动this.port.emit('previousHistory', prefs); 进入Panel.onShow()工作..

panel = PanelAPI.Panel({
        width: 300,
        height: 400,
        contentURL: Data.get("html/ui.html"),
        onShow: function() { 

            var prefs = JSON.stringify({
                history: SimpleStorage.getHistory(),
                currentHistoricalEntry: SimpleStorage.getCurrentHistoricalEntry()
            });

            this.port.emit('previousHistory', prefs);
        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM