【发布时间】:2023-02-26 05:07:12
【问题描述】:
tl;博士
如何在 GNOME 扩展中创建一个空窗口?
语境
我正在开发一个扩展程序,它将在一个窗口中管理多个窗口。我想要实现的第一件事就是创建一个新的空窗口。
我试过的
我发现 an example 正是这样做的(但不是在扩展中),就像这样:
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);
所以我在我的扩展中尝试了以下内容:
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())
}
但是在测试时(在嵌套 shell 中),出现以下错误:
(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
【问题讨论】:
标签: javascript gnome-shell-extensions gjs