Skip to content

Commit c2c6c57

Browse files
committed
Format and update dartssh2
1 parent 4678daa commit c2c6c57

100 files changed

Lines changed: 2281 additions & 902 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/app.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ class _MyAppState extends State<MyApp> {
109109
);
110110
}
111111

112-
Widget _buildApp(BuildContext ctx, {required ThemeData light, required ThemeData dark}) {
112+
Widget _buildApp(
113+
BuildContext ctx, {
114+
required ThemeData light,
115+
required ThemeData dark,
116+
}) {
113117
final tMode = Stores.setting.themeMode.fetch();
114118
// Issue #57
115119
final themeMode = switch (tMode) {
@@ -124,7 +128,10 @@ class _MyAppState extends State<MyApp> {
124128
navigatorKey: AppNavigator.key,
125129
builder: ResponsivePoints.builder,
126130
locale: locale,
127-
localizationsDelegates: const [LibLocalizations.delegate, ...AppLocalizations.localizationsDelegates],
131+
localizationsDelegates: const [
132+
LibLocalizations.delegate,
133+
...AppLocalizations.localizationsDelegates,
134+
],
128135
supportedLocales: AppLocalizations.supportedLocales,
129136
localeListResolutionCallback: LocaleUtil.resolve,
130137
navigatorObservers: [AppRouteObserver.instance],
@@ -142,7 +149,9 @@ class _MyAppState extends State<MyApp> {
142149
Widget child;
143150
var hasWindowFrame = false;
144151
if (snapshot.connectionState == ConnectionState.waiting) {
145-
child = const Scaffold(body: Center(child: CircularProgressIndicator()));
152+
child = const Scaffold(
153+
body: Center(child: CircularProgressIndicator()),
154+
);
146155
} else {
147156
final intros = snapshot.data ?? [];
148157
if (intros.isNotEmpty) {

lib/core/chan.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ abstract final class MethodChans {
4747
final res = await _channel.invokeMethod('isServiceRunning');
4848
return res == true;
4949
} catch (e, s) {
50-
Loggers.app.warning('Failed to check if Android service is running', e, s);
50+
Loggers.app.warning(
51+
'Failed to check if Android service is running',
52+
e,
53+
s,
54+
);
5155
return false;
5256
}
5357
}
@@ -84,10 +88,13 @@ abstract final class MethodChans {
8488
}
8589

8690
/// Register a handler for native -> Flutter callbacks.
87-
/// Currently handles:
91+
/// Currently handles:
8892
/// - `disconnectSession` with argument map {id: string}
8993
/// - `stopAllConnections` with no arguments
90-
static void registerHandler(Future<void> Function(String id) onDisconnect, [VoidCallback? onStopAll]) {
94+
static void registerHandler(
95+
Future<void> Function(String id) onDisconnect, [
96+
VoidCallback? onStopAll,
97+
]) {
9198
_channel.setMethodCallHandler((call) async {
9299
switch (call.method) {
93100
case 'disconnectSession':

lib/core/extension/server.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ import 'package:server_box/data/res/store.dart';
77

88
extension LogoExt on ServerState {
99
String? getLogoUrl(BuildContext context) {
10-
var logoUrl = spi.custom?.logoUrl ?? Stores.setting.serverLogoUrl.fetch().selfNotEmptyOrNull;
10+
var logoUrl =
11+
spi.custom?.logoUrl ??
12+
Stores.setting.serverLogoUrl.fetch().selfNotEmptyOrNull;
1113
if (logoUrl == null) {
1214
return null;
1315
}
1416
final dist = status.more[StatusCmdType.sys]?.dist;
1517
if (dist != null) {
1618
logoUrl = logoUrl.replaceFirst('{DIST}', dist.name);
1719
}
18-
logoUrl = logoUrl.replaceFirst('{BRIGHT}', context.isDark ? 'dark' : 'light');
20+
logoUrl = logoUrl.replaceFirst(
21+
'{BRIGHT}',
22+
context.isDark ? 'dark' : 'light',
23+
);
1924
return logoUrl;
2025
}
2126
}

lib/core/extension/ssh_client.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ extension SSHClientX on SSHClient {
7575
final session = await execute(
7676
entry ??
7777
switch (systemType) {
78-
SystemType.windows => 'powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass',
78+
SystemType.windows =>
79+
'powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass',
7980
_ => 'cat | sh',
8081
},
8182
pty: pty,

lib/core/service/ssh_discovery.dart

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import 'package:server_box/data/model/server/discovery_result.dart';
99
class SshDiscoveryService {
1010
static const _sshPort = 22;
1111

12-
static Future<SshDiscoveryReport> discover([SshDiscoveryConfig config = const SshDiscoveryConfig()]) async {
12+
static Future<SshDiscoveryReport> discover([
13+
SshDiscoveryConfig config = const SshDiscoveryConfig(),
14+
]) async {
1315
final t0 = DateTime.now();
1416
final candidates = <InternetAddress>{};
1517

@@ -32,7 +34,11 @@ class SshDiscoveryService {
3234

3335
// Filter out unwanted addresses: loopback, link-local, 0.0.0.0, broadcast, multicast
3436
candidates.removeWhere(
35-
(a) => a.isLoopback || a.isLinkLocal || a.address == '0.0.0.0' || _isBroadcastOrMulticast(a),
37+
(a) =>
38+
a.isLoopback ||
39+
a.isLinkLocal ||
40+
a.address == '0.0.0.0' ||
41+
_isBroadcastOrMulticast(a),
3642
);
3743

3844
// 4) Concurrent SSH port scanning
@@ -45,7 +51,13 @@ class SshDiscoveryService {
4551
results.sort((a, b) => a.addr.address.compareTo(b.addr.address));
4652

4753
final discoveryResults = results
48-
.map((r) => SshDiscoveryResult(ip: r.addr.address, port: _sshPort, banner: r.banner?.trim()))
54+
.map(
55+
(r) => SshDiscoveryResult(
56+
ip: r.addr.address,
57+
port: _sshPort,
58+
banner: r.banner?.trim(),
59+
),
60+
)
4961
.toList();
5062

5163
return SshDiscoveryReport(
@@ -56,7 +68,11 @@ class SshDiscoveryService {
5668
);
5769
}
5870

59-
static Future<String?> _run(String exe, List<String> args, {Duration? timeout}) async {
71+
static Future<String?> _run(
72+
String exe,
73+
List<String> args, {
74+
Duration? timeout,
75+
}) async {
6076
try {
6177
final p = await Process.start(exe, args, runInShell: false);
6278
final out = await p.stdout
@@ -75,7 +91,11 @@ class SshDiscoveryService {
7591
if (out.trim().isNotEmpty) return out;
7692
return null;
7793
} catch (e, s) {
78-
Loggers.app.warning('Failed to run command: $exe ${args.join(' ')}', e, s);
94+
Loggers.app.warning(
95+
'Failed to run command: $exe ${args.join(' ')}',
96+
e,
97+
s,
98+
);
7999
return null;
80100
}
81101
}
@@ -92,7 +112,8 @@ class SshDiscoveryService {
92112
final tok = line.split(RegExp(r'\s+'));
93113
if (tok.isNotEmpty) {
94114
final ip = tok[0];
95-
if (InternetAddress.tryParse(ip)?.type == InternetAddressType.IPv4) {
115+
if (InternetAddress.tryParse(ip)?.type ==
116+
InternetAddressType.IPv4) {
96117
set.add(InternetAddress(ip));
97118
}
98119
}
@@ -126,7 +147,8 @@ class SshDiscoveryService {
126147
if (s != null) {
127148
for (final line in const LineSplitter().convert(s)) {
128149
final ip = line.split(RegExp(r'\s+')).firstOrNull;
129-
if (ip != null && InternetAddress.tryParse(ip)?.type == InternetAddressType.IPv6) {
150+
if (ip != null &&
151+
InternetAddress.tryParse(ip)?.type == InternetAddressType.IPv6) {
130152
set.add(InternetAddress(ip));
131153
}
132154
}
@@ -136,7 +158,8 @@ class SshDiscoveryService {
136158
if (s != null) {
137159
for (final line in const LineSplitter().convert(s)) {
138160
final ip = line.trim().split(RegExp(r'\s+')).firstOrNull;
139-
if (ip != null && InternetAddress.tryParse(ip)?.type == InternetAddressType.IPv6) {
161+
if (ip != null &&
162+
InternetAddress.tryParse(ip)?.type == InternetAddressType.IPv6) {
140163
set.add(InternetAddress(ip));
141164
}
142165
}
@@ -148,10 +171,19 @@ class SshDiscoveryService {
148171
static Future<List<_Cidr>> _localIPv4Cidrs() async {
149172
final res = <_Cidr>[];
150173
if (_isLinux) {
151-
final s = await _run('ip', ['-o', '-4', 'addr', 'show', 'scope', 'global']);
174+
final s = await _run('ip', [
175+
'-o',
176+
'-4',
177+
'addr',
178+
'show',
179+
'scope',
180+
'global',
181+
]);
152182
if (s != null) {
153183
for (final line in const LineSplitter().convert(s)) {
154-
final m = RegExp(r'inet\s+(\d+\.\d+\.\d+\.\d+)\/(\d+)').firstMatch(line);
184+
final m = RegExp(
185+
r'inet\s+(\d+\.\d+\.\d+\.\d+)\/(\d+)',
186+
).firstMatch(line);
155187
if (m != null) {
156188
final ip = InternetAddress(m.group(1)!);
157189
final prefix = int.parse(m.group(2)!);
@@ -177,7 +209,9 @@ class SshDiscoveryService {
177209
r'inet\s+(\d+\.\d+\.\d+\.\d+)\s+netmask\s+0x([0-9a-fA-F]+)(?:\s+broadcast\s+(\d+\.\d+\.\d+\.\d+))?',
178210
).firstMatch(line);
179211
if (ipm == null) {
180-
Loggers.app.warning('[ssh_discovery] Warning: Unexpected ifconfig line format: $line');
212+
Loggers.app.warning(
213+
'[ssh_discovery] Warning: Unexpected ifconfig line format: $line',
214+
);
181215
continue;
182216
}
183217
final ip = InternetAddress(ipm.group(1)!);
@@ -187,10 +221,14 @@ class SshDiscoveryService {
187221
final mask = InternetAddress(dotted);
188222
final prefix = _maskToPrefix(mask.address);
189223
final net = _networkAddress(ip, mask);
190-
final brd = InternetAddress(ipm.group(3) ?? _broadcastAddress(ip, mask).address);
224+
final brd = InternetAddress(
225+
ipm.group(3) ?? _broadcastAddress(ip, mask).address,
226+
);
191227
res.add(_Cidr(ip, prefix, mask, net, brd));
192228
} catch (e) {
193-
Loggers.app.warning('[ssh_discovery] Error parsing ifconfig output: $e, line: $line');
229+
Loggers.app.warning(
230+
'[ssh_discovery] Error parsing ifconfig output: $e, line: $line',
231+
);
194232
continue;
195233
}
196234
}
@@ -219,7 +257,10 @@ class SshDiscoveryService {
219257
final set = <InternetAddress>{};
220258
if (_isMac) {
221259
try {
222-
final proc = await Process.start('/usr/bin/dns-sd', ['-B', '_ssh._tcp']);
260+
final proc = await Process.start('/usr/bin/dns-sd', [
261+
'-B',
262+
'_ssh._tcp',
263+
]);
223264
final lines = <String>[];
224265
final subscription = proc.stdout
225266
.transform(utf8.decoder)
@@ -250,7 +291,11 @@ class SshDiscoveryService {
250291
}
251292
}
252293
} catch (e, s) {
253-
Loggers.app.warning('Failed to discover mDNS SSH candidates on macOS', e, s);
294+
Loggers.app.warning(
295+
'Failed to discover mDNS SSH candidates on macOS',
296+
e,
297+
s,
298+
);
254299
}
255300
} else if (_isLinux) {
256301
final s = await _run('/usr/bin/avahi-browse', ['-rat', '_ssh._tcp']);
@@ -316,7 +361,11 @@ class _Scanner {
316361
Socket? socket;
317362
StreamSubscription? sub;
318363
try {
319-
socket = await Socket.connect(ip, SshDiscoveryService._sshPort, timeout: timeout);
364+
socket = await Socket.connect(
365+
ip,
366+
SshDiscoveryService._sshPort,
367+
timeout: timeout,
368+
);
320369
socket.timeout(timeout);
321370
final c = Completer<String?>();
322371
sub = socket.listen(
@@ -370,7 +419,8 @@ class _Semaphore {
370419
}
371420
}
372421

373-
Future<T> _guarded<T>(_Semaphore sem, Future<T> Function() fn) => sem.withPermit(fn);
422+
Future<T> _guarded<T>(_Semaphore sem, Future<T> Function() fn) =>
423+
sem.withPermit(fn);
374424

375425
// IPv4 utilities
376426

@@ -379,7 +429,8 @@ int _ipv4ToInt(String ip) {
379429
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
380430
}
381431

382-
String _intToIPv4(int v) => '${(v >> 24) & 0xff}.${(v >> 16) & 0xff}.${(v >> 8) & 0xff}.${v & 0xff}';
432+
String _intToIPv4(int v) =>
433+
'${(v >> 24) & 0xff}.${(v >> 16) & 0xff}.${(v >> 8) & 0xff}.${v & 0xff}';
383434

384435
InternetAddress _prefixToMask(int prefix) {
385436
final mask = prefix == 0 ? 0 : 0xffffffff << (32 - prefix);

lib/core/utils/comparator.dart

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ class ChainComparator<T> {
66
ChainComparator.empty() : this._create(null, (a, b) => 0);
77
ChainComparator.create() : this._create(null, (a, b) => 0);
88

9-
static ChainComparator<T> comparing<T, F extends Comparable<F>>(F Function(T) extractor) {
10-
return ChainComparator._create(null, (a, b) => extractor(a).compareTo(extractor(b)));
9+
static ChainComparator<T> comparing<T, F extends Comparable<F>>(
10+
F Function(T) extractor,
11+
) {
12+
return ChainComparator._create(
13+
null,
14+
(a, b) => extractor(a).compareTo(extractor(b)),
15+
);
1116
}
1217

1318
int compare(T a, T b) {
@@ -35,12 +40,23 @@ class ChainComparator<T> {
3540
);
3641
}
3742

38-
ChainComparator<T> thenWithComparator(Comparator<T> comparator, {bool reversed = false}) {
39-
return ChainComparator._create(this, !reversed ? comparator : (a, b) => comparator(b, a));
43+
ChainComparator<T> thenWithComparator(
44+
Comparator<T> comparator, {
45+
bool reversed = false,
46+
}) {
47+
return ChainComparator._create(
48+
this,
49+
!reversed ? comparator : (a, b) => comparator(b, a),
50+
);
4051
}
4152

42-
ChainComparator<T> thenCompareByReversed<F extends Comparable<F>>(F Function(T) extractor) {
43-
return ChainComparator._create(this, (a, b) => -extractor(a).compareTo(extractor(b)));
53+
ChainComparator<T> thenCompareByReversed<F extends Comparable<F>>(
54+
F Function(T) extractor,
55+
) {
56+
return ChainComparator._create(
57+
this,
58+
(a, b) => -extractor(a).compareTo(extractor(b)),
59+
);
4460
}
4561

4662
ChainComparator<T> thenTrueFirst(bool Function(T) f) {
@@ -56,7 +72,9 @@ class ChainComparator<T> {
5672
}
5773

5874
class Comparators {
59-
static Comparator<String> compareStringCaseInsensitive({bool uppercaseFirst = false}) {
75+
static Comparator<String> compareStringCaseInsensitive({
76+
bool uppercaseFirst = false,
77+
}) {
6078
return (String a, String b) {
6179
final r = a.toLowerCase().compareTo(b.toLowerCase());
6280
if (r != 0) return r;

lib/core/utils/host_key_helper.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Future<bool> ensureHostKeyAcceptedForSftp(BuildContext context, Spi spi) async {
1717
fn: () async {
1818
await ensureKnownHostKey(
1919
spi,
20-
onKeyboardInteractive: (_) => KeybordInteractive.defaultHandle(spi, ctx: context),
20+
onKeyboardInteractive: (_) =>
21+
KeybordInteractive.defaultHandle(spi, ctx: context),
2122
);
2223
return true;
2324
},

0 commit comments

Comments
 (0)