I am writing the preference view a GNOME shell extension and an facing issues when using the imports.lang
function to write the application in an object oriented fashion.
const Gtk = imports.gi.Gtk
const Lang = imports.lang
Gtk.init(null)
const MyWindow = new Lang.Class({...})
Opening the preference window the first time works, but subsequent ones throw the following error: Error: Type name Gjs_MyWindow is already registered
. Upon closing the window for the first time, I receive this error: TypeError: prefsModule.init is not a function
.
The following more imperative code works:
const Gtk = imports.gi.Gtk
Gtk.init(null)
const window = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL })
Based on the errors thrown, my guess is that the class is being redefined. How can I avoid redefinition and receive the defined class otherwise? (Are there any docs I can refer to?)