簡體   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