I have the following code:
let widget = await createWidget();
if (config.runsInWidget) {
Script.setWidget(widget);
widget.presentMedium();
Script.complete();
}
async function createWidget() {
let listWidget = new ListWidget();
listWidget.backgroundColor = Color.white();
let isConnected = await checkConnection();
let widgetText = listWidget.addText("You are " + (isConnected ? "connected to the Internet." : "not connected to the Internet."));
widgetText.font = Font.regularSystemFont(16);
widgetText.textColor = new Color("212529", 1.0);
widgetText.centerAlignText();
return listWidget;
}
async function checkConnection() {
/* I need help on this part! */
}
I need to find a way to check if the user is connected to the Internet. I even looked at the documentation various times, and still no luck.
Does anyone know a way to achieve this?