Hello GNOME Planet!
I was wondering if you could help me in finding documentation about making extensions in GNOME. Where I can find documentation of the API in Javascript?
I am asking because, after running this code, the lap freeze:
const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const WebKit = imports.gi.WebKit;
const Gtk = imports.gi.Gtk;
let text, button;
function _hideHello() {
Main.uiGroup.remove_actor(text);
text = null;
}
function _showHello() {
/*if (!text) {
text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" });
Main.uiGroup.add_actor(text);
}
text.opacity = 255;
let monitor = Main.layoutManager.primaryMonitor;
text.set_position(Math.floor(monitor.width / 2 - text.width / 2),
Math.floor(monitor.height / 2 - text.height / 2));
Tweener.addTween(text,
{ opacity: 0,
time: 2,
transition: 'easeOutQuad',
onComplete: _hideHello });*/
Gtk.init(null, null);
win = new Gtk.Window({title: 'Ola Ke ase'});
webview = new WebKit.WebView();
hbox = new Gtk.HBox();
webview.load_uri('http://www.google.com.pe');
hbox.add(webview);
win.add(hbox);
win.show_all();
Gtk.main();
}
function init() {
button = new St.Bin({ style_class: 'panel-button',
reactive: true,
can_focus: true,
x_fill: true,
y_fill: false,
track_hover: true });
let icon = new St.Icon({ icon_name: 'system-run-symbolic',
style_class: 'system-status-icon' });
button.set_child(icon);
button.connect('button-press-event', _showHello);
}
function enable() {
Main.panel._rightBox.insert_child_at_index(button, 0);
}
function disable() {
Main.panel._rightBox.remove_child(button);
}
Thanks in advanced,
Julita
Have you tried here?
https://live.gnome.org/GnomeShell/Extensions
Thanks your response, but what we need is a library in order to interact with a Web socket
Welcome to the confusing world of shell extensions!
The Shell API (other than the ST toolkit) is not officially documented, and much to the annoyance of everybody outside of gnome keeps changing (hence extensions requiring re-writes with every new version of the shell) – you are left to look at the source code. For other libraries, you can generate documentatioin from the gir file. See http://www.piware.de/2013/03/automatically-generating-documentation-from-gir-files/
WRT your particular example, init() is used for setting up persistent items, UI items should be allocated/connected in enable() and deallocated/disconnected in disable(), or from the extension class’s function called from those two places. I doubt whether connecting an object to a signal is at all safe inside init(). There some very useful guidelines on the following blog: http://blog.mecheye.net/2012/02/requirements-and-tips-for-getting-your-gnome-shell-extension-approved/
Secondly, I don’t think that you can call gtk.init()/gtk.main() in thiis way from within an extension. Somewhere is the depths of the shell code there is a section which enables extension writers to add their own preferences dialog (as a javascript function) running the result as a separate gtk window/thread – but getting that to work is a lot more complicated than just calling gtk.main(). Normally you would simply connect to the signals that you were interested in and recieve callbacks in your javascript code, in which case you don’t need either function call, since your extension is running on the main shell gtk event loop.
Hope this helps!
Well, Julita just take the extension.js generated by ‘gnome-shell-extension-tool -c’ command , comment some parts and add the webkit and gtk stuff.
So i think this tool is not up-to-date with new rules
Thats exactly whats she has done, and you are right gnome-shell-extension-tool is generating code which was banned with the arrival of gnome 3.4. (see the guidelines blog posted above).
There’s a bug report here, if anyone wants to file it.
There is a bigger problem here: you cannot use toplevel Gtk windows in a shell extension, because you are running inside the window manager. Basically, any Gtk widget is out of question in a shell extension, because the way windows are created and events are delivered by Gdk are incompatible with mutter. (The fact that menus work on windows is a result of multiple hacks in mutter core, that cannot be replicated in JS)
So now we have defined the problem, what is the solution?
Write the window and its widgets as a separate application and merely use the extension to launch it as an independent task?
/*if (!text) {
Have you removed this /* ?