// Stolen some code from:
// https://github.com/mathematicalcoffee/EvilStatusIconForever/blob/22a2d0c6da79943f8bb49a7fc7006e20523356e5/extension.js
// By: Hedayat Vatankhah <hedayat.fwd@gmail.com>, 2011
const Shell = imports.gi.Shell;
const PanelMenu = imports.ui.panelMenu;
const Panel = imports.ui.panel;
const Main = imports.ui.main;
const STANDARD_TRAY_ICON_IMPLEMENTATIONS = imports.ui.notificationDaemon.STANDARD_TRAY_ICON_IMPLEMENTATIONS;
let trayManager, addedID;
let statusArea;
/** Callback when a tray icon is added to the tray manager.
* We make a panel button for the top panel for it. */
function _onTrayIconAdded(o, icon) {
let wmClass = icon.wm_class ? icon.wm_class.toLowerCase() : '';
if (wmClass != "starcal2.py")
return;
icon.height = Panel.PANEL_ICON_SIZE;
let buttonBox = new PanelMenu.Button();
let box = buttonBox.actor;
box.add_actor(icon);
Main.panel._addToPanelBox(wmClass, buttonBox, 0, Main.panel._rightBox);
}
// STANDARD_TRAY_ICON_IMPLEMENTATIONS is necessary for 3.6
// to stop the message tray also making an icon for it.
function removeFromTopBar(wmClass)
{
delete STANDARD_TRAY_ICON_IMPLEMENTATIONS[wmClass];
if (statusArea[wmClass]) {
statusArea[wmClass].destroy();
}
}
function addToTopBar(wmClass)
{
STANDARD_TRAY_ICON_IMPLEMENTATIONS[wmClass] = wmClass;
}
function init() {
}
function enable() {
statusArea = Main.panel.statusArea;
trayManager = Main.notificationDaemon._trayManager;
addedID = trayManager.connect('tray-icon-added', _onTrayIconAdded);
addToTopBar("starcal2.py");
}
function disable() {
trayManager.disconnect(addedID);
addedID = 0;
removeFromTopBar("starcal2.py");
}