Search code examples
gnome-shellgnome-shell-extensionsgjs

Call a function from another gnome extension


My question is simple, is that possible to call a function declared in another gnome extension from my own gnome extension ?


Solution

  • If using GNOME 3.36, you could use the ExtensionManager to lookup the extension.

    const Main = imports.ui.main;
    const ExtensionManager = Main.extensionManager;
    
    // Looking up the extension
    let someExtension = ExtensionManager.lookup('some@extension');
    
    // Importing a module
    const SomeModule = someExtension.imports.someModule;
    

    But as pointed out by ptomato, this is a pretty bad idea, and I would count on this blowing up at some point. If you want to access live classes loaded from their extension you're probably on your own or will have to ask the author directly.