11// ignore_for_file: use_build_context_synchronously
22import 'dart:async' ;
33import 'dart:io' ;
4+ import 'package:connecter/help_page.dart' ;
45import 'package:connecter/setting_page.dart' ;
56import 'package:flutter/material.dart' ;
67import 'manage_connections_page.dart' ;
78import 'manage_credentials_page.dart' ;
89import 'quick_connect_dialog.dart' ;
910import 'models/connection_model.dart' ;
11+ import 'services/setting_service.dart' ;
1012import 'services/storage_service.dart' ;
1113import 'services/ssh_service.dart' ;
1214import 'terminal_page.dart' ;
@@ -28,13 +30,25 @@ class _MainPageState extends State<MainPage> {
2830 bool _isConnecting = false ;
2931 ConnectionInfo ? _connectingConnection;
3032 bool _permissionsGranted = false ;
33+ final SettingsService _settingsService = SettingsService ();
34+ bool _isFirstRun = true ;
3135
3236 @override
3337 void initState () {
3438 super .initState ();
35- _checkAndRequestPermissions ();
39+ if (Platform .isAndroid) {
40+ _checkAndRequestPermissions ();
41+ } else {
42+ setState (() {
43+ _permissionsGranted = true ;
44+ });
45+ _loadRecentConnections ();
46+ _checkFirstRun ();
47+ }
3648 }
3749
50+
51+
3852 Future <void > _checkAndRequestPermissions () async {
3953 final storageStatus = await Permission .storage.status;
4054 final storageStatusHigh = await Permission .manageExternalStorage.status;
@@ -121,6 +135,68 @@ class _MainPageState extends State<MainPage> {
121135 exit (0 );
122136 }
123137
138+ Future <void > _checkFirstRun () async {
139+ final settings = await _settingsService.getSettings ();
140+ setState (() {
141+ _isFirstRun = settings.isFirstRun;
142+ });
143+
144+ if (_isFirstRun) {
145+ _showWelcome ();
146+ _settingsService.markAsNotFirstRun ();
147+ }
148+ }
149+
150+
151+
152+ void _showWelcome () {
153+ WidgetsBinding .instance.addPostFrameCallback ((_) {
154+ showDialog (
155+ context: context,
156+ barrierDismissible: false ,
157+ builder: (context) => AlertDialog (
158+ title: const Text ('欢迎使用Connecter' ),
159+ content: Column (
160+ mainAxisSize: MainAxisSize .min,
161+ crossAxisAlignment: CrossAxisAlignment .start,
162+ children: [
163+ const Text ('看起来您是第一次使用该应用' ),
164+ const SizedBox (height: 8 ),
165+ MouseRegion (
166+ cursor: SystemMouseCursors .click,
167+ child: GestureDetector (
168+ onTap: _showHelp,
169+ child: const Text (
170+ '点击查看帮助' ,
171+ style: TextStyle (
172+ color: Colors .blueAccent,
173+ ),
174+ ),
175+ ),
176+ ),
177+ ],
178+ ),
179+ actions: [
180+ TextButton (
181+ onPressed: () => Navigator .of (context).pop (),
182+ child: const Text ('关闭' ),
183+ ),
184+ ],
185+ ),
186+ );
187+ });
188+ }
189+
190+ void _showHelp () {
191+
192+ Navigator .of (context).push (
193+ MaterialPageRoute (
194+ builder: (context) => const HelpPage (),
195+ ),
196+ );
197+ }
198+
199+
124200 Future <void > _loadRecentConnections () async {
125201 try {
126202 final recentConnections = await _storageService.getRecentConnections ();
@@ -710,9 +786,9 @@ Future<void> _performConnection(ConnectionInfo connection) async {
710786 );
711787
712788 await sshService.connect (connection, credential)
713- .timeout (const Duration (seconds: 3 ), onTimeout: () {
714- throw TimeoutException ('连接超时,请检查网络或主机是否可达' );
715- });
789+ .timeout (const Duration (seconds: 3 ),); // onTimeout: () {
790+ // throw TimeoutException('连接超时,请检查网络或主机是否可达');
791+ // });
716792
717793 // 添加到最近连接(不等待完成),不然巨卡无比
718794 unawaited (storageService.addRecentConnection (connection));
@@ -766,12 +842,14 @@ void _handleConnectionError(ConnectionInfo connection, String error) {
766842 );
767843}
768844
845+
769846 List <Widget > _buildButtons (
770847 BuildContext context,
771848 bool showSubtitle,
772849 double screenHeight,
773850 ) {
774- const double buttonHeight = 100 ;
851+ // 根据屏幕高度动态计算按钮高度
852+ final double buttonHeight = screenHeight >= 500 ? 100 : 80 ;
775853
776854 Widget buildButton ({
777855 required VoidCallback onPressed,
@@ -787,16 +865,16 @@ void _handleConnectionError(ConnectionInfo connection, String error) {
787865 children: [
788866 Text (
789867 title,
790- style: const TextStyle (
791- fontSize: 18 ,
868+ style: TextStyle (
869+ fontSize: screenHeight >= 500 ? 18 : 16 , // 根据高度调整字体大小
792870 fontWeight: FontWeight .bold,
793871 ),
794872 ),
795873 const SizedBox (height: 4 ),
796874 Text (
797875 subtitle,
798- style: const TextStyle (
799- fontSize: 14 ,
876+ style: TextStyle (
877+ fontSize: screenHeight >= 500 ? 14 : 12 , // 根据高度调整字体大小
800878 color: Colors .grey,
801879 ),
802880 ),
@@ -807,20 +885,20 @@ void _handleConnectionError(ConnectionInfo connection, String error) {
807885 padding: const EdgeInsets .only (left: 8.0 ),
808886 child: Text (
809887 title,
810- style: const TextStyle (
811- fontSize: 18 ,
888+ style: TextStyle (
889+ fontSize: screenHeight >= 500 ? 18 : 16 , // 根据高度调整字体大小
812890 fontWeight: FontWeight .bold,
813891 ),
814892 ),
815893 );
816894
817895 return SizedBox (
818896 width: double .infinity,
819- height: buttonHeight,
897+ height: buttonHeight, // 使用动态计算的高度
820898 child: OutlinedButton (
821899 onPressed: onPressed,
822900 style: OutlinedButton .styleFrom (
823- padding: const EdgeInsets .all (14 ),
901+ padding: EdgeInsets .all (screenHeight >= 500 ? 14 : 12 ), // 根据高度调整内边距
824902 shape: RoundedRectangleBorder (
825903 borderRadius: BorderRadius .circular (12 ),
826904 ),
@@ -846,7 +924,6 @@ void _handleConnectionError(ConnectionInfo connection, String error) {
846924 },
847925 title: '快速连接' ,
848926 subtitle: '输入地址和凭证快速建立连接' ,
849-
850927 ),
851928 const SizedBox (height: 16 ),
852929
@@ -875,17 +952,16 @@ void _handleConnectionError(ConnectionInfo connection, String error) {
875952 ),
876953 );
877954 },
878-
879955 title: '管理认证凭证' ,
880956 subtitle: '管理密码和证书凭证' ,
881957 ),
882958 const SizedBox (height: 16 ),
883959 buildButton (
884960 onPressed: () {
885- Navigator .push (
886- context,
887- MaterialPageRoute (builder: (context) => const SettingsPage ()),
888- );
961+ Navigator .push (
962+ context,
963+ MaterialPageRoute (builder: (context) => const SettingsPage ()),
964+ );
889965 },
890966 title: "设置" ,
891967 subtitle: "查看设置、使用说明和版本信息" ,
0 commit comments