Skip to content

Commit ce92c64

Browse files
authored
Merge pull request #563 from corecoding/develop
Develop
2 parents 04ce1c1 + bfb700e commit ce92c64

8 files changed

Lines changed: 128 additions & 11 deletions

File tree

extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ var VitalsMenuButton = GObject.registerClass({
334334
let settings = [ 'use-higher-precision', 'alphabetize', 'hide-zeros',
335335
'fixed-widths', 'hide-icons', 'unit',
336336
'memory-measurement', 'include-public-ip', 'network-public-ip-interval',
337-
'network-public-ip-show-flag', 'network-speed-format', 'storage-measurement',
337+
'network-public-ip-show-flag', 'network-public-ip-provider', 'network-speed-format', 'network-speed-unit', 'storage-measurement',
338338
'include-static-info', 'include-static-gpu-info' ];
339339

340340
for (let setting of Object.values(settings))

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"url": "https://github.com/corecoding/Vitals",
1010
"uuid": "Vitals@CoreCoding.com",
11-
"version": 77,
11+
"version": 78,
1212
"donations": {
1313
"paypal": "corecoding"
1414
}

prefs.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const Settings = new GObject.Class({
6262
}
6363

6464
// process individual drop down sensor preferences
65-
sensors = [ 'position-in-panel', 'unit', 'network-speed-format', 'memory-measurement', 'storage-measurement', 'battery-slot', 'icon-style' ];
65+
sensors = [ 'position-in-panel', 'unit', 'network-speed-format', 'network-speed-unit', 'memory-measurement', 'storage-measurement', 'battery-slot', 'icon-style', 'network-public-ip-provider' ];
6666
for (let key in sensors) {
6767
let sensor = sensors[key];
6868

@@ -73,6 +73,14 @@ const Settings = new GObject.Class({
7373
});
7474
}
7575

76+
let providerWidget = this.builder.get_object('network-public-ip-provider');
77+
let flagWidget = this.builder.get_object('network-public-ip-show-flag');
78+
let updateFlagSensitivity = () => {
79+
flagWidget.set_sensitive(providerWidget.get_active() !== 1);
80+
};
81+
updateFlagSensitivity();
82+
providerWidget.connect('changed', updateFlagSensitivity);
83+
7684
this._settings.bind('update-time', this.builder.get_object('update-time'), 'value', Gio.SettingsBindFlags.DEFAULT);
7785

7886
this._settings.bind('network-public-ip-interval', this.builder.get_object('network-public-ip-interval'),

prefs.ui

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686
</property>
8787
</object>
8888
</child>
89+
<child>
90+
<object class="GtkListBoxRow">
91+
<property name="width_request">100</property>
92+
<property name="selectable">0</property>
93+
<property name="child">
94+
<object class="GtkBox">
95+
<property name="can_focus">0</property>
96+
<property name="margin_top">6</property>
97+
<property name="margin_bottom">6</property>
98+
<property name="margin_start">6</property>
99+
<property name="margin_end">6</property>
100+
<child>
101+
<object class="GtkLabel">
102+
<property name="hexpand">1</property>
103+
<property name="can_focus">0</property>
104+
<property name="halign">start</property>
105+
<property name="label" translatable="yes">Public IP provider</property>
106+
</object>
107+
</child>
108+
<child>
109+
<object class="GtkComboBoxText" id="network-public-ip-provider">
110+
<property name="can_focus">0</property>
111+
<property name="active">0</property>
112+
<items>
113+
<item translatable="yes">Core Coding</item>
114+
<item translatable="yes">ipify</item>
115+
<item translatable="yes">MyIP.com</item>
116+
</items>
117+
</object>
118+
</child>
119+
</object>
120+
</property>
121+
</object>
122+
</child>
89123
<child>
90124
<object class="GtkListBoxRow">
91125
<property name="visible">True</property>
@@ -147,6 +181,40 @@
147181
</property>
148182
</object>
149183
</child>
184+
<child>
185+
<object class="GtkListBoxRow">
186+
<property name="width_request">100</property>
187+
<property name="selectable">0</property>
188+
<property name="child">
189+
<object class="GtkBox">
190+
<property name="can_focus">0</property>
191+
<property name="margin_top">6</property>
192+
<property name="margin_bottom">6</property>
193+
<property name="margin_start">6</property>
194+
<property name="margin_end">6</property>
195+
<child>
196+
<object class="GtkLabel">
197+
<property name="hexpand">1</property>
198+
<property name="can_focus">0</property>
199+
<property name="halign">start</property>
200+
<property name="label" translatable="yes">Speed Unit</property>
201+
</object>
202+
</child>
203+
<child>
204+
<object class="GtkComboBoxText" id="network-speed-unit">
205+
<property name="can_focus">0</property>
206+
<property name="active">0</property>
207+
<items>
208+
<item translatable="yes">Auto</item>
209+
<item translatable="yes">Kbps / KiB/s</item>
210+
<item translatable="yes">Mbps / MiB/s</item>
211+
</items>
212+
</object>
213+
</child>
214+
</object>
215+
</property>
216+
</object>
217+
</child>
150218
</object>
151219
</property>
152220
</object>

schemas/gschemas.compiled

136 Bytes
Binary file not shown.

schemas/org.gnome.shell.extensions.vitals.gschema.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,21 @@
8989
<default>true</default>
9090
<summary>Show country flag for public IP</summary>
9191
</key>
92+
<key type="i" name="network-public-ip-provider">
93+
<default>0</default>
94+
<summary>Public IP provider</summary>
95+
<description>Service used to look up public IP address. 0=Core Coding, 1=ipify, 2=MyIP.com</description>
96+
</key>
9297
<key type="i" name="network-speed-format">
9398
<default>0</default>
9499
<summary>Network speed format</summary>
95100
<description>Should speed display in bits or bytes?</description>
96101
</key>
102+
<key type="i" name="network-speed-unit">
103+
<default>0</default>
104+
<summary>Fixed network speed unit</summary>
105+
<description>Fix the network speed unit instead of auto-scaling. 0=Auto, 1=Kbps/KiB/s, 2=Mbps/MiB/s</description>
106+
</key>
97107
<key type="s" name="storage-path">
98108
<default>"/"</default>
99109
<summary>Storage path</summary>

sensors.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export const Sensors = GObject.registerClass({
5353
this._settingChangedSignals = [];
5454
this._addSettingChangedSignal('show-gpu', this._reconfigureNvidiaSmiProcess.bind(this));
5555
this._addSettingChangedSignal('update-time', this._reconfigureNvidiaSmiProcess.bind(this));
56-
this._addSettingChangedSignal('network-public-ip-interval', () => {this._lastPublicIPCheck = 0;});
56+
this._addSettingChangedSignal('network-public-ip-interval', () => {this._next_public_ip_check = 0;});
57+
this._addSettingChangedSignal('network-public-ip-provider', () => {this._next_public_ip_check = 0;});
5758
//this._addSettingChangedSignal('include-static-gpu-info', this._reconfigureNvidiaSmiProcess.bind(this));
5859

5960
this._gpu_drm_vendors = null;
@@ -83,11 +84,29 @@ export const Sensors = GObject.registerClass({
8384
}
8485

8586
_refreshIPAddress(callback) {
86-
// check IP address
87-
new FileModule.File('https://ipv4.corecoding.com').read().then(contents => {
87+
const provider = this._settings.get_int('network-public-ip-provider');
88+
let url;
89+
if (provider === 1)
90+
url = 'https://api.ipify.org?format=json';
91+
else if (provider === 2)
92+
url = 'https://api.myip.com';
93+
else
94+
url = 'https://ipv4.corecoding.com';
95+
96+
new FileModule.File(url).read().then(contents => {
8897
let obj = JSON.parse(contents);
89-
let cc = (obj && typeof obj['countryCode'] === 'string') ? obj['countryCode'].trim().toLowerCase() : '';
90-
let ip = (obj && typeof obj['IPv4'] === 'string') ? obj['IPv4'].trim() : '';
98+
let cc = '';
99+
let ip = '';
100+
if (provider === 1) {
101+
ip = (obj && typeof obj['ip'] === 'string') ? obj['ip'].trim() : '';
102+
} else if (provider === 2) {
103+
cc = (obj && typeof obj['cc'] === 'string') ? obj['cc'].trim().toLowerCase() : '';
104+
if (cc === 'xx') cc = ''; // MyIP.com uses XX when country is unknown; not a real flag
105+
ip = (obj && typeof obj['ip'] === 'string') ? obj['ip'].trim() : '';
106+
} else {
107+
cc = (obj && typeof obj['countryCode'] === 'string') ? obj['countryCode'].trim().toLowerCase() : '';
108+
ip = (obj && typeof obj['IPv4'] === 'string') ? obj['IPv4'].trim() : '';
109+
}
91110
const showFlag = this._settings.get_boolean('network-public-ip-show-flag');
92111
let typeOut = (showFlag && /^[a-z]{2}$/.test(cc)) ? ('network-' + cc) : 'network';
93112
this._returnValue(callback, 'Public IP', ip, typeOut, 'string');

values.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,23 @@ export const Values = GObject.registerClass({
141141

142142
break;
143143
case 'speed':
144+
let fixed_unit = this._settings.get_int('network-speed-unit');
145+
144146
if (value > 0) {
145147
if (use_bps) value *= 8;
146-
exp = Math.floor(Math.log(value) / Math.log(unit));
147-
if (value >= Math.pow(unit, exp) * (unit - 0.05)) exp++;
148-
value = parseFloat((value / Math.pow(unit, exp)));
148+
149+
if (fixed_unit > 0) {
150+
// fixed unit: force to K (exp=1) or M (exp=2)
151+
exp = fixed_unit;
152+
value = parseFloat((value / Math.pow(unit, exp)));
153+
} else {
154+
// auto: current behavior
155+
exp = Math.floor(Math.log(value) / Math.log(unit));
156+
if (value >= Math.pow(unit, exp) * (unit - 0.05)) exp++;
157+
value = parseFloat((value / Math.pow(unit, exp)));
158+
}
159+
} else {
160+
exp = 0;
149161
}
150162

151163
format = (use_higher_precision)?'%.1f %s':'%.0f %s';

0 commit comments

Comments
 (0)