Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ var VitalsMenuButton = GObject.registerClass({
this._addSettingChangedSignal('menu-centered', this._positionInPanelChanged.bind(this));
this._addSettingChangedSignal('icon-style', this._iconStyleChanged.bind(this));

let settings = [ 'use-higher-precision', 'alphabetize', 'hide-zeros', 'fixed-widths', 'hide-icons', 'unit', 'memory-measurement', 'include-public-ip', 'network-speed-format', 'storage-measurement', 'include-static-info', 'include-static-gpu-info' ];
let settings = [ 'use-higher-precision', 'alphabetize', 'hide-zeros',
'fixed-widths', 'hide-icons', 'unit',
'memory-measurement', 'include-public-ip', 'network-public-ip-interval',
'network-public-ip-show-flag', 'network-speed-format', 'storage-measurement',
'include-static-info', 'include-static-gpu-info' ];
for (let setting of Object.values(settings))
this._addSettingChangedSignal(setting, this._redrawMenu.bind(this));

Expand Down Expand Up @@ -276,7 +280,10 @@ var VitalsMenuButton = GObject.registerClass({
this._hotItems[key] = item;
this._menuLayout.add_child(item);

if (!this._settings.get_boolean('hide-icons') || key == '_default_icon_') {
let isPublicIP = key.includes('public_ip');
let shouldHideIcon = isPublicIP && this._settings.get_boolean('network-public-ip-show-flag');

if ((!this._settings.get_boolean('hide-icons') || key == '_default_icon_') && !shouldHideIcon) {
let icon = this._defaultIcon(key);
if (gicon) icon.gicon = gicon;
item.add_child(icon);
Expand Down
7 changes: 5 additions & 2 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const Settings = new GObject.Class({
'show-memory', 'show-processor', 'show-system',
'show-network', 'show-storage', 'use-higher-precision',
'alphabetize', 'hide-zeros', 'include-public-ip',
'show-battery', 'fixed-widths', 'hide-icons',
'menu-centered', 'include-static-info',
'network-public-ip-show-flag', 'show-battery', 'fixed-widths',
'hide-icons', 'menu-centered', 'include-static-info',
'show-gpu', 'include-static-gpu-info' ];

for (let key in sensors) {
Expand All @@ -75,6 +75,9 @@ const Settings = new GObject.Class({

this._settings.bind('update-time', this.builder.get_object('update-time'), 'value', Gio.SettingsBindFlags.DEFAULT);

this._settings.bind('network-public-ip-interval', this.builder.get_object('network-public-ip-interval'),
'value', Gio.SettingsBindFlags.DEFAULT);

// process individual text entry sensor preferences
sensors = [ 'storage-path', 'monitor-cmd' ];
for (let key in sensors) {
Expand Down
68 changes: 65 additions & 3 deletions prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
<property name="page_increment">10</property>
</object>
<object class="GtkBox" id="network_prefs">
<property name="can_focus">0</property>
<property name="can_focus">1</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="margin_start">6</property>
<property name="margin_end">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame">
<property name="can_focus">0</property>
<property name="can_focus">1</property>
<property name="child">
<object class="GtkListBox">
<property name="can_focus">0</property>
<property name="can_focus">1</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow">
Expand Down Expand Up @@ -52,6 +52,68 @@
</property>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="selectable">1</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">12</property>
<property name="margin_top">6</property>
<child>
<object class="GtkLabel">
<property name="hexpand">1</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Update in minutes</property>
</object>
</child>
<child>
<object class="GtkSpinButton" id="network-public-ip-interval">
<!-- <property name="can_focus">True</property> -->
<property name="editable">1</property>
<property name="numeric">1</property>
<property name="update_policy">if-valid</property>
<property name="adjustment">
<object class="GtkAdjustment">
<property name="lower">1</property>
<property name="upper">1440</property>
<property name="step_increment">1</property>
</object>
</property>
</object>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Show country flag</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="network-public-ip-show-flag">
<property name="visible">True</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="width_request">100</property>
Expand Down
8 changes: 8 additions & 0 deletions schemas/org.gnome.shell.extensions.vitals.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
<summary>Include public IP address</summary>
<description>Display public IP address of internet connection</description>
</key>
<key type="i" name="network-public-ip-interval">
<default>60</default>
<summary>Public IP refresh interval in minutes</summary>
</key>
<key name="network-public-ip-show-flag" type="b">
<default>true</default>
<summary>Show country flag for public IP</summary>
</key>
<key type="i" name="network-speed-format">
<default>0</default>
<summary>Network speed format</summary>
Expand Down
38 changes: 30 additions & 8 deletions sensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ import * as FileModule from './helpers/file.js';
import { gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';
import NM from 'gi://NM';


function getFlagEmoji(countryCode) {
if (!countryCode || countryCode.length !== 2) return '🌐';
try {
return countryCode
.toUpperCase()
.replace(/./g, char => String.fromCodePoint(char.charCodeAt(0) + 127397));
} catch (e) {
return '🌐';
}
}

let GTop, hasGTop = true;
try {
({default: GTop} = await import('gi://GTop'));
Expand All @@ -53,6 +65,7 @@ export const Sensors = GObject.registerClass({
this._settingChangedSignals = [];
this._addSettingChangedSignal('show-gpu', this._reconfigureNvidiaSmiProcess.bind(this));
this._addSettingChangedSignal('update-time', this._reconfigureNvidiaSmiProcess.bind(this));
this._addSettingChangedSignal('network-public-ip-interval', () => {this._lastPublicIPCheck = 0;});
//this._addSettingChangedSignal('include-static-gpu-info', this._reconfigureNvidiaSmiProcess.bind(this));

this._gpu_drm_vendors = null;
Expand Down Expand Up @@ -82,14 +95,22 @@ export const Sensors = GObject.registerClass({
}

_refreshIPAddress(callback) {
// check IP address
new FileModule.File('https://ipv4.corecoding.com').read().then(contents => {
let obj = JSON.parse(contents);
let cc = (obj && typeof obj['countryCode'] === 'string') ? obj['countryCode'].trim().toLowerCase() : '';
let ip = (obj && typeof obj['IPv4'] === 'string') ? obj['IPv4'].trim() : '';
let typeOut = (/^[a-z]{2}$/.test(cc)) ? ('network-' + cc) : 'network';
this._returnValue(callback, 'Public IP', ip, typeOut, 'string');
}).catch(err => { });
try {
let obj = JSON.parse(contents);
if (!obj.IPv4) throw new Error("No IP");

let flag = getFlagEmoji(obj.countryCode);
let display = this._settings.get_boolean('network-public-ip-show-flag')
? `${flag} ${obj.IPv4}`
: obj.IPv4;
this._returnValue(callback, 'Public IP', display, 'network', 'string');
} catch (e) {
this._returnValue(callback, 'Public IP', '🏳️ Parse Error', 'network', 'string');
}
}).catch(err => {
this._returnValue(callback, 'Public IP', '📡 Offline', 'network', 'string');
});
}

_findStorageDevice() {
Expand Down Expand Up @@ -312,7 +333,8 @@ export const Sensors = GObject.registerClass({
if (this._settings.get_boolean('include-public-ip')) {
// check the public ip every hour or when waking from sleep
if (this._next_public_ip_check <= 0) {
this._next_public_ip_check = 3600;
let intervalMinutes = this._settings.get_int('network-public-ip-interval');
this._next_public_ip_check = intervalMinutes * 60;

this._refreshIPAddress(callback);
}
Expand Down