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 10:41] – 194.32.120.98 | 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. | + | < |
- | + | ||
- | < | + | |
{ | { | ||
- | " | ||
" | " | ||
" | " | ||
" | " | ||
- | " | + | |
+ | " | ||
+ | | ||
+ | " | ||
+ | "40" | ||
], | ], | ||
" | " | ||
Line 32: | Line 33: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Create a extensions.js file ===== | ||
+ | |||
+ | **extensions.js** is the core file of the extension and contains the function hooks **init()**, **enable()** and **disable()** used by GNOME Shell to load, enable and disable the extension. | ||
+ | |||
+ | <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; | ||
+ | |||
+ | const VpnIndicator = new Lang.Class({ | ||
+ | Name: ' | ||
+ | Extends: PanelMenu.Button, | ||
+ | |||
+ | _init: function() { | ||
+ | this.parent(0.0, | ||
+ | |||
+ | if (!this.buttonText) { | ||
+ | this.buttonText = new St.Label({ | ||
+ | text: _(" | ||
+ | y_align: Clutter.ActorAlign.CENTER | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | this.actor.add_actor(this.buttonText); | ||
+ | this._refresh(); | ||
+ | }, | ||
+ | |||
+ | _checkVPN: function() { | ||
+ | let [res, out, err, exit] = GLib.spawn_sync(null, | ||
+ | |||
+ | // To prevent / | ||
+ | try { | ||
+ | if (this.buttonText) { | ||
+ | if (exit == 256) | ||
+ | this.buttonText.set_text(" | ||
+ | else if (exit == 0) | ||
+ | this.buttonText.set_text(" | ||
+ | else | ||
+ | this.buttonText.set_text(" | ||
+ | } | ||
+ | } catch (e) { | ||
+ | // logError(e, ' | ||
+ | } | ||
+ | |||
+ | return exit; | ||
+ | }, | ||
+ | |||
+ | _refresh: function() { | ||
+ | var qres = this._checkVPN(); | ||
+ | // | ||
+ | | ||
+ | // Calls the refresh function every 2 seconds. | ||
+ | this._timeout = Mainloop.timeout_add_seconds(2, | ||
+ | }, | ||
+ | |||
+ | _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) { | ||
+ | // logError(e, ' | ||
+ | } | ||
+ | | ||
+ | */ | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | |||
+ | let twMenu; | ||
+ | |||
+ | |||
+ | function init() { | ||
+ | } | ||
+ | |||
+ | function enable() { | ||
+ | twMenu = new VpnIndicator; | ||
+ | Main.panel.addToStatusArea(' | ||
+ | } | ||
+ | |||
+ | function disable() { | ||
+ | if (this._timeout) | ||
+ | Mainloop.source_remove(this._timeout); | ||
+ | |||
+ | this._timeout = undefined; | ||
+ | |||
+ | if (this.buttonText !== null) { | ||
+ | this.buttonText.destroy(); | ||
+ | this.buttonText = null; | ||
+ | } | ||
+ | |||
+ | twMenu.destroy(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Reload GNOME to pick up the extension ===== | ||
+ | |||
+ | Press **Alt+F2**, and enter **r** and press **ENTER** to restart GNOME Shell. | ||
---- | ---- |
gnome/extensions/vpn_indicator.1658572881.txt.gz · Last modified: 2022/07/23 10:41 by 194.32.120.98