mvan231

Cached Display Widget

Nov 21st, 2022 (edited)
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. by mvan231
  4.  
  5. */
  6.  
  7. let localFm = FileManager.local()
  8. let cachePath = localFm.documentsDirectory()
  9. let data;
  10. let usingCachedData = false;
  11. let cache = localFm.joinPath(cachePath, "lastread")
  12.  
  13. try {
  14.   log('trying')
  15.   data = await new Request("https://pastebin.com/raw/iE1BzSpQ").loadString()
  16.   localFm.writeString(cache, data)
  17. } catch(e) {
  18.   console.log("Offline mode")
  19.     data = localFm.readString(cache);
  20.     usingCachedData = true
  21. }
  22.  
  23. let widget = new ListWidget();
  24.  
  25. widget.addText(`usingCachedData value is ${usingCachedData}`)
  26. widget.addText(`data value is: ${data}`)
  27.  
  28. Script.setWidget(widget)
  29. Script.complete()
  30. widget.presentMedium()
Advertisement
Add Comment
Please, Sign In to add comment