User Tools

Site Tools


gnome:extensions:vpn_indicator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gnome:extensions:vpn_indicator [2022/07/23 09:57] 194.32.120.110gnome:extensions:vpn_indicator [2022/07/23 11:25] (current) 194.32.120.99
Line 15: Line 15:
 ===== Create a metadata.json file ===== ===== Create a metadata.json file =====
  
-**metadata.json** is a required file of every extension.+**metadata.json** is a mandatory file of the extension, containing information about the extension such as its UUID, name and description.
  
-  * It contains basic information about the extension such as its UUID, name and description. +<file json metadata.json>
- +
-<file bash metadata.json>+
 { {
-  "_author": "Peter Terence Roux, 2016", 
   "description": "A VPN connection indicator.",   "description": "A VPN connection indicator.",
   "name": "VPN Indicator",   "name": "VPN Indicator",
   "shell-version": [   "shell-version": [
-    "1.00.1"+    "3.32", 
 +    "3.34", 
 +    "3.36", 
 +    "3.38", 
 +    "40"
   ],   ],
   "url": "",   "url": "",
Line 33: Line 34:
 </file> </file>
  
-<WRAP info> +----
-**NOTE:**  Some fields are mandatory, but there are a number of other optional fields too:+
  
-__Mandatory fields__+===== Create a extensions.js file =====
  
-  * **uuid**: This is the name of the directory where the extension is going to be installed. +**extensions.js** is the core file of the extension and contains the function hooks **init()****enable()** and **disable()** used by GNOME Shell to loadenable and disable the extension.
-    In this case **~/.local/share/gnome-shell/extensions/vpn-indicator**+
-    Officially the name should be a globally-unique identifier for your extension, made of two parts separated by **@**+
-      * Each part must only container letters, numbers, period (.), underscore (_) and hyphen (-). +
-      * But this does work well using a UUID that does not contain the second part with **@**.+
  
-  * **name**:  A short, descriptive string.+<file javascript extensions.js> 
 +const St = imports.gi.St; 
 +const Main = imports.ui.main; 
 +const Lang = imports.lang; 
 +const Util = imports.misc.util; 
 +const PanelMenu = imports.ui.panelMenu; 
 +const Mainloop = imports.mainloop; 
 +const GLib = imports.gi.GLib; 
 +const Clutter = imports.gi.Clutter;
  
-  * **description**:  A relatively short description of the extension+const VpnIndicator = new Lang.Class({ 
-    * Line breaks and tabs can be used with **\n** and **\t** escape sequences.+    Name: 'VpnIndicator', 
 +    Extends: PanelMenu.Button,
  
-  * **shell-version** The GNOME Shell versions this supports. +    _initfunction() { 
-    * An array of strings describing the GNOME Shell versions that an extension supports. +        this.parent(0.0, "VPN Indicator", false);
-    * It must include at least one entry or the extension will be uninstallable. +
-    * For versions up to and including GNOME 3.38this should have a major and minor component such as "3.38"+
-      * Starting with GNOME 40it should simply be the major version, such as "40" or "41".+
  
-<wrap em>GNOME Shell has a configuration setting**disable-extension-version-validation**, which controls whether unsupported extensions can be loaded.+        if (!this.buttonText) { 
 +          this.buttonText = new St.Label({ 
 +              text: _("Loading..."), 
 +              y_align: Clutter.ActorAlign.CENTER 
 +          }); 
 +        }
  
-  * Before GNOME 40 this was true by default (users could install extensions regardless of the shell-version), but because of the major changes it is now false by default+        this.actor.add_actor(this.buttonText)
-</wrap>+        this._refresh(); 
 +    },
  
-  * **url** A URL for the extensionwhich could point to where the code can be found and issues can be reported.+    _checkVPNfunction() { 
 +        let [resout, err, exit] = GLib.spawn_sync(null, ["/bin/bash", "-c","ip addr | grep tun0"], null, GLib.SpawnFlags.SEARCH_PATH, null);
  
-  * **version**:  The version of the extension, as known to the GNOME Extensions website, and MUST be a whole number like 1+        // To prevent /var/log/syslog filling with error messages once the object is destroyed
-    * It is not a semantic version like 1.1 or a string like "1". +        try { 
-    * This version is automatically incremented by the GNOME Extensions website with each submission.+            if (this.buttonText) { 
 +              if (exit == 256) 
 +                this.buttonText.set_text("VPN off"); 
 +              else if (exit == 0) 
 +                this.buttonText.set_text("VPN on"); 
 +              else 
 +                this.buttonText.set_text("VPN Error"); 
 +            } 
 +        } catch (e) { 
 +          //    logError(e, 'ExtensionError'); 
 +        }
  
-__Other optional fields__+        return exit; 
 +    },
  
-    "session-modes"["user""unlock-dialog"]+    _refreshfunction() { 
-    "settings-schema""org.gnome.shell.extensions.example", +        var qres = this._checkVPN(); 
-    "gettext-domain": "example@gjs.guide",+        //this._refreshUI(qres); 
 +         
 +        // Calls the refresh function every 2 seconds. 
 +        this._timeout = Mainloop.timeout_add_seconds(2Lang.bind(thisthis._refresh)); 
 +    }, 
 + 
 +    _refreshUI: function(data) { 
 +/*       
 +        var text; 
 + 
 +        if (data == 256) { 
 +            text = "VPN is down!"
 +        } else if (data == 0) { 
 +            text = "VPN is up!"; 
 +        } else { 
 +            text = "Error!"; 
 +        } 
 + 
 +        // To prevent /var/log/syslog filling with error messages once the object is destroyed. 
 +        try { 
 +            if (this.buttonText) { 
 +                this.buttonText.set_text(text); 
 +            } 
 +        } catch (e) { 
 +          //    logError(e'ExtensionError'); 
 +        } 
 +                 
 +*/ 
 +    } 
 +}); 
 + 
 + 
 +let twMenu; 
 + 
 + 
 +function init() {
 } }
  
-**NOTE:**+function enable() { 
 +    twMenu = new VpnIndicator; 
 +    Main.panel.addToStatusArea('vpn-indicator', twMenu); 
 +}
  
 +function disable() {
 +    if (this._timeout)
 +      Mainloop.source_remove(this._timeout);
  
-</WRAP>+    this._timeout = undefined; 
 + 
 +    if (this.buttonText !== null) { 
 +        this.buttonText.destroy(); 
 +        this.buttonText = null; 
 +    } 
 + 
 +    twMenu.destroy(); 
 +
 +</file> 
 + 
 +----
  
 +===== Reload GNOME to pick up the extension =====
  
 +Press **Alt+F2**, and enter **r** and press **ENTER** to restart GNOME Shell.
  
 ---- ----
Line 88: Line 162:
 http://smasue.github.io/gnome-shell-tw http://smasue.github.io/gnome-shell-tw
  
-https://gjs.guide/extensions/overview/anatomy.html#metadata-json-required 
gnome/extensions/vpn_indicator.1658570244.txt.gz · Last modified: 2022/07/23 09:57 by 194.32.120.110

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki