/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */

const Main = imports.ui.main;
const Panel = imports.ui.panel;
const PopupMenu = imports.ui.popupMenu;
const Indicator = imports.ui.status.ibus.indicator;

let indicator = null;
let menus = null;

function init() {
}

function main() {
    // The gettext is fixed in gnome-shell 3.1.4 or later at least.
    if (window._ == undefined) {
        const Shell = imports.gi.Shell;
        const Gettext = imports.gettext;
        window.global = Shell.Global.get();
        window._ = Gettext.gettext;
        window.C_ = Gettext.pgettext;
        window.ngettext = Gettext.ngettext;
    }
    Panel.STANDARD_TRAY_ICON_ORDER.push('ibus');
    Panel.STANDARD_TRAY_ICON_SHELL_IMPLEMENTATION['ibus'] = Indicator.Indicator;
}

function enable() {
    if (!indicator) {
        indicator = new Indicator.Indicator();
    }
    if (!menus) {
        menus = new PopupMenu.PopupMenuManager(indicator);
    }
    menus.addMenu(indicator.menu);
    Main.statusIconDispatcher.emit('status-icon-added', indicator.actor, 'ibus');
}

function disable() {
    if (indicator) {
        if (menus) {
            menus.removeMenu(indicator.menu);
            menus = null;
        }
        Main.statusIconDispatcher.emit('status-icon-removed', indicator.actor);
        indicator = null;
    }
}

@@ -96,80 +96,8 @@
 in;%0A
-const Panel = imports.ui.panel;%0Aconst PopupMenu = imports.ui.popupMenu;%0A
 cons
@@ -170,26 +170,8 @@
 ull;
-%0Alet menus = null;
 %0A%0Afu
@@ -193,509 +193,8 @@
 %0A%7D%0A%0A
-function main() %7B%0A    // The gettext is fixed in gnome-shell 3.1.4 or later at least.%0A    if (window._ == undefined) %7B%0A        const Shell = imports.gi.Shell;%0A        const Gettext = imports.gettext;%0A        window.global = Shell.Global.get();%0A        window._ = Gettext.gettext;%0A        window.C_ = Gettext.pgettext;%0A        window.ngettext = Gettext.ngettext;%0A    %7D%0A    Panel.STANDARD_TRAY_ICON_ORDER.push('ibus');%0A    Panel.STANDARD_TRAY_ICON_SHELL_IMPLEMENTATION%5B'ibus'%5D = Indicator.Indicator;%0A%7D%0A%0A
 func
@@ -286,435 +286,139 @@
     
-%7D%0A
     
-if (!menus) %7B%0A        menus = new PopupMenu.PopupMenuManager(indicator);%0A    %7D%0A    menus.addMenu(indicator.menu);%0A    Main.statusIconDispatcher.emit('status-icon-added', indicator.actor, 'ibus');%0A%7D%0A%0Afunction disable() %7B%0A    if (indicator) %7B%0A        if (menus) %7B%0A            menus.removeMenu(indicator.menu);%0A            menus = null;%0A        %7D%0A        Main.statusIconDispatcher.emit('status-icon-removed', indicator.actor
+Main.panel.addToStatusArea('ibus', indicator, 0);%0A    %7D%0A%7D%0A%0Afunction disable() %7B%0A    if (indicator) %7B%0A        indicator.destroy(
 );%0A 

Make use of standard API addToStatusArea