在Gjs中使用Shell对象

Ale*_*der 11 gnome-shell

我正在使用Gjs(Gnome JavaScript绑定)编写gtk +应用程序由于没有可用的文档,我正在阅读gnome-shell JavaScript的源代码.在我的应用程序中,我需要访问global.userdatadir.

我试图将Shell对象添加到我的脚本:

const Shell = imports.gi.Shell;
Run Code Online (Sandbox Code Playgroud)

然后运行它#gjs myscript.js 但是当我这样做时它会抛出一个错误说:

JS ERROR: !!!   Exception was: Error: Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found
    JS ERROR: !!!     lineNumber = '0'
    JS ERROR: !!!     fileName = '"gjs_throw"'
    JS ERROR: !!!     stack = '"("Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found")@gjs_throw:0
@manager.js:5
"'
    JS ERROR: !!!     message = '"Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found"'
Error: Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found
Run Code Online (Sandbox Code Playgroud)

我无法理解它的错误,它与Gnome-shell源文件完全一样.其它目的是利用细imports.gi.Gio,imports.gi.GLib,工程确定.

在Ubuntu 11.10 x64上工作

gfx*_*onk 7

你不能通过gjs运行gnome-shell扩展,它们必须由gnome-shell本身加载.对于开发,这通常意味着将它们放入~/.local/share/gnome-shell/extensions/YOUR-EXTENSION-ID并重新启动shell.