mirror of
https://github.com/Ximi1970/systray-x.git
synced 2025-11-10 07:16:12 +01:00
Cleanup
This commit is contained in:
@@ -81,25 +81,6 @@ var folderChange = class extends ExtensionCommon.ExtensionAPI {
|
||||
};
|
||||
},
|
||||
}).api(),
|
||||
|
||||
// An event. Most of this is boilerplate you don't need to worry about, just copy it.
|
||||
onToolbarClick: new ExtensionCommon.EventManager({
|
||||
context,
|
||||
name: "folderChange.onToolbarClick",
|
||||
// In this function we add listeners for any events we want to listen to, and return a
|
||||
// function that removes those listeners. To have the event fire in your extension,
|
||||
// call fire.async.
|
||||
register(fire) {
|
||||
function callback(event, id, x, y) {
|
||||
return fire.async(id, x, y);
|
||||
}
|
||||
|
||||
windowListener.add(callback);
|
||||
return function () {
|
||||
windowListener.remove(callback);
|
||||
};
|
||||
},
|
||||
}).api(),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -430,61 +411,3 @@ var SysTrayX = {
|
||||
this.callback = undefined;
|
||||
},
|
||||
};
|
||||
|
||||
// This object is just what we're using to listen for toolbar clicks. The implementation isn't
|
||||
// what this example is about, but you might be interested as it's a common pattern. We count the
|
||||
// number of callbacks waiting for events so that we're only listening if we need to be.
|
||||
var windowListener = new (class extends ExtensionCommon.EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.callbackCount = 0;
|
||||
}
|
||||
|
||||
handleEvent(event) {
|
||||
let toolbar = event.target.closest("toolbar");
|
||||
windowListener.emit(
|
||||
"toolbar-clicked",
|
||||
toolbar.id,
|
||||
event.clientX,
|
||||
event.clientY
|
||||
);
|
||||
}
|
||||
|
||||
add(callback) {
|
||||
this.on("toolbar-clicked", callback);
|
||||
this.callbackCount++;
|
||||
|
||||
if (this.callbackCount == 1) {
|
||||
ExtensionSupport.registerWindowListener("changeFolderListener", {
|
||||
chromeURLs: [
|
||||
"chrome://messenger/content/messenger.xhtml",
|
||||
"chrome://messenger/content/messenger.xul",
|
||||
],
|
||||
onLoadWindow: function (window) {
|
||||
let toolbox = window.document.getElementById("mail-toolbox");
|
||||
toolbox.addEventListener("click", windowListener.handleEvent);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
remove(callback) {
|
||||
this.off("toolbar-clicked", callback);
|
||||
this.callbackCount--;
|
||||
|
||||
if (this.callbackCount == 0) {
|
||||
for (let window of ExtensionSupport.openWindows) {
|
||||
if (
|
||||
[
|
||||
"chrome://messenger/content/messenger.xhtml",
|
||||
"chrome://messenger/content/messenger.xul",
|
||||
].includes(window.location.href)
|
||||
) {
|
||||
let toolbox = window.document.getElementById("mail-toolbox");
|
||||
toolbox.removeEventListener("click", this.handleEvent);
|
||||
}
|
||||
}
|
||||
ExtensionSupport.unregisterWindowListener("changeFolderListener");
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user