-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-version
- Loading branch information
Showing
3 changed files
with
362 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:http/http.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
import 'package:elastic_dashboard/services/nt_connection.dart'; | ||
import 'package:elastic_dashboard/services/settings.dart'; | ||
|
||
typedef LayoutDownloadResponse = ({bool successful, String data}); | ||
|
||
class ElasticLayoutDownloader { | ||
final Client client = Client(); | ||
|
||
Future<LayoutDownloadResponse> downloadLayout({ | ||
required NTConnection ntConnection, | ||
required SharedPreferences preferences, | ||
}) async { | ||
if (!ntConnection.isNT4Connected) { | ||
return ( | ||
successful: false, | ||
data: | ||
'Cannot download a remote layout while disconnected from the robot.' | ||
); | ||
} | ||
String robotIP = | ||
preferences.getString(PrefKeys.ipAddress) ?? Defaults.ipAddress; | ||
Uri robotUri = Uri.parse( | ||
'http://$robotIP:5800/elastic-layout.json', | ||
); | ||
Response response; | ||
try { | ||
response = await client.get(robotUri); | ||
} on ClientException catch (e) { | ||
return (successful: false, data: e.message); | ||
} | ||
if (response.statusCode < 200 || response.statusCode >= 300) { | ||
String errorMessage = switch (response.statusCode) { | ||
404 => | ||
'File "elastic-layout.json" was not found, ensure that you have deployed a file named "elastic_layout.json" in the deploy directory', | ||
_ => 'Request returned status code ${response.statusCode}', | ||
}; | ||
|
||
return (successful: false, data: errorMessage); | ||
} | ||
return (successful: true, data: response.body); | ||
} | ||
} |
Oops, something went wrong.