diff --git a/lib/core/utils/platform/base.dart b/lib/core/utils/platform/base.dart index 5513fc2b..73a4b988 100644 --- a/lib/core/utils/platform/base.dart +++ b/lib/core/utils/platform/base.dart @@ -79,10 +79,6 @@ bool get isLinux => OS.type == OS.linux; bool get isMacOS => OS.type == OS.macos; bool get isWindows => OS.type == OS.windows; bool get isWeb => OS.type == OS.web; -bool get isMobile => - OS.type == OS.ios || - OS.type == OS.android; +bool get isMobile => OS.type == OS.ios || OS.type == OS.android; bool get isDesktop => - OS.type == OS.linux || - OS.type == OS.macos || - OS.type == OS.windows; + OS.type == OS.linux || OS.type == OS.macos || OS.type == OS.windows; diff --git a/lib/data/provider/server.dart b/lib/data/provider/server.dart index 5a4af49b..57a4bb56 100644 --- a/lib/data/provider/server.dart +++ b/lib/data/provider/server.dart @@ -104,7 +104,15 @@ class ServerProvider extends ChangeNotifier { if (s.state != ServerState.failed) return; _limiter.reset(s.spi.id); } - if (!(s.spi.autoConnect ?? true)) return; + /// If [spi.autoConnect] is false and server is disconnected, then skip. + /// + /// If [spi.autoConnect] is false and server is connected, then refresh. + /// If no this, the server will only refresh once by clicking refresh button. + /// + /// If [spi.autoConnect] is true, then refresh. + if (!(s.spi.autoConnect ?? true) && s.state == ServerState.disconnected) { + return; + } return await _getData(s.spi); })); } diff --git a/lib/view/widget/url_text.dart b/lib/view/widget/url_text.dart index ab543495..724eb13a 100644 --- a/lib/view/widget/url_text.dart +++ b/lib/view/widget/url_text.dart @@ -7,8 +7,6 @@ import '../../core/utils/ui.dart'; final _reg = RegExp( r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*"); -const _textStyle = TextStyle(); - class UrlText extends StatelessWidget { final String text; final String? replace; @@ -20,60 +18,41 @@ class UrlText extends StatelessWidget { required this.text, this.replace, this.textAlign, - this.style = _textStyle, + this.style = const TextStyle(), }) : super(key: key); - List getTextSpans(Color c) { + List _buildTextSpans(Color c) { final widgets = []; - Iterable matches = _reg.allMatches(text); - List<_ResultMatch> resultMatches = <_ResultMatch>[]; int start = 0; - for (Match match in matches) { + for (final match in _reg.allMatches(text)) { final group0 = match.group(0); if (group0 != null && group0.isNotEmpty) { if (start != match.start) { - _ResultMatch result1 = _ResultMatch( - false, - text.substring(start, match.start), + widgets.add( + TextSpan( + text: text.substring(start, match.start), + style: style.copyWith(color: c), + ), ); - resultMatches.add(result1); } - _ResultMatch result2 = _ResultMatch( - true, - match.group(0)!, - ); - resultMatches.add(result2); + widgets.add(_LinkTextSpan( + replace: replace, + text: group0, + style: style.copyWith(color: primaryColor), + )); start = match.end; } } if (start < text.length) { - _ResultMatch result1 = _ResultMatch( - false, - text.substring(start), + widgets.add( + TextSpan( + text: text.substring(start), + style: style.copyWith(color: c), + ), ); - resultMatches.add(result1); - } - - for (var result in resultMatches) { - if (result.isUrl) { - widgets.add( - _LinkTextSpan( - replace: replace ?? result.text, - text: result.text, - style: style.copyWith(color: primaryColor), - ), - ); - } else { - widgets.add( - TextSpan( - text: result.text, - style: style.copyWith(color: c), - ), - ); - } } return widgets; } @@ -83,7 +62,7 @@ class UrlText extends StatelessWidget { return RichText( textAlign: textAlign ?? TextAlign.start, text: TextSpan( - children: getTextSpans(DynamicColors.content.resolve(context)), + children: _buildTextSpans(DynamicColors.content.resolve(context)), ), ); } @@ -93,17 +72,10 @@ class _LinkTextSpan extends TextSpan { _LinkTextSpan({TextStyle? style, required String text, String? replace}) : super( style: style, - text: replace, + text: replace ?? text, recognizer: TapGestureRecognizer() ..onTap = () { openUrl(text); }, ); } - -class _ResultMatch { - final bool isUrl; - final String text; - - _ResultMatch(this.isUrl, this.text); -}