| 1681 | |
| 1682 | #include <HTTPClient.h> |
| 1683 | void installAppStoreJS() { |
| 1684 | |
| 1685 | if (WiFi.status() != WL_CONNECTED) { wifiConnectMenu(WIFI_STA); } |
| 1686 | if (WiFi.status() != WL_CONNECTED) { |
| 1687 | displayWarning("WiFi not connected", true); |
| 1688 | return; |
| 1689 | } |
| 1690 | |
| 1691 | FS *fs; |
| 1692 | if (!getFsStorage(fs)) { |
| 1693 | log_i("Fail getting filesystem"); |
| 1694 | return; |
| 1695 | } |
| 1696 | |
| 1697 | if (!fs->exists("/BruceJS")) { |
| 1698 | if (!fs->mkdir("/BruceJS")) { |
| 1699 | displayWarning("Failed to create /BruceJS directory", true); |
| 1700 | return; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | if (!fs->exists("/BruceJS/Tools")) { |
| 1705 | if (!fs->mkdir("/BruceJS/Tools")) { |
| 1706 | displayWarning("Failed to create /BruceJS/Tools directory", true); |
| 1707 | return; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | HTTPClient http; |
| 1712 | http.begin("http://ghp.iceis.co.uk/service/appstore/"); |
| 1713 | int httpCode = http.GET(); |
| 1714 | if (httpCode != 200) { |
| 1715 | http.end(); |
| 1716 | displayWarning("Failed to download App Store", true); |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1720 | File file = fs->open("/BruceJS/Tools/App Store.js", FILE_WRITE); |
| 1721 | if (!file) { |
| 1722 | displayWarning("Failed to save App Store", true); |
| 1723 | return; |
| 1724 | } |
| 1725 | file.print(http.getString()); |
| 1726 | http.end(); |
| 1727 | file.close(); |
| 1728 | |
| 1729 | displaySuccess("App Store installed", true); |
| 1730 | displaySuccess("Goto JS Interpreter -> Tools -> App Store", true); |
| 1731 | } |
| 1732 | #endif |
no test coverage detected