Ahmad Ismail
Ahmad Ismail

Reputation: 13942

Call a Function from Another Class (another file) in Gnome Extension

I am using GNOME Shell 43.9.

my extensions.js looks like:

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();
}

my windowFunctions.js looks like:

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);
    }

....
}

My markedWindowFunctions.js currently looks like:

var markedWindowFunctions = class markedWindowFunctions {

    CloseOtherNotMarkedWindowsCurrentWorkspaceOfFocusedWindowWMClass() {
        // call _get_other_normal_windows_current_workspace_of_focused_window_wm_class from here
    }

}

How to call _get_other_normal_windows_current_workspace_of_focused_window_wm_class of WindowFunctions from CloseOtherNotMarkedWindowsCurrentWorkspaceOfFocusedWindowWMClass of markedWindowFunctions.

Upvotes: 0

Views: 28

Answers (1)

Ahmad Ismail
Ahmad Ismail

Reputation: 13942

OP Here. The following solved my problem.

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
    }

}

The documentation was found here. For latest version of gnome shell, please check here.

Upvotes: 0

Related Questions