2012-12-10 24 views
1

我正在爲gnome-shell寫入擴展名。 但是在gnome-shell 3.4中,菜單被添加了panel._menus,並且在gnome-shell3.6中被添加了panel.menuManager。我如何添加適用於每個版本的菜單?爲gnome-shell寫入擴展名3.4和3.6

回答

1

有幾種方法可以做到這一點。

你可以檢查的panel._menus存在和使用,如果它存在,否則使用panel.menuManager

let menuManager = panel._menus || panel.menuManager 
// now do everything with menuManager 

或者你可以明確檢查的gnome-shell版:

const ShellVersion = imports.misc.config.PACKAGE_VERSION.split(".").map(
    function (x) { return +x; }) // <-- converts from string to number 
// this is now an array, e.g. if I am on gnome-shell 3.6.2 it is [3, 6, 2]. 

if (ShellVersion[1] === 4) { 
    // GNOME 3.4, use panel._menus 
} else if (ShellVersion[1] === 6) { 
    // GNOME 3.6, use panel.menuManager 
}