It is currently December 3rd, 2020, 10:35 am

VPN skin not updating

Help with creating, editing & fixing problems with skins
Darv
Posts: 11
Joined: September 27th, 2015, 1:48 am

VPN skin not updating

Post by Darv »

This skin seems to work great to determine if the PIA VPN application is active or not. However it only updates on initial launch or manual refresh. If I turn the VPN off, it does not update the skin. And the reverse is true, if it correctly identifies that the VPN is off, then I start it, it does not reflect the new state in the skin. I left the default Update at 1000 but have tried other settings.

Any help would be appreciated.
Thanks

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=3
SolidColor=0,0,0,90

[Metadata]
; Contains basic information of the skin.
Name=VPN Status

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoData=Best
SysInfoType=ADAPTER_DESCRIPTION
Substitute="Private Internet Access Network Adapter":"1","WireGuard Tunnel":"1"
DynamicVariables=1

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork]
IfCondition=OnlineStatus = 1
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfCondition2=OnlineStatus <> 1
IfTrueAction2=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]

[PiaIcon]
Meter=Image
ImageName=pia_gray.png
W=30
H=30
X=8
Y=7

[MeterNetwork]
Meter=String
MeasureName=OnlineStatus
FontSize=30
FontColor=167,167,167,255
StringStyle=Bold
AntiAlias=1
Text= VPN
X=40
Last edited by balala on November 15th, 2020, 8:17 pm, edited 1 time in total.
Reason: Please use <code> tags whenever are posting code snippets. It's the </> button.
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: VPN skin not updating

Post by balala »

Darv wrote: November 15th, 2020, 7:57 pm This skin seems to work great to determine if the PIA VPN application is active or not. However it only updates on initial launch or manual refresh. If I turn the VPN off, it does not update the skin. And the reverse is true, if it correctly identifies that the VPN is off, then I start it, it does not reflect the new state in the skin. I left the default Update at 1000 but have tried other settings.
The [OnlineStatus] measure uses a section variable ([MeasureNetwork]) into its Formula option (Formula=[MeasureNetwork]). But such a section variable requires setting on the dynamic Variables. So add a DynamicVariables=1 option to this measure.

Additional note: since the [MeasureNetwork] measure returns both, a String and a numeric value, I'd use better its numeric value into Formula option of a Calc measure. In fact this option always works only with numeric values, so how have you set it is ok, however I recommend to explicitely say the measure to use numeric value. To do this replace the mentioned Formula option with Formula=[MeasureNetwork:].
Darv
Posts: 11
Joined: September 27th, 2015, 1:48 am

Re: VPN skin not updating

Post by Darv »

Well, assuming I did everything right, it seems to have broke the script. But then I know very little of scripting skins.
Here is the skin. I am sure I did something wrong. Adding the: Formula=[MeasureNetwork:] seems to have broke it as it no longer is able to determine the status as anything but offline.

Thanks for trying to help.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=3
SolidColor=0,0,0,90

[Metadata]
; Contains basic information of the skin.
Name=VPN Status

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoData=Best
SysInfoType=ADAPTER_DESCRIPTION
Substitute="Private Internet Access Network Adapter":"1","WireGuard Tunnel":"1"
DynamicVariables=1

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork:]
IfCondition=OnlineStatus = 1
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfCondition2=OnlineStatus <> 1
IfTrueAction2=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]
DynamicVariables=1

[PiaIcon]
Meter=Image
ImageName=pia_gray.png
W=30
H=30
X=8
Y=7

[MeterNetwork]
Meter=String
MeasureName=OnlineStatus
FontSize=30
FontColor=167,167,167,255
StringStyle=Bold
AntiAlias=1
Text= VPN
X=40
User avatar
jsmorley
Developer
Posts: 21520
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: VPN skin not updating

Post by jsmorley »

Darv wrote: November 15th, 2020, 10:35 pm Well, assuming I did everything right, it seems to have broke the script. But then I know very little of scripting skins.
Here is the skin. I am sure I did something wrong. Adding the: Formula=[MeasureNetwork:] seems to have broke it as it no longer is able to determine the status as anything but offline.

Thanks for trying to help.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=3
SolidColor=0,0,0,90

[Metadata]
; Contains basic information of the skin.
Name=VPN Status

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoData=Best
SysInfoType=ADAPTER_DESCRIPTION
Substitute="Private Internet Access Network Adapter":"1","WireGuard Tunnel":"1"
DynamicVariables=1

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork:]
IfCondition=OnlineStatus = 1
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfCondition2=OnlineStatus <> 1
IfTrueAction2=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]
DynamicVariables=1

[PiaIcon]
Meter=Image
ImageName=pia_gray.png
W=30
H=30
X=8
Y=7

[MeterNetwork]
Meter=String
MeasureName=OnlineStatus
FontSize=30
FontColor=167,167,167,255
StringStyle=Bold
AntiAlias=1
Text= VPN
X=40
Since you are using Substitute to change the name of the adapter into a number, that is acting on the string value of the measure. So you want to use:

Formula=[MeasureNetwork]

And not:

Formula=[MeasureNetwork:]

Since using the : character in the section variable tells it to use the number value, which this measure won't have. The number value of the measure will always be 0.
Darv
Posts: 11
Joined: September 27th, 2015, 1:48 am

Re: VPN skin not updating

Post by Darv »

jsmorley wrote: November 15th, 2020, 10:51 pm Since you are using Substitute to change the name of the adapter into a number, that is acting on the string value of the measure. So you want to use:

Formula=[MeasureNetwork]

And not:

Formula=[MeasureNetwork:]

Since using the : character in the section variable tells it to use the number value, which this measure won't have. The number value of the measure will always be 0.

Thanks! Yes, that explains why adding the Formula=[MeasureNetwork:] broke the script. The script now does detect the change from Off to On (turns the icon from Red to Green) but fails to turn the icon from On to OFF when turning the VPN off. So we are like 95% there. Adding the DynamicVariables=1 to the [OnlineStatus] seemed to fix the detection that the VPN had been turned on. Now I just need to get it to detect an Off state.

Thanks again for the help. Can you see any reason it wouldn't detect the VPN going off line?
Here is the current script.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=3
SolidColor=0,0,0,90

[Metadata]
; Contains basic information of the skin.
Name=VPN Status

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoData=Best
SysInfoType=ADAPTER_DESCRIPTION
Substitute="Private Internet Access Network Adapter":"1","WireGuard Tunnel":"1"
DynamicVariables=1

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork]
IfCondition=OnlineStatus = 1
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfCondition2=OnlineStatus <> 1
IfTrueAction2=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]
DynamicVariables=1

[PiaIcon]
Meter=Image
ImageName=pia_gray.png
W=30
H=30
X=8
Y=7

[MeterNetwork]
Meter=String
MeasureName=OnlineStatus
FontSize=30
FontColor=167,167,167,255
StringStyle=Bold
AntiAlias=1
Text= VPN
X=40
Last edited by balala on November 16th, 2020, 7:18 am, edited 1 time in total.
Reason: Please use <code> tags whenever are posting code snippets. It's the </> button.
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: VPN skin not updating

Post by balala »

jsmorley wrote: November 15th, 2020, 10:51 pm Since you are using Substitute to change the name of the adapter into a number, that is acting on the string value of the measure. So you want to use:

Formula=[MeasureNetwork]

And not:

Formula=[MeasureNetwork:]

Since using the : character in the section variable tells it to use the number value, which this measure won't have. The number value of the measure will always be 0.
Yep, I missed this detail. Sorry, my bad...
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: VPN skin not updating

Post by balala »

Darv wrote: November 15th, 2020, 11:10 pm Can you see any reason it wouldn't detect the VPN going off line?
You might want to try the followings:
  • Remove the IfCondition2 option from the [OnlineStatus] measure and replace IfTrueAction2 by IfFalseAction.
  • Try including the name of the same [OnlineStatus] measure into brackets in the IfCondition option.
Not sure any of the advices helps, but maybe it worth a try. Here is an updated code of the measure in question:

Code: Select all

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork]
IfCondition=([OnlineStatus]=1)
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfFalseAction=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]
DynamicVariables=1
Darv
Posts: 11
Joined: September 27th, 2015, 1:48 am

Re: VPN skin not updating

Post by Darv »

balala wrote: November 16th, 2020, 7:30 am You might want to try the followings:
  • Remove the IfCondition2 option from the [OnlineStatus] measure and replace IfTrueAction2 by IfFalseAction.
  • Try including the name of the same [OnlineStatus] measure into brackets in the IfCondition option.
Not sure any of the advices helps, but maybe it worth a try. Here is an updated code of the measure in question:

Code: Select all

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork]
IfCondition=([OnlineStatus]=1)
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfFalseAction=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]
DynamicVariables=1
Thanks balala,

I used your code and it seems to work exactly the same.
1) PIA = OFF - Launching skin correctly shows RED.
2) PIA = ON - Launch PIA and connect skin changes to GREEN.
3) PIA = OFF - Turn PIA off and skin remains GREEN (Should change to RED)
4) PIA = ON - Launch skin turns GREEN

So only item #3 fails to detect that PIA has been turned off. I am completely baffled. If item #1 is detecting PIA=OFF and it gets re-run every 1 second why isn't it detecting that PIA has been turned off?

I really do appreciate all the work you put into it. The code seems to make sense to me but fails to function as it should.

If you have any further ideas, please do let me know. I hate to give up on this. I know for a fact it can work.

Thanks,
Darv
Darv
Posts: 11
Joined: September 27th, 2015, 1:48 am

Re: VPN skin not updating [SOLVED!!]

Post by Darv »

Okay, good news. The script did not know how to deal with the default ADAPTER_DESCRIPTION because the Substitute did not assign it a numeric value. So it was seeing the string for the Intel(R) Ethernet Connection I217-V adapter instead of a numeric value. When I assigned the value other than 1 to the Intel adapter it worked like a charm. It now detects the connection to the Intel adapter as a number 2 and thus invalid.

QUESTION: Is there a way to assign anything other than the PIA adapter a value other than 1 in the Substitute line so the script would work on anyone's computer? If so I will post it.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=1
SolidColor=0,0,0,90

[Metadata]
; Contains basic information of the skin.
Name=VPN Status

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoData=Best
SysInfoType=ADAPTER_DESCRIPTION
Substitute="Private Internet Access Network Adapter":"1","Intel(R) Ethernet Connection I217-V":"2"
DynamicVariables=1

[OnlineStatus]
Measure=Calc
Formula=[MeasureNetwork]
IfCondition=([OnlineStatus]=1)
IfTrueAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter PiaIcon][!Redraw]
IfFalseAction=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter PiaIcon][!Redraw]
DynamicVariables=1

[PiaIcon]
Meter=Image
ImageName=pia_gray.png
W=30
H=30
X=8
Y=7

[MeterNetwork]
Meter=String
MeasureName=OnlineStatus
FontSize=30
FontColor=167,167,167,255
StringStyle=Bold
AntiAlias=1
Text= VPN

X=40
Last edited by eclectic-tech on November 17th, 2020, 2:52 am, edited 1 time in total.
Reason: Please use code tags. It is the </> symbol.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4206
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: VPN skin not updating [SOLVED!!]

Post by eclectic-tech »

Darv wrote: November 17th, 2020, 12:09 am QUESTION: Is there a way to assign anything other than the PIA adapter a value other than 1 in the Substitute line so the script would work on anyone's computer? If so I will post it.
Use IfMatch and the string value of the network description measure rather than substituting the text with numbers .

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=3
SolidColor=0,0,0,90

[Metadata]
; Contains basic information of the skin.
Name=VPN Status

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoData=Best
SysInfoType=ADAPTER_DESCRIPTION
IfMatch={?i)^Private Internet Access Network Adapter$
IfMatchAction=[!SetOption MeterNetwork FontColor 0,255,0,155][!SetOption PiaIcon ImageName pia_on.png][!UpdateMeter *][!Redraw]
IfNotMatchAction=[!SetOption MeterNetwork FontColor 255,0,0,255][!SetOption PiaIcon ImageName pia_off.png][!UpdateMeter *][!Redraw]

[PiaIcon]
Meter=Image
ImageName=pia_gray.png
W=30
H=30
X=8
Y=7

[MeterNetwork]
Meter=String
FontSize=30
FontColor=167,167,167,255
StringStyle=Bold
AntiAlias=1
Text= VPN
X=40
The IfMatch uses RegExp to set the options directly:
when [MeasureNetwork] equals "Private Internet Access Network Adapter" the match actions are taken
when [MeasureNetwork] equals any other text, the not match actions.