forked from hthienloc/dms-ipIndicator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPIndicatorWidget.qml
More file actions
830 lines (741 loc) · 32.6 KB
/
Copy pathIPIndicatorWidget.qml
File metadata and controls
830 lines (741 loc) · 32.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
import QtQuick
import QtQuick.Controls
import Quickshell
import Quickshell.Io
import qs.Common
import qs.Services
import qs.Widgets
import qs.Modules.Plugins
import "../dms-common"
PluginComponent {
id: root
LocalI18n {
id: localI18n
baseUrl: Qt.resolvedUrl(".")
}
// Public IP state
property string publicIP: ""
property string ispName: ""
property string countryCode: ""
property string countryName: ""
property string regionName: ""
property string cityName: ""
property string statusMessage: "..."
// Settings
property bool privacyMode: (pluginData.privacyDefault || false)
property bool autoRefresh: (pluginData.autoRefresh ?? true)
readonly property bool showHints: (pluginData.showHints ?? true)
readonly property bool showIP: (pluginData.showIP ?? true)
readonly property bool showISP: (pluginData.showISP ?? true)
readonly property bool showLocation: (pluginData.showLocation ?? true)
readonly property bool showLocalIP: (pluginData.showLocalIP ?? true)
readonly property bool showLocalGateway: (pluginData.showLocalGateway ?? true)
readonly property bool showLocalInterface: (pluginData.showLocalInterface ?? true)
readonly property bool showLatency: (pluginData.showLatency ?? true)
readonly property bool useFlagIcon: (pluginData.useFlagIcon ?? true)
readonly property string displayMode: (pluginData.displayMode || "country")
readonly property bool notifyOnIPChange: (pluginData.notifyOnIPChange ?? false)
readonly property int refreshIntervalMin: (pluginData.refreshInterval ?? 30)
onRefreshIntervalMinChanged: {
if (bgRefreshTimer.running) {
bgRefreshTimer.restart()
}
}
// Fetching state
property bool isFetching: false
// VPN Detection
property bool vpnActive: false
property string vpnInterfaceName: ""
// Latency
property string latencyMs: ""
property string latencyError: ""
// Local Network
property string localIP: ""
property string localGateway: ""
property string localInterface: ""
// Shell script to fetch local IP address with multiple robust fallback layers
readonly property string _localIPScript: [
"ip route get 1.1.1.1 2>/dev/null | awk '/src/ {for(i=1;i<=NF;i++) if($i==\"src\") {print $(i+1); exit}}'",
"hostname -I 2>/dev/null | awk '{print $1}'",
"ip address | awk '/inet / && !/127.0.0.1/ {split($2, a, \"/\"); print a[1]; exit}'"
].join(" || ")
// IP change tracking
property string lastKnownIP: ""
property string lastKnownCountryCode: ""
// Provider list for redundancy (primary uses HTTPS for privacy/security)
property var ipProviders: [
{
name: "ip-api.com",
url: "http://ip-api.com/json",
parser: function(data) {
return {
ip: data.query || "",
isp: data.isp || data.org || "",
countryCode: (data.countryCode || "").toLowerCase(),
country: data.country || "",
region: data.regionName || data.region || "",
city: data.city || ""
}
}
},
{
name: "ipinfo.io",
url: "https://ipinfo.io/json",
parser: function(data) {
return {
ip: data.ip || "",
isp: data.org || "",
countryCode: (data.country || "").toLowerCase(),
country: null,
region: data.region || "",
city: data.city || ""
}
}
},
{
name: "freeipapi.com",
url: "https://freeipapi.com/api/json",
parser: function(data) {
return {
ip: data.ipAddress || "",
isp: data.asnOrganization || "",
countryCode: (data.countryCode || "").toLowerCase(),
country: data.countryName || "",
region: data.regionName || "",
city: data.cityName || ""
}
}
}
]
Component.onCompleted: {
checkVPN()
fetchLocalDetails()
if (autoRefresh) {
statusMessage = "..."
fetchIPInfo()
} else {
statusMessage = localI18n.tr("Click to fetch")
}
}
Timer {
id: bgRefreshTimer
interval: refreshIntervalMin * 60 * 1000 // Convert minutes to milliseconds
running: autoRefresh
repeat: true
triggeredOnStart: false
onTriggered: {
checkVPN()
fetchLocalDetails()
fetchIPInfo()
}
}
// Automatically detect network or VPN changes and trigger a fast, responsive refetch
Connections {
target: NetworkService
function onConnectionChanged() {
vpnRefreshTimer.restart()
}
}
Timer {
id: vpnRefreshTimer
interval: 1500 // 1.5s delay to allow routing tables to settle
running: false
repeat: false
onTriggered: {
checkVPN()
fetchLocalDetails()
fetchIPInfo()
}
}
// Shell command helpers — thin wrappers around Proc.runCommand
// for commonly used shell pipelines. Keeps the main logic readable
// and avoids dense sh -c invocations scattered through the code.
function _runSh(taskId, script, callback) {
Proc.runCommand(taskId, ["sh", "-c", script], callback, 50, 3000)
}
function _findVpnInterface() {
_runSh("check-vpn", "ls /sys/class/net | grep -E '^(tun|tap|wg|ppp|proton|tailscale|zero|vpn|cscotun)' | head -1", function(output, exitCode) {
if (exitCode === 0 && output.trim() !== "") {
vpnActive = true
vpnInterfaceName = output.trim()
} else {
vpnActive = false
vpnInterfaceName = ""
}
})
}
function _fetchLocalInterface() {
_runSh("local-iface", "ip route get 1.1.1.1 | awk '/dev/ {for(i=1;i<=NF;i++) if($i==\"dev\") print $(i+1); exit}'", function(output, exitCode) {
localInterface = (exitCode === 0 && output.trim() !== "") ? output.trim() : "N/A"
})
}
function _fetchLocalGateway() {
_runSh("local-gw", "ip route | awk '/default/ {print $3; exit}'", function(output, exitCode) {
localGateway = (exitCode === 0 && output.trim() !== "") ? output.trim() : "N/A"
})
}
function _fetchLocalIP() {
_runSh("local-ip-addr", root._localIPScript, function(output, exitCode) {
localIP = (exitCode === 0 && output.trim() !== "") ? output.trim() : "N/A"
})
}
function checkVPN() {
_findVpnInterface()
}
function measureLatency(target) {
if (!target) target = "8.8.8.8"
latencyMs = ""
latencyError = ""
Proc.runCommand(
"ping-" + target,
["ping", "-c", "1", "-W", "2", target],
function(output, exitCode) {
if (exitCode !== 0) {
latencyError = "Fail"
return
}
var match = output.match(/time=([\d\.]+)\s*ms/)
if (match) {
latencyMs = match[1] + " ms"
} else {
latencyError = "N/A"
}
},
50,
5000
)
}
function fetchLocalDetails() {
_fetchLocalInterface()
_fetchLocalGateway()
_fetchLocalIP()
}
function fetchIPInfo() {
lastKnownIP = publicIP
lastKnownCountryCode = countryCode
isFetching = true
statusMessage = "..."
tryProvider(0)
}
function tryProvider(index) {
if (index >= ipProviders.length) {
isFetching = false
statusMessage = localI18n.tr("Error")
return
}
var provider = ipProviders[index]
Proc.runCommand(
"fetch-ip-" + index,
["curl", "-s", provider.url],
function(output, exitCode) {
if (exitCode !== 0 || !output) {
tryProvider(index + 1)
return
}
try {
var data = JSON.parse(output)
var parsed = provider.parser(data)
if (!parsed || !parsed.ip) {
tryProvider(index + 1)
return
}
publicIP = parsed.ip || ""
ispName = parsed.isp || ""
countryCode = parsed.countryCode || ""
if (parsed.country) countryName = parsed.country
regionName = parsed.region || ""
cityName = parsed.city || ""
var ipChanged = lastKnownIP !== "" && publicIP !== lastKnownIP
if (notifyOnIPChange && ipChanged) {
var reason = ""
if (privacyMode) {
reason = localI18n.tr("Network connection changed") + " (" + localI18n.tr("IP details hidden in Privacy Mode") + ")"
} else {
var lines = [
localI18n.tr("Old IP") + ": " + lastKnownIP + (lastKnownCountryCode ? " " + root.getFlagEmoji(lastKnownCountryCode) : ""),
localI18n.tr("New IP") + ": " + publicIP + (countryCode ? " " + root.getFlagEmoji(countryCode) : "")
]
if (ispName) {
lines.push(localI18n.tr("ISP") + ": " + ispName)
}
var locs = []
if (cityName) locs.push(cityName)
if (regionName) locs.push(regionName)
if (countryName) locs.push(countryName)
if (locs.length > 0) {
lines.push(localI18n.tr("Location") + ": " + locs.join(", "))
}
reason = lines.join("\n")
}
Proc.runCommand("notify-ip-change", ["notify-send", "IP Indicator", reason], function() {}, 50, 5000)
}
lastKnownIP = publicIP
lastKnownCountryCode = countryCode
isFetching = false
statusMessage = "OK"
} catch (e) {
tryProvider(index + 1)
}
},
50,
30000
)
}
function togglePrivacy() {
privacyMode = !privacyMode
}
function getDisplayText() {
if (root.displayMode === "icon") return ""
if (privacyMode) return ""
if (isFetching) return "..."
if (root.publicIP) {
switch (root.displayMode) {
case "ip": return root.publicIP;
case "country_ip": return (countryCode ? countryCode.toUpperCase() + " " : "") + root.publicIP;
case "city": return cityName || countryCode.toUpperCase();
case "isp": return ispName || "N/A";
case "country_city": return (countryCode ? countryCode.toUpperCase() : "") + (cityName ? " - " + cityName : "");
case "city_ip": return (cityName ? cityName + " " : "") + root.publicIP;
case "country":
default:
return countryCode ? countryCode.toUpperCase() : root.publicIP;
}
}
return root.statusMessage
}
function getFlagEmoji(code) {
if (!code || code.length !== 2) return "";
let codePoints = [];
let upper = code.toUpperCase();
for (let i = 0; i < upper.length; i++) {
codePoints.push(127397 + upper.charCodeAt(i));
}
return String.fromCodePoint.apply(null, codePoints);
}
readonly property color pillColor: {
if (isFetching) return Theme.surfaceText
if (privacyMode) return Theme.warning
if (vpnActive) return Theme.success
if (root.publicIP) return Theme.primary
return Theme.surfaceText
}
pillRightClickAction: () => {
checkVPN()
fetchLocalDetails()
fetchIPInfo()
}
horizontalBarPill: Component {
Row {
spacing: Theme.spacingS
Image {
source: root.countryCode ? "./flags/" + root.countryCode.toLowerCase() + ".png" : ""
width: 20
height: 14
fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
visible: root.useFlagIcon && !privacyMode && root.countryCode !== ""
smooth: true
asynchronous: true
cache: true
}
DankIcon {
name: privacyMode ? "visibility_off" : (vpnActive ? "vpn_key" : "public")
size: Theme.iconSizeSmall
color: root.pillColor
anchors.verticalCenter: parent.verticalCenter
visible: !root.useFlagIcon || privacyMode || root.countryCode === ""
}
StyledText {
text: root.getDisplayText()
color: root.pillColor
font.pixelSize: Theme.fontSizeMedium
anchors.verticalCenter: parent.verticalCenter
visible: root.displayMode !== "icon" && root.getDisplayText() !== ""
}
}
}
verticalBarPill: Component {
Column {
spacing: Theme.spacingXS
Image {
source: root.countryCode ? "./flags/" + root.countryCode.toLowerCase() + ".png" : ""
width: 20
height: 14
fillMode: Image.PreserveAspectFit
anchors.horizontalCenter: parent.horizontalCenter
visible: root.useFlagIcon && !privacyMode && root.countryCode !== ""
smooth: true
asynchronous: true
cache: true
}
DankIcon {
name: privacyMode ? "visibility_off" : (vpnActive ? "vpn_key" : "public")
size: Theme.iconSizeSmall
color: root.pillColor
anchors.horizontalCenter: parent.horizontalCenter
visible: !root.useFlagIcon || privacyMode || root.countryCode === ""
}
StyledText {
text: root.getDisplayText()
color: root.pillColor
font.pixelSize: Theme.fontSizeSmall
anchors.horizontalCenter: parent.horizontalCenter
visible: root.displayMode !== "icon" && root.getDisplayText() !== ""
}
}
}
popoutContent: Component {
FocusScope {
width: parent ? parent.width : 0
implicitHeight: mainContent.implicitHeight
Component.onCompleted: {
measureLatency("8.8.8.8")
}
PopoutComponent {
id: mainContent
width: parent.width
headerText: "IP Indicator" + (vpnActive ? " (VPN)" : "")
detailsText: privacyMode ? "Hidden" : root.statusMessage
showCloseButton: false
headerActions: Component {
Row {
spacing: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
// Privacy Button
Rectangle {
width: 32
height: 32
radius: 16
color: privacyArea.containsMouse ? Theme.surfaceContainerHigh : "transparent"
anchors.verticalCenter: parent.verticalCenter
DankIcon {
anchors.centerIn: parent
name: privacyMode ? "visibility_off" : "visibility"
size: Theme.iconSizeSmall
color: Theme.surfaceText
}
MouseArea {
id: privacyArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: togglePrivacy()
}
}
// Refresh Button
Rectangle {
width: 32
height: 32
radius: 16
color: refreshArea.containsMouse ? Theme.surfaceContainerHigh : "transparent"
anchors.verticalCenter: parent.verticalCenter
DankIcon {
anchors.centerIn: parent
name: "refresh"
size: Theme.iconSizeSmall
color: Theme.surfaceText
}
MouseArea {
id: refreshArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
checkVPN()
fetchLocalDetails()
fetchIPInfo()
}
}
}
}
}
Column {
width: parent.width
spacing: Theme.spacingM
// VPN badge
Row {
spacing: Theme.spacingS
visible: vpnActive
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
text: "VPN: " + vpnInterfaceName
color: Theme.success
font.pixelSize: Theme.fontSizeMedium
}
}
// Group 1: Public Connection Card
StyledRect {
width: parent.width
height: visible ? (group1Column.implicitHeight + Theme.spacingM * 2) : 0
color: Theme.surfaceContainerHigh
radius: Theme.cornerRadius
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.1)
border.width: 1
visible: root.showIP || root.showISP || root.showLocation
Column {
id: group1Column
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Theme.spacingM
spacing: Theme.spacingM
StyledText {
text: localI18n.tr("Public Connection")
font.pixelSize: Theme.fontSizeSmall
font.bold: true
color: Theme.primary
}
// IP Row
Row {
width: parent.width
visible: root.showIP
StyledText {
text: localI18n.tr("Public IP")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
anchors.verticalCenter: parent.verticalCenter
}
Row {
spacing: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
visible: !privacyMode && publicIP !== ""
StyledText {
text: publicIP
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
font.bold: true
width: Math.min(implicitWidth, parent.parent.width - 100 - 24 - Theme.spacingS)
elide: Text.ElideRight
anchors.verticalCenter: parent.verticalCenter
}
Rectangle {
width: 24
height: 24
radius: 12
color: copyArea.containsMouse ? Theme.surfaceContainerHigh : "transparent"
anchors.verticalCenter: parent.verticalCenter
DankIcon {
anchors.centerIn: parent
name: "content_copy"
size: Theme.iconSizeSmall - 2
color: Theme.primary
}
MouseArea {
id: copyArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
Proc.runCommand("copy-ip", ["wl-copy", "--", publicIP], function() {
ToastService?.showInfo(localI18n.tr("Copied to clipboard"))
})
}
}
}
}
StyledText {
text: "----"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
visible: privacyMode || !publicIP
anchors.verticalCenter: parent.verticalCenter
}
}
// ISP Row
Row {
width: parent.width
visible: root.showISP
StyledText {
text: localI18n.tr("ISP")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
}
StyledText {
text: privacyMode ? "----" : (ispName || "N/A")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width - 100
elide: Text.ElideRight
}
}
// Location Row
Row {
width: parent.width
visible: root.showLocation
StyledText {
text: localI18n.tr("Location")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
}
StyledText {
text: privacyMode ? "----" : (countryName ? countryName + (cityName || regionName ? " - " + (cityName || regionName) : "") : "N/A")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width - 100
elide: Text.ElideRight
}
}
}
}
// Group 2: Local Network Card
StyledRect {
width: parent.width
visible: root.showLocalIP || root.showLocalGateway || root.showLocalInterface || root.showLatency
height: visible ? (group2Column.implicitHeight + Theme.spacingM * 2) : 0
color: Theme.surfaceContainerHigh
radius: Theme.cornerRadius
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.1)
border.width: 1
Column {
id: group2Column
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Theme.spacingM
spacing: Theme.spacingM
StyledText {
text: localI18n.tr("Local Network")
font.pixelSize: Theme.fontSizeSmall
font.bold: true
color: Theme.primary
}
// Local IP Row
Row {
width: parent.width
visible: root.showLocalIP
StyledText {
text: localI18n.tr("Local IP")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
}
StyledText {
text: localIP || "N/A"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width - 100
elide: Text.ElideRight
}
}
// Gateway Row
Row {
width: parent.width
visible: root.showLocalGateway
StyledText {
text: localI18n.tr("Gateway")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
}
StyledText {
text: localGateway || "N/A"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width - 100
elide: Text.ElideRight
}
}
// Interface Row
Row {
width: parent.width
visible: root.showLocalInterface
StyledText {
text: localI18n.tr("Interface")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
}
StyledText {
text: localInterface || "N/A"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
width: parent.width - 100
elide: Text.ElideRight
}
}
// Latency Row
Row {
width: parent.width
visible: root.showLatency
StyledText {
text: localI18n.tr("Latency")
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
width: 100
}
StyledText {
text: latencyMs ? latencyMs : (latencyError ? latencyError : "")
color: (latencyError ? Theme.error : Theme.surfaceText)
font.pixelSize: Theme.fontSizeMedium
}
}
}
}
HintSection {
showHints: root.showHints
width: parent.width
HintItem {
icon: "mouse"
text: localI18n.tr("Right-click the bar icon to quickly refresh network status")
}
HintItem {
icon: "visibility_off"
text: localI18n.tr("Use the eye button in header to toggle Privacy Mode")
}
}
}
}
}
}
popoutWidth: {
let baseWidth = 330;
let longestIP = 15;
if (!privacyMode && publicIP && publicIP.length > longestIP) {
longestIP = publicIP.length;
}
if (localIP && localIP.length > longestIP) {
longestIP = localIP.length;
}
if (localGateway && localGateway.length > longestIP) {
longestIP = localGateway.length;
}
if (longestIP > 15) {
return baseWidth + (longestIP - 15) * 8;
}
return baseWidth;
}
popoutHeight: {
let h = 80; // Header + spacing
// Group 1: Public Connection Card
if (root.showIP || root.showISP || root.showLocation) {
h += 44; // Card Margins + Title
if (root.showIP) h += 28;
if (root.showISP) h += 28;
if (root.showLocation) h += 28;
let rows = 0;
if (root.showIP) rows++;
if (root.showISP) rows++;
if (root.showLocation) rows++;
if (rows > 1) h += 12 * (rows - 1);
}
// Group 2: Local Network Card
if (root.showLocalIP || root.showLocalGateway || root.showLocalInterface || root.showLatency) {
h += 44; // Card Margins + Title
if (root.showLocalIP) h += 28;
if (root.showLocalGateway) h += 28;
if (root.showLocalInterface) h += 28;
if (root.showLatency) h += 28;
let rows = 0;
if (root.showLocalIP) rows++;
if (root.showLocalGateway) rows++;
if (root.showLocalInterface) rows++;
if (root.showLatency) rows++;
if (rows > 1) h += 12 * (rows - 1);
}
if (root.showHints) h += 60;
return h + 40; // margins
}
}