Inside main.js
I create a Panel
.
ui.html
includes a js
source file and in it I listen for messages from Panel
.
I never see restoring
dumped the console, why is this function never called?
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
file includes this to listen for messages ..
addon.port.on("previousHistory", function(history, currentHistoricalEntry) {
console.log("restoring");
Namespace.restoreHistory(history, currentHistoricalEntry);
});
SimpleStorage.js
, is where I handle access to 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;
}
Moving this.port.emit('previousHistory', prefs);
into Panel.onShow()
worked ..
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);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.