Re: Monkey patching the network applet
- From: "Jasper St. Pierre" <jstpierre mecheye net>
- To: Herczeg Zsolt <zsolt94 gmail com>
- Cc: gnome-shell-list gnome org
- Subject: Re: Monkey patching the network applet
- Date: Sun, 21 Oct 2012 13:31:50 -0400
On Sun, Oct 21, 2012 at 12:59 PM, Herczeg Zsolt <zsolt94 gmail com> wrote:
> HI!
>
> Can you help me please making an extension?
>
> I would like to make an extension with the same result as adding this after
> 1602 line to the
> /usr/share/gnome-shell/js/ui/status/network.js
> this.menu.addSettingsAction("Old network managger",
> 'nm-connection-editor.desktop');
>
> If I put this directly to the file, it's perfectly works. (Adds a new
> settings entry, which launches the old-style network managger window)
>
> I wanted to make an extensions, to do this without touching the network.js,
> but I can't get it work:
>
> const network = imports.ui.status.network;
>
> let network_init = null;
>
> function init() {
> network_init = network.NMApplet.prototype['_init'];
> global.log('OLDNETWORK: Original func:');
> global.log(network_init);
> //global.log('OLDNETWORK: Menu add function:');
> //global.log(network.NMApplet.menu); //This is undefined
> }
>
> function enable() {
> global.log('Bekapcsolva');
> network.NMApplet.prototype['_init'] = function() {
> global.log('OLDNETWORK: Successful change!!');
> let ret = network_init();
> this.menu.addSettingsAction("Old network managger",
> 'nm-connection-editor.desktop');
> return ret;
> }
> }
>
> function disable() {
> network.NMApplet.prototype['_init'] = network_init;
> }
>
> Actually as the output of global.log(network_init); i don't receive the
> source code found in network.js, it's just some wrapper, and the
> global.log('OLDNETWORK: Successful change!!'); never runs. (So it never adds
> the menu item.)
> I also tried to add the menu item from the extension, but the
> network.NMApplet.menu is undefined, so I can't run it.
>
>
> I'm new to developing gnome-shell extensions, but I would like to learn
> making and publishing them. Can you help me where to look for the solution?
By the time your extension has been initialized, the network menu has
already been constructed. You need to add/remove the menu at runtime:
let item = null;
function enable() {
item = Main.panel.statusArea.network.menu.addSettingsAction("Old
network managger", 'nm-connection-editor.desktop');
}
function disable() {
item.destroy();
item = null;
}
> Thanks:
> Herczeg Zsolt
>
> _______________________________________________
> gnome-shell-list mailing list
> gnome-shell-list gnome org
> https://mail.gnome.org/mailman/listinfo/gnome-shell-list
>
--
Jasper
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]