从 Gnome 扩展中的另一个类(另一个文件)调用函数

问题描述 投票:0回答:1

我正在使用 GNOME Shell 43.9。

我的

extensions.js
看起来像:

const Me = ExtensionUtils.getCurrentExtension();
const windowFunctions = Me.imports.windowFunctions;
const markedWindowFunctions = Me.imports.markedWindowFunctions;

class Extension {

    enable() {
....
}

function init(meta) {
    log(`initializing ${meta.metadata.name}`);
    return new Extension();
}

我的

windowFunctions.js
看起来像:

var WindowFunctions = class WindowFunctions {

    _get_other_normal_windows_current_workspace_of_focused_window_wm_class = function () {
        let win = Display.get_focus_window();
        return this._get_normal_windows_current_workspace_given_wm_class(win.get_wm_class()).filter(w => win != w);
    }

....
}

我的

markedWindowFunctions.js
目前看起来像:

var markedWindowFunctions = class markedWindowFunctions {

    CloseOtherNotMarkedWindowsCurrentWorkspaceOfFocusedWindowWMClass() {
        // call _get_other_normal_windows_current_workspace_of_focused_window_wm_class from here
    }

}

如何从

_get_other_normal_windows_current_workspace_of_focused_window_wm_class
WindowFunctions
呼叫
CloseOtherNotMarkedWindowsCurrentWorkspaceOfFocusedWindowWMClass
markedWindowFunctions

gnome gnome-shell gnome-shell-extensions gnome-3
1个回答
0
投票

OP在这里。以下解决了我的问题。

const Me = imports.misc.extensionUtils.getCurrentExtension();
const { WindowFunctions } = Me.imports.windowFunctions;

var MarkedWindowFunctions = class MarkedWindowFunctions {
    constructor() {
        this.windowFunctionsInstance = new WindowFunctions();
    }
    CloseOtherNotMarkedWindowsCurrentWorkspaceOfFocusedWindowWMClass() {
        // call let wins = this.windowFunctionsInstance._get_other_normal_windows_current_workspace_of_focused_window_wm_class from here
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.