Page 1 of 1

Checking Network Adapter...

Posted: September 15th, 2020, 7:30 pm
by brax64
Hi all,

This is the code I've came up with:

Code: Select all


[Variables]
Adapter=Kaspersky Security Data Escort Adapter
U2=[!UpdateMeterGroup IP][!Redraw]
path=#@#Images\

[Adapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
Substitute="#Adapter#":"1","Realtek PCIe GBE Family Controller":"0"

[WAN]
Measure=WebParser
URL=https://api.ipify.org/
RegExp=^(.*)$
StringIndex=1
UpdateRate=600

[VPNCheck]
Measure=Calc
Formula=[Adapter]
IfCondition=VPNCheck = 1
IfTrueAction=[!SetOption VPNIcon ImageName "#path#vpnon.png"][!SetOption IPText Text "[*WAN*]"]#U2#
IfCondition2=VPNCheck = 0
IfTrueAction2=[!SetOption VPNIcon ImageName "#path#vpnoff.png"][!SetOption IPText Text "VPN is off . . ."]#U2#
DynamicVariables=1

[VPNIcon]
Meter=Image
Group=IP
ToolTipText=VPN
SolidColor=0,0,0,1
X=75
Y=535
W=30

[IPText]
Meter=String
Group=IP
MeterStyle=TextStyle
X=45r
Y=8r
DynamicVariables=1
It's working but I've few question about it:

- How can I avoid to describe the default adapter (Realtek PCIe GBE Family Controller) but simply verify if the Kaspersky one (VPN) is in use or not? If I don't describe the default adapter (Realtek), can't use !IfFalseAction instead of !IfCondition2 in the [VPNCheck] measure because i get an error (Calc: "Realtek" is unknown (Gruvy\Dash\Gruvy.ini - [VPNCheck])

- How can I update the [WAN] measure on the fly when [Adapter] measure's value change and leave the UpdateRate=600 just to check periodically if the IP address has changed (Kaspersky VPN it change address randomly, I guess it depends by traffic in order to get the best service...)

- Why, in order to make it works, I've to use [!SetOption IPText Text "[*WAN*]" instead of [!SetOption IPText Text "[WAN]"]

Re: Checking Network Adapter...

Posted: September 15th, 2020, 7:44 pm
by balala
brax64 wrote: September 15th, 2020, 7:30 pm - Why, in order to make it works, I've to use [!SetOption IPText Text "[*WAN*]" instead of [!SetOption IPText Text "[WAN]"]
Because of this: https://docs.rainmeter.net/manual/skins/option-types/#AsteriskEscape

Re: Checking Network Adapter...

Posted: September 16th, 2020, 2:20 am
by brax64
brax64 wrote: September 15th, 2020, 7:30 pm - How can I avoid to describe the default adapter (Realtek PCIe GBE Family Controller) but simply verify if the Kaspersky one (VPN) is in use or not? If I don't describe the default adapter (Realtek), can't use !IfFalseAction instead of !IfCondition2 in the [VPNCheck] measure because i get an error (Calc: "Realtek" is unknown (Gruvy\Dash\Gruvy.ini - [VPNCheck])

- How can I update the [WAN] measure on the fly when [Adapter] measure's value change and leave the UpdateRate=600 just to check periodically if the IP address has changed (Kaspersky VPN it change address randomly, I guess it depends by traffic in order to get the best service...)
Found a solution myself with this:

Code: Select all

[WAN]
Measure=WebParser
URL=https://api.ipify.org/
RegExp=^(.*)$
StringIndex=1
UpdateRate=600

[Adapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1

[VPNCheck]
Measure=String
String=[Adapter]
DynamicVariables=1
IfMatch=#Adapter#
IfMatchAction=[!SetOption VPNIcon ImageName "#path#vpnon.png"][!SetOption IPText Text "[*WAN*]"]#U2#
IfNotMatchAction=[!SetOption VPNIcon ImageName "#path#vpnoff.png"][!SetOption IPText Text "VPN is off . . ."]#U2#
OnChangeAction=[!CommandMeasure WAN "Update"]

Re: Checking Network Adapter...

Posted: September 16th, 2020, 8:21 am
by Yincognito
brax64 wrote: September 16th, 2020, 2:20 am Found a solution myself with this:

Code: Select all

[WAN]
Measure=WebParser
URL=https://api.ipify.org/
RegExp=^(.*)$
StringIndex=1
UpdateRate=600

[Adapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1

[VPNCheck]
Measure=String
String=[Adapter]
DynamicVariables=1
IfMatch=#Adapter#
IfMatchAction=[!SetOption VPNIcon ImageName "#path#vpnon.png"][!SetOption IPText Text "[*WAN*]"]#U2#
IfNotMatchAction=[!SetOption VPNIcon ImageName "#path#vpnoff.png"][!SetOption IPText Text "VPN is off . . ."]#U2#
OnChangeAction=[!CommandMeasure WAN "Update"]
See, that was easy - no point in using numerical IfConditions where string capable IfMatches can do. By the way, if the U2 variable or other considerations in your skin don't interfere with this, you can get rid of [VPNCheck] and move your IfMatch and OnChangeAction directly into [Adapter]. Creating duplicate measures is useful in cases where you can't do what you want in the original measure, but I doubt this is such a case here...

Re: Checking Network Adapter...

Posted: September 16th, 2020, 10:01 am
by brax64
Yincognito wrote: September 16th, 2020, 8:21 am See, that was easy - no point in using numerical IfConditions where string capable IfMatches can do. By the way, if the U2 variable or other considerations in your skin don't interfere with this, you can get rid of [VPNCheck] and move your IfMatch and OnChangeAction directly into [Adapter]. Creating duplicate measures is useful in cases where you can't do what you want in the original measure, but I doubt this is such a case here...
Hi Yincognito,

Thank for the tip! Moved IfMatch and OnChangeAction directly to the [Adapter] measure and got rid off the [VPNCheck] measure, nice and clean!
Sometimes I miss simple solutions and get lost over thinking the problem... well, I'm happy 'cause I've been able to find a solution and learnt a little more :)

Re: Checking Network Adapter...

Posted: September 16th, 2020, 1:25 pm
by Yincognito
brax64 wrote: September 16th, 2020, 10:01 am Hi Yincognito,

Thank for the tip! Moved IfMatch and OnChangeAction directly to the [Adapter] measure and got rid off the [VPNCheck] measure, nice and clean!
Sometimes I miss simple solutions and get lost over thinking the problem... well, I'm happy 'cause I've been able to find a solution and learnt a little more :)
Yeah, no problem. It's simple things like these that can shorten the code, since the length and the redundancy of the code is one of the things users keep mentioning (read complaining) about when it comes to Rainmeter.