-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
291 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
use std::fs; | ||
use std::process::Command; | ||
|
||
fn main() { | ||
// ensure that the directory exists which needs to be embedded in our binary | ||
let directory_path = "./frontend/build/web"; | ||
if fs::create_dir_all(directory_path).is_err() { | ||
std::process::exit(1); | ||
} | ||
|
||
let output = Command::new("git") | ||
.args(["rev-parse", "HEAD"]) | ||
.output() | ||
.expect("To be able to get commit hash"); | ||
let git_hash = String::from_utf8(output.stdout).expect("To be a valid string"); | ||
let output = Command::new("git") | ||
.args(["rev-parse", "--abbrev-ref", "HEAD"]) | ||
.output() | ||
.expect("To be able to get branch name"); | ||
let branch_name = String::from_utf8(output.stdout).expect("To be a valid string"); | ||
println!("cargo:rustc-env=COMMIT_HASH={}", git_hash); | ||
println!("cargo:rustc-env=BRANCH_NAME={}", branch_name); | ||
} |
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
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,172 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:get_10101/common/color.dart'; | ||
import 'package:get_10101/common/snack_bar.dart'; | ||
import 'package:get_10101/common/version_service.dart'; | ||
import 'package:get_10101/logger/logger.dart'; | ||
import 'package:get_10101/settings/settings_service.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class AppInfoScreen extends StatefulWidget { | ||
const AppInfoScreen({super.key}); | ||
|
||
@override | ||
State<AppInfoScreen> createState() => _AppInfoScreenState(); | ||
} | ||
|
||
class _AppInfoScreenState extends State<AppInfoScreen> { | ||
EdgeInsets margin = const EdgeInsets.all(10); | ||
|
||
String _version = ""; | ||
String _nodeId = ""; | ||
String _commit = "not available"; | ||
String _branch = "not available"; | ||
|
||
@override | ||
void initState() { | ||
try { | ||
// todo: fetch node id from backend. | ||
var nodeId = "unknown"; // rust.api.getNodeId(); | ||
_nodeId = nodeId; | ||
} catch (e) { | ||
logger.e("Error getting node id: $e"); | ||
_nodeId = "UNKNOWN"; | ||
} | ||
|
||
_nodeId = "03e637498b08254711199fc9ca0b0ae557cf279711ed7c827d48ba01bda146b0c9"; | ||
|
||
Future.wait<dynamic>([ | ||
context.read<VersionService>().fetchVersion(), | ||
context.read<SettingsService>().getNodeId() | ||
]).then((value) { | ||
final version = value[0]; | ||
final nodeId = value[1]; | ||
|
||
setState(() { | ||
_commit = version.commitHash; | ||
_branch = version.branch; | ||
_version = version.version; | ||
_nodeId = "03e637498b08254711199fc9ca0b0ae557cf279711ed7c827d48ba01bda146b0c9"; | ||
}); | ||
}); | ||
|
||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Container( | ||
padding: const EdgeInsets.only(top: 20, left: 10, right: 10), | ||
child: Column( | ||
children: [ | ||
Column( | ||
children: [ | ||
Container( | ||
margin: const EdgeInsets.only(top: 20, left: 10, right: 10, bottom: 10), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const Text( | ||
"NODE INFO", | ||
style: TextStyle(color: Colors.grey, fontSize: 17), | ||
), | ||
const SizedBox( | ||
height: 10, | ||
), | ||
Container( | ||
decoration: BoxDecoration( | ||
color: Colors.white, borderRadius: BorderRadius.circular(15)), | ||
child: moreInfo(context, | ||
title: "Node Id", info: _nodeId, showCopyButton: true)) | ||
], | ||
), | ||
), | ||
Container( | ||
margin: const EdgeInsets.all(10), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const Text( | ||
"BUILD INFO", | ||
style: TextStyle(color: Colors.grey, fontSize: 18), | ||
), | ||
const SizedBox( | ||
height: 10, | ||
), | ||
Container( | ||
decoration: BoxDecoration( | ||
color: Colors.white, borderRadius: BorderRadius.circular(15)), | ||
child: Column( | ||
children: [ | ||
moreInfo(context, title: "Version", info: _version), | ||
moreInfo(context, | ||
title: "Commit Hash", info: _commit, showCopyButton: true), | ||
moreInfo(context, | ||
title: "Branch", info: _branch, showCopyButton: kDebugMode) | ||
], | ||
)) | ||
], | ||
), | ||
), | ||
], | ||
), | ||
const SizedBox(height: 10) | ||
], | ||
)), | ||
); | ||
} | ||
} | ||
|
||
Widget moreInfo(BuildContext context, | ||
{required String title, required String info, bool showCopyButton = false}) { | ||
return Container( | ||
padding: const EdgeInsets.all(15), | ||
child: Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
title, | ||
style: | ||
const TextStyle(fontSize: 17, fontWeight: FontWeight.w400, color: Colors.black), | ||
), | ||
const SizedBox(height: 7), | ||
showCopyButton | ||
? SizedBox( | ||
width: 400, | ||
child: Text( | ||
info, | ||
softWrap: true, | ||
maxLines: 4, | ||
style: TextStyle( | ||
fontSize: 18, fontWeight: FontWeight.w300, color: Colors.grey.shade700), | ||
)) | ||
: const SizedBox() | ||
], | ||
), | ||
showCopyButton | ||
? GestureDetector( | ||
onTap: () async { | ||
showSnackBar(ScaffoldMessenger.of(context), "Copied $info"); | ||
await Clipboard.setData(ClipboardData(text: info)); | ||
}, | ||
child: Icon( | ||
Icons.copy, | ||
size: 17, | ||
color: tenTenOnePurple.shade800, | ||
), | ||
) | ||
: Text( | ||
info, | ||
style: TextStyle( | ||
fontSize: 18, fontWeight: FontWeight.w300, color: Colors.grey.shade700), | ||
) | ||
], | ||
), | ||
); | ||
} |
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,23 @@ | ||
import 'package:http/http.dart' as http; | ||
|
||
class SettingsService { | ||
const SettingsService(); | ||
|
||
Future<String> getNodeId() async { | ||
// TODO(holzeis): this should come from the config | ||
const port = "3001"; | ||
const host = "localhost"; | ||
|
||
try { | ||
final response = await http.get(Uri.http('$host:$port', '/api/node')); | ||
|
||
if (response.statusCode == 200) { | ||
return response.body; | ||
} else { | ||
return "unknown"; | ||
} | ||
} catch (e) { | ||
return "unknown"; | ||
} | ||
} | ||
} |
Oops, something went wrong.