tl;dr
How do I create an empty window in a GNOME extension?
Context
I'm working on an extension that will manage several windows within one. One of the first things I'm trying to achieve is to create a new empty window.
What I've Tried
I've found an example that does exactly that (but not in an extension) like so:
import Gtk from "gi://Gtk?version=4.0";
import Adw from "gi://Adw?version=1";
import system from "system";
const application = new Adw.Application({
application_id: "com.example.Application",
});
application.connect("activate", () => {
// create a Gtk Window belonging to the application itself
const window = new Gtk.ApplicationWindow({
application,
title: "Welcome to GNOME",
});
window.present();
});
/*
* Run the application, exit with the value returned by
* running the program
*/
const exit_code = application.run([system.programInvocationName, ...ARGV]);
system.exit(exit_code);
So I tried the following in my extension:
const Gtk = imports.gi.Gtk;
const Adw = imports.gi.Adw;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const globals = {
_version: "v4"
}
function enable() {
log(`enabling ${Me.metadata.name} ${globals._version}`);
const application = new Adw.Application({
application_id: "com.example.Application"
})
let testWindow = Gtk.ApplicationWindow.new(application)
testWindow.present_with_time(Date.now())
}
But when testing (in a nested shell), I'm getting the following error:
(gnome-shell:234231): Gjs-WARNING **: 12:51:46.718: JS ERROR: Extension helloworld@klino.me: Error: Requiring Adw, version none: Requiring namespace 'Gtk' version '4.0', but '3.0' is already loaded