Skip to content

Scheduled task to refresh Cloudflare WARP auto-connect timeout

Notifications You must be signed in to change notification settings

dsaidgovsg/warp-refresh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

WARP Refresh

Contains scheduled task to refresh Cloudflare WARP auto-connect timeout.

Currently Windows only, since the warp-refresh.vbs is written in VBScript to be run as a Windows Scheduled Task. (MacOS users are welcome to try converting the script and re-purposing it into a similarly runnable package.)

If you are a developer on Windows dev machine with Cloudflare WARP installed, and somewhat bothered by occasional interruptions to video calls, or strange TLS cert error without realizing WARP reconnected, or having to disconnect WARP every now and then, this might be for you.

How to use

Download warp-refresh.vbs into %UserProfile%\Documents\warp-refresh.vbs, and run the following in cmd:

schtasks /Create /SC minute /MO 5 /TN "WARP auto-connect refresh" /TR "WScript.exe \"%UserProfile%\Documents\warp-refresh.vbs\""

Note that the task is designated to run with your current user and does not require escalated privileges. You may choose to change the file path to download into, but remember to change argument value for /TR.

If you change your mind after adding as a scheduled task, you may delete the task by running:

schtasks /Delete /TN "WARP auto-connect refresh" /F

cmd-only way to install quickly

WIN+R and run cmd. Enter the following:

:: Downloads the .vbs file into designated file path
:: NOTE: this line is to be directly run in cmd (to run powershell on behalf for convenience), and not directly in powershell
powershell -c "Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/dsaidgovsg/warp-refresh/main/warp-refresh.vbs' -OutFile '%UserProfile%\\Documents\\warp-refresh.vbs'

:: Installs and runs script as a scheduled task
schtasks /Create /SC minute /MO 5 /TN "WARP auto-connect refresh" /TR "WScript.exe \"%UserProfile%\Documents\warp-refresh.vbs\""

How the script works

The script assumes WARP is installed, which exposes warp-cli in cmd. The script also assumes to be run periodically (minimally every 5 mins), and requires the user to have first manually disconnected the WARP (i.e. slider in the WARP tray icon turned off).

It extracts the auto-connect timeout value (starts with 3 hours / 10800 seconds), and once the value drops below a certain threshold, it runs the connect command (equivalent to the slider in WARP tray icon turning on), and immediately runs disconnect command again (equivalent to the slider in WARP tray icon turning off). The effect of this resets the auto-connect timeout back to 10800 seconds.

Iinstead of printing to stdout, log echos are written to warp-refresh.log in the same directory to where the script resides (the log filename also changes to whatever the script filename is). This is because VBScript does not support printing to stdout. The logs are kept to a max of 100 lines to prevent any possibility of causing storage space to run out.

Again, the user is expected to first manually disconnect the WARP when the OS starts up, if one chooses to do so, since the script is intended to only have effect in this state, and not effect any changes should the user prefers the WARP to stay connected.

While this is not 100% foolproof to prevent your video streams from cutting off in the process of connect/disconnect, empirically this seems to work well.

As part of the AIPF/DSAID ethos, the .vbs script was mostly prompted and generated by Copilot :)

Why .vbs?

.vbs was chosen because it can be directly run as a scheduled task. While .bat file can also work, it will cause a cmd window to pop up and disappear every time it triggers, which is annoying.

Importantly, this also prevents any focus loss to the current working window, otherwise we would just be transferring the annoyance of having to manually disconnect WARP, to that of having to deal with the popup window and the loss of window focus.

About

Scheduled task to refresh Cloudflare WARP auto-connect timeout

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published