@@ -12,39 +12,41 @@ class HomeGeneral extends StatefulWidget {
1212
1313class _HomeGeneralState extends State <HomeGeneral > {
1414 LanMouseServer lanMouseServer = LanMouseServer .instance;
15+ String fingerprint = "" ;
1516
1617 var portController = TextEditingController ();
1718 var hostnameController = TextEditingController ();
1819
1920 @override
2021 void initState () {
2122 super .initState ();
22- loadIp ();
23+ portController.text = lanMouseServer.defaultClient.port.toString ();
24+ hostnameController.text = lanMouseServer.defaultClient.host;
25+ _refreshData ();
2326 }
2427
25- void loadIp () async {
26- hostnameController.text = lanMouseServer.host;
27- portController.text = lanMouseServer.port.toString ();
28+ void _refreshData () async {
29+ // Load Ip
2830 try {
2931 NetworkInfo network = NetworkInfo ();
3032 hostnameController.text = (await network.getWifiIP ()) ?? "127.0.0.1" ;
3133 } catch (e) {
32- print ("NetworkInfoError: $e " );
34+ showSnackbar ("NetworkInfoError: $e " );
3335 }
34- _syncHostAndPort ();
35- }
36-
37- void toggleServer (bool isRunning) async {
38- _syncHostAndPort ();
36+ // Load FingerPrint
3937 try {
40- if (! isRunning) {
41- await lanMouseServer.startServer ();
38+ String ? data = await lanMouseServer.getFingerprint ();
39+ if (data != null ) {
40+ setState (() {
41+ fingerprint = data;
42+ });
4243 } else {
43- lanMouseServer. stopServer ( );
44+ showSnackbar ( "Failed to get fingerprint" );
4445 }
4546 } catch (e) {
46- showSnackbar (e );
47+ showSnackbar ("Failed to get fingerprint: $ e " );
4748 }
49+ _syncHost ();
4850 }
4951
5052 void showSnackbar (message) {
@@ -55,9 +57,9 @@ class _HomeGeneralState extends State<HomeGeneral> {
5557 }
5658 }
5759
58- void _syncHostAndPort () {
59- lanMouseServer.host = hostnameController.text;
60- lanMouseServer.port = int .parse (portController.text);
60+ void _syncHost () {
61+ lanMouseServer.defaultClient. host = hostnameController.text;
62+ lanMouseServer.defaultClient. port = int .parse (portController.text);
6163 }
6264
6365 @override
@@ -72,17 +74,9 @@ class _HomeGeneralState extends State<HomeGeneral> {
7274 "General" ,
7375 style: Theme .of (context).textTheme.titleSmall,
7476 ),
75- ValueListenableBuilder <bool >(
76- valueListenable: lanMouseServer.isSocketRunning,
77- builder: (context, isRunning, _) {
78- return IconButton (
79- onPressed: () => toggleServer (isRunning),
80- icon: Icon (
81- Icons .lan,
82- color: isRunning ? Colors .green : null ,
83- ),
84- );
85- },
77+ IconButton (
78+ onPressed: _refreshData,
79+ icon: const Icon (Icons .refresh),
8680 ),
8781 ],
8882 ),
@@ -133,12 +127,35 @@ class _HomeGeneralState extends State<HomeGeneral> {
133127 ),
134128 const SizedBox (width: 2 ),
135129 InkWell (
136- onTap: loadIp,
137- child: const Icon (Icons .refresh),
130+ onTap: () {
131+ Clipboard .setData (
132+ ClipboardData (text: hostnameController.text),
133+ );
134+ },
135+ child: const Icon (Icons .copy),
138136 ),
139137 ],
140138 ),
141- )
139+ ),
140+ const Divider (),
141+ Padding (
142+ padding: const EdgeInsets .symmetric (horizontal: 8.0 ),
143+ child: ListTile (
144+ minVerticalPadding: 0 ,
145+ contentPadding: EdgeInsets .zero,
146+ leading: const Icon (Icons .fingerprint),
147+ title: const Text ("Certificate Fingerprint" ),
148+ subtitle: Text (
149+ fingerprint,
150+ style: Theme .of (context).textTheme.bodySmall,
151+ ),
152+ onTap: () {
153+ Clipboard .setData (ClipboardData (text: fingerprint));
154+ showSnackbar ("Fingerprint copied to clipboard" );
155+ },
156+ ),
157+ ),
158+ const SizedBox (height: 15 ),
142159 ],
143160 ),
144161 )
0 commit comments