It is currently April 19th, 2024, 1:02 pm

How to hide text or skin until internet connection is established?

Get help with creating, editing & fixing problems with skins
User avatar
makeitrain
Posts: 11
Joined: October 24th, 2019, 1:10 am

How to hide text or skin until internet connection is established?

Post by makeitrain »

Upon startup, a skin takes a while to load data from a weather website. So while the data is downloading I would like the skin to be hidden or the text size to be set to 0. The skin must not be hidden if a connection in the internet is lost, only at the start up and then unhidden after an internet connection has been established.
I thought about using Ping and !RainmeterSetVariable. Is there a simple way to do this or script already made?
Thank you
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to hide text or skin until internet connection is established?

Post by balala »

makeitrain wrote: October 24th, 2019, 1:21 am Upon startup, a skin takes a while to load data from a weather website. So while the data is downloading I would like the skin to be hidden or the text size to be set to 0. The skin must not be hidden if a connection in the internet is lost, only at the start up and then unhidden after an internet connection has been established.
To hide skin in the very first moment, add an appropriate bang into the OnRefreshaction option of the [Rainmeter] section:

Code: Select all

[Rainmeter]
...
OnRefreshAction=[!Hide]
This bang hides the current skin when it is refreshed / loaded.
But to get it to reappear when the parsing is done, you'll need another bang. Add the following FinishAction option to the parent WebParser measure:

Code: Select all

[MeasureParentWebParser]
...
FinishAction=[!ShowFade]
When the measure finishes parsing the data, the FinishAction is executed, so its !ShowFade bang shows up the previously hidden skin.
Note that if there already is either an OnRefreshAction, or a FinishAction option, you have to add the above two bangs together with the existing ones.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to hide text or skin until internet connection is established?

Post by jsmorley »

balala wrote: October 24th, 2019, 12:40 pm To hide skin in the very first moment, add an appropriate bang into the OnRefreshaction option of the [Rainmeter] section:

Code: Select all

[Rainmeter]
...
OnRefreshAction=[!Hide]
This bang hides the current skin when it is refreshed / loaded.
But to get it to reappear when the parsing is done, you'll need another bang. Add the following FinishAction option to the parent WebParser measure:

Code: Select all

[MeasureParentWebParser]
...
FinishAction=[!ShowFade]
When the measure finishes parsing the data, the FinishAction is executed, so its !ShowFade bang shows up the previously hidden skin.
Note that if there already is either an OnRefreshAction, or a FinishAction option, you have to add the above two bangs together with the existing ones.
Right. I would also point out that there are a couple of other ways to detect the network, and take action based on that.

This will detect if you are connected to your local area network:

Code: Select all

[MeasureNetwork]
Measure=Plugin
Plugin=SysInfo
SysInfoType=LAN_CONNECTIVITY
UpdateDivider=5
DynamicVariables=1
IfCondition=MeasureNetWork = 1
IfTrueAction=[!ShowFade]
IfFalseAction=[!Hide]
This will detect if you are connected to the internet:

Code: Select all

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
UpdateDivider=5
DynamicVariables=1
IfCondition=MeasureInternet = 1
IfTrueAction=[!ShowFade]
IfFalseAction=[!Hide]
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to hide text or skin until internet connection is established?

Post by balala »

jsmorley wrote: October 24th, 2019, 12:50 pm I would also point out that there are a couple of other ways to detect the network, and take action based on that.
Yes. But if I'm not wrong, makeitrain's computer is always conneted to internet, he just wanted to hide the skin while after refresh it didn't get the data yet.
User avatar
makeitrain
Posts: 11
Joined: October 24th, 2019, 1:10 am

Re: How to hide text or skin until internet connection is established?

Post by makeitrain »

Wonderful! Thank you both for you input.

I will tinker with these ideas and implement it because my current code is a waste of resources; it is pinging to Google after the connection is established which is unnecessary.

Code: Select all

[MeasurePing]
Measure=Plugin
Plugin=PingPlugin
DestAddress=www.google.com
UpdateRate=5
DynamicVariables=1
TimeoutValue=0
IfAboveValue=1
IfAboveAction=[!SetVariable LoadingText  ][!SetVariable FontSizeAll 10][!Redraw][!UpdateMeter *]
IfEqualValue=0
IfEqualAction=[!Redraw][!UpdateMeter *]

[MeterPing]
Meter=String
MeasureName=MeasurePing
DynamicVariables=1
X=5
Y=5
W=200
H=20
FontColor=255,255,255,140
FontFace=#FontAll#
Text=#LoadingText#
FontSize=10
AntiAlias=1
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to hide text or skin until internet connection is established?

Post by balala »

makeitrain wrote: October 25th, 2019, 12:02 am I will tinker with these ideas and implement it because my current code is a waste of resources; it is pinging to Google after the connection is established which is unnecessary.
Yep, it indeed seems more or less useless.
And beside this, note that there is a small mistake in the posted code: the [!SetVariable LoadingText ] bang of the IfAboveAction option of the [MeasurePing] measure doesn't work, when you load / refresh the skin, you get a !SetVariable: Incorrect number of arguments (....ini) error message in the log. This because when using the !SetVariable bang, you have to specify the value which you want to set to the variable. You can't simply leave empty the second parameter of the bang. If you want to set the variable empty, quotation mark is needed: [!SetVariable LoadingText ""]. These quotation marks tell the bang to set the variable empty.
User avatar
makeitrain
Posts: 11
Joined: October 24th, 2019, 1:10 am

Re: How to hide text or skin until internet connection is established?

Post by makeitrain »

balala wrote: October 25th, 2019, 3:48 pm Yep, it indeed seems more or less useless.
And beside this, note that there is a small mistake in the posted code: the [!SetVariable LoadingText ] bang of the IfAboveAction option of the [MeasurePing] measure doesn't work, when you load / refresh the skin, you get a !SetVariable: Incorrect number of arguments (....ini) error message in the log.
It's actually an alt-255 character; hence it appears empty. Although using some inverted commas could be useful too! Thank you again.
User avatar
makeitrain
Posts: 11
Joined: October 24th, 2019, 1:10 am

Re: How to hide text or skin until internet connection is established?

Post by makeitrain »

jsmorley wrote: October 24th, 2019, 12:50 pm This will detect if you are connected to the internet:

Code: Select all

[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
UpdateDivider=5
DynamicVariables=1
IfCondition=MeasureInternet = 1
IfTrueAction=[!ShowFade]
IfFalseAction=[!Hide]
There's a question about this if I may; how does SysInfoType=INTERNET_CONNECTIVITY detect internet connection? Is it similar to ping? Many thanks :)
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to hide text or skin until internet connection is established?

Post by jsmorley »

makeitrain wrote: October 26th, 2019, 3:15 am There's a question about this if I may; how does SysInfoType=INTERNET_CONNECTIVITY detect internet connection? Is it similar to ping? Many thanks :)
It uses an internal Windows "Network Aware" API, which is what Windows uses itself to detect internet connectivity to display in the Notification Area. I think it creates a network socket to a particular service hosted by Microsoft and checks for success.
User avatar
makeitrain
Posts: 11
Joined: October 24th, 2019, 1:10 am

Re: How to hide text or skin until internet connection is established?

Post by makeitrain »

balala wrote: October 24th, 2019, 1:27 pm Yes. But if I'm not wrong, makeitrain's computer is always conneted to internet, he just wanted to hide the skin while after refresh it didn't get the data yet.
You're right. This code only shows data if there's an active internet connection.

I am saving resources by modifying my current code slightly. It's not pretty; but it works.

Code: Select all

[MeasurePing]
Measure=Plugin
Plugin=PingPlugin
DestAddress=www.google.com
UpdateRate=#RefreshForever#
DynamicVariables=1
TimeoutValue=0
IfAboveValue=1
IfAboveAction=[!SetVariable RefreshForever 999999999][!SetVariable LoadingText  ][!SetVariable FontSizeAll 10][!Redraw][!UpdateMeter *]
IfEqualValue=0
IfEqualAction=[!SetVariable RefreshForever 2][!Redraw][!UpdateMeter *]
Last edited by makeitrain on October 28th, 2019, 12:10 am, edited 1 time in total.