diff --git a/lib/core/utils/server.dart b/lib/core/utils/server.dart index d75ce381..a7d723a0 100644 --- a/lib/core/utils/server.dart +++ b/lib/core/utils/server.dart @@ -46,14 +46,16 @@ Future genClient( ServerPrivateInfo spi, { void Function(GenSSHClientStatus)? onStatus, String? privateKey, + Duration? timeout, }) async { onStatus?.call(GenSSHClientStatus.socket); late SSHSocket socket; + final duration = timeout ?? const Duration(seconds: 5); try { socket = await SSHSocket.connect( spi.ip, spi.port, - timeout: const Duration(seconds: 5), + timeout: duration, ); } catch (e) { if (spi.alterUrl == null) rethrow; @@ -62,7 +64,7 @@ Future genClient( socket = await SSHSocket.connect( ipPort.ip, ipPort.port, - timeout: const Duration(seconds: 5), + timeout: duration, ); } catch (e) { rethrow; diff --git a/lib/data/provider/server.dart b/lib/data/provider/server.dart index 55dd5f9d..72c36422 100644 --- a/lib/data/provider/server.dart +++ b/lib/data/provider/server.dart @@ -198,7 +198,10 @@ class ServerProvider extends ChangeNotifier { // Only reconnect if neccessary if (newSpi.shouldReconnect(old)) { - _servers[newSpi.id]?.client = await genClient(newSpi); + _servers[newSpi.id]?.client = await genClient( + newSpi, + timeout: _settingStore.timeoutD, + ); refreshData(spi: newSpi); } @@ -231,7 +234,10 @@ class ServerProvider extends ChangeNotifier { final time1 = DateTime.now(); try { - s.client = await genClient(spi); + s.client = await genClient( + spi, + timeout: _settingStore.timeoutD, + ); } catch (e) { _limiter.inc(sid); s.status.failedInfo = e.toString(); diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 8f702623..f54de859 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -153,4 +153,14 @@ class SettingStore extends PersistentStore { 'serverTabUseOldUI', false, ); + + /// Time out for server connect and more... + late final timeout = StoreProperty( + box, + 'timeOut', + 5, + ); + + /// Duration of [timeout] + Duration get timeoutD => Duration(seconds: timeout.fetch()); } diff --git a/lib/view/page/ssh_term.dart b/lib/view/page/ssh_term.dart index 74936811..b8d19804 100644 --- a/lib/view/page/ssh_term.dart +++ b/lib/view/page/ssh_term.dart @@ -326,6 +326,7 @@ class _SSHPageState extends State { return _write('Sending password to auth...'); } }, + timeout: _setting.timeoutD, ); _write('Connected\r\n'); _write('Terminal size: ${_terminal.viewWidth}x${_terminal.viewHeight}\r\n');