1

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

taharqa
  • 1,112
  • 1
  • 13
  • 19

2 Answers2

2

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.)

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • My question should have been, can you show me how to handle it if possible ? ANd then, yes you're right, I should not do this. But this is for a private extension I'll use it for my own usage. Thx – taharqa May 20 '20 at 09:44
2

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.

andy.holmes
  • 3,383
  • 17
  • 28
  • 1
    Thank you @andy.holmes. At some point when gnome version is increasing everything is blowing up anyway ;) – taharqa May 21 '20 at 19:36
  • Well, to be clear, this will only let you create classes or call functions defined in the extension's modules. Accessing the classes created *by* an extension or calling methods on them is another matter. – andy.holmes May 22 '20 at 23:00