taharqa
taharqa

Reputation: 1132

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 ?

Upvotes: 1

Views: 295

Answers (2)

andy.holmes
andy.holmes

Reputation: 3696

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.

Upvotes: 2

ptomato
ptomato

Reputation: 57920

Yes. You just have to make sure the other GNOME Shell extension stashes the function somewhere that your extension can find it, like on the global object.

(But, please don't do this anyway. It's unpredictable whether someone will have a particular extension installed, and there's a reason that there isn't a dependency system for extensions.)

Upvotes: 2

Related Questions