0

对于raise-activated GNOME Shell 3.16 扩展,我正在尝试对该AppSwitcherPopup._finish方法进行猴子补丁。与原始版本一样,修补版本调用this.parent

function _modifiedFinish(timestamp) {
    // ...monkey-patched code...
    this.parent(timestamp);
}

function enable() {
    _originalFinish = AltTab.AppSwitcherPopup.prototype._finish;
    AltTab.AppSwitcherPopup.prototype._finish = _modifiedFinish;
}

完整代码

但是我在控制台中得到了这个堆栈跟踪(来自运行gnome-shell --replace):

(gnome-shell:24452): Gjs-WARNING **: JS ERROR: TypeError: The method '_keyReleaseEvent' is not on the superclass
_parent@resource:///org/gnome/gjs/modules/lang.js:129
_modifiedFinish@/home/lastorset/.local/share/gnome-shell/extensions/Alt_Tab_Mod_Only_Raise_Activated_Window@dsboger.com.br/extension.js:34
SwitcherPopup<._keyReleaseEvent@resource:///org/gnome/shell/ui/switcherPopup.js:199
wrapper@resource:///org/gnome/gjs/modules/lang.js:169

在这种情况下,SwitcherPopup._keyReleaseEvent正在调用this,并且this 应该是子类的一个实例AppSwitcherPopup。我相信this.parent在打补丁后应该是一样的——为什么它现在试图打电话给调用者?就此而言,为什么不成功?

我查找了生成的GJS 代码this.parent,但我无法完全发现缺少的内容。

4

1 回答 1

0

在挖掘了更多之后,我找到了解决它的方法。在 GJS 类模型中,parent函数实际上是在寻找方法所有者的超类,以便调用同名方法。看起来每个 GJS 类都有一个wrapFunction帮助器来设置_owner. 我用它来修补函数:

AltTab.AppSwitcherPopup.prototype._finish = AltTab.AppSwitcherPopup.wrapFunction('_finish', _modifiedFinish);
于 2015-12-06T21:27:14.123 回答