gnome:extensions:vpn_indicator
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
gnome:extensions:vpn_indicator [2022/07/23 09:57] – 194.32.120.110 | gnome: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 | + | **metadata.json** is a mandatory |
- | * It contains basic information about the extension such as its UUID, name and description. | + | < |
- | + | ||
- | < | + | |
{ | { | ||
- | " | ||
" | " | ||
" | " | ||
" | " | ||
- | "1.00.1" | + | "3.32", |
+ | "3.34", | ||
+ | " | ||
+ | " | ||
+ | "40" | ||
], | ], | ||
" | " | ||
Line 33: | Line 34: | ||
</ | </ | ||
- | <WRAP info> | + | ---- |
- | **NOTE: | + | |
- | __Mandatory fields__ | + | ===== Create a extensions.js file ===== |
- | | + | **extensions.js** is the core file of the extension and contains |
- | | + | |
- | | + | |
- | * Each part must only container letters, numbers, period | + | |
- | * But this does work well using a UUID that does not contain | + | |
- | * **name**: | + | <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**: | + | const VpnIndicator = new Lang.Class({ |
- | | + | |
+ | Extends: PanelMenu.Button, | ||
- | * **shell-version**: The GNOME Shell versions | + | _init: function() { |
- | * An array of strings describing the GNOME Shell versions that an extension supports. | + | |
- | * It must include at least one entry or the extension will be uninstallable. | + | |
- | * For versions up to and including GNOME 3.38, this should have a major and minor component such as "3.38". | + | |
- | * Starting with GNOME 40, it should simply be the major version, such as " | + | |
- | <wrap em>GNOME Shell has a configuration setting, **disable-extension-version-validation**, | + | if (!this.buttonText) { |
+ | this.buttonText = new St.Label({ | ||
+ | text: _(" | ||
+ | y_align: Clutter.ActorAlign.CENTER | ||
+ | }); | ||
+ | } | ||
- | * Before GNOME 40 this was true by default | + | |
- | </ | + | this._refresh(); |
+ | }, | ||
- | * **url**: A URL for the extension, which could point to where the code can be found and issues can be reported. | + | _checkVPN: function() { |
+ | let [res, out, err, exit] = GLib.spawn_sync(null, | ||
- | * **version**: | + | // To prevent / |
- | * 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(" | ||
+ | | ||
+ | this.buttonText.set_text(" | ||
+ | } | ||
+ | } catch (e) { | ||
+ | // logError(e, ' | ||
+ | } | ||
- | __Other optional fields__ | + | return exit; |
+ | }, | ||
- | | + | |
- | "settings-schema": "org.gnome.shell.extensions.example", | + | var qres = this._checkVPN(); |
- | | + | // |
+ | |||
+ | // Calls the refresh function every 2 seconds. | ||
+ | this._timeout = Mainloop.timeout_add_seconds(2, Lang.bind(this, this._refresh)); | ||
+ | | ||
+ | |||
+ | _refreshUI: function(data) { | ||
+ | /* | ||
+ | var text; | ||
+ | |||
+ | if (data == 256) { | ||
+ | text = "VPN is down!"; | ||
+ | } else if (data == 0) { | ||
+ | text = "VPN is up!"; | ||
+ | } else { | ||
+ | text = " | ||
+ | } | ||
+ | |||
+ | // To prevent / | ||
+ | try { | ||
+ | if (this.buttonText) { | ||
+ | this.buttonText.set_text(text); | ||
+ | } | ||
+ | } catch (e) { | ||
+ | // | ||
+ | } | ||
+ | |||
+ | */ | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | |||
+ | let twMenu; | ||
+ | |||
+ | |||
+ | function init() { | ||
} | } | ||
- | **NOTE:** | + | function enable() { |
+ | twMenu = new VpnIndicator; | ||
+ | Main.panel.addToStatusArea(' | ||
+ | } | ||
+ | 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:// | http:// | ||
- | https:// |
gnome/extensions/vpn_indicator.1658570244.txt.gz · Last modified: 2022/07/23 09:57 by 194.32.120.110