Skip to content

Commit 75d7438

Browse files
authored
refactor: remove dead code and dedupe redundant utilities (#1230)
* refactor: remove 42 unused localization keys and regenerate l10n * refactor: remove dead tmux methods and unused res constants * refactor: drop unused comparator/sudo-password methods and dedupe shellSingleQuote * refactor: replace deprecated EquatableMixin and complete tmux barrel export * test: update tests after removing dead tmux and comparator methods * fix: use 'extends Equatable' instead of 'with Equatable' in Disk
1 parent 90e1cdc commit 75d7438

43 files changed

Lines changed: 81 additions & 3173 deletions

Some content is hidden

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

lib/core/utils/comparator.dart

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ class ChainComparator<T> {
55
ChainComparator._create(this._parent, this._comparator);
66
ChainComparator.create() : this._create(null, (a, b) => 0);
77

8-
static ChainComparator<T> comparing<T, F extends Comparable<F>>(
9-
F Function(T) extractor,
10-
) {
11-
return ChainComparator._create(
12-
null,
13-
(a, b) => extractor(a).compareTo(extractor(b)),
14-
);
15-
}
16-
178
int compare(T a, T b) {
189
final parent = _parent;
1910
if (parent != null) {
@@ -49,25 +40,12 @@ class ChainComparator<T> {
4940
);
5041
}
5142

52-
ChainComparator<T> thenCompareByReversed<F extends Comparable<F>>(
53-
F Function(T) extractor,
54-
) {
55-
return ChainComparator._create(
56-
this,
57-
(a, b) => -extractor(a).compareTo(extractor(b)),
58-
);
59-
}
60-
6143
ChainComparator<T> thenTrueFirst(bool Function(T) f) {
6244
return ChainComparator._create(this, (a, b) {
6345
final fa = f(a), fb = f(b);
6446
return fa == fb ? 0 : (fa ? -1 : 1);
6547
});
6648
}
67-
68-
ChainComparator<T> reversed() {
69-
return ChainComparator._create(null, (a, b) => compare(b, a));
70-
}
7149
}
7250

7351
class Comparators {

lib/core/utils/sudo_password.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ abstract final class SudoPassword {
1414
return value;
1515
}
1616

17-
static Future<bool> hasOverride(String serverId) async {
18-
return await readOverride(serverId) != null;
19-
}
20-
2117
static Future<void> writeOverride(String serverId, String value) async {
2218
if (value.isEmpty) {
2319
await clearOverride(serverId);

lib/data/model/server/disk.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:server_box/data/model/server/time_seq.dart';
66

77
import 'package:server_box/data/res/misc.dart';
88

9-
class Disk with EquatableMixin {
9+
class Disk extends Equatable {
1010
final String path;
1111
final String? fsTyp;
1212
final String mount;

lib/data/provider/container.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
88
import 'package:riverpod_annotation/riverpod_annotation.dart';
99
import 'package:server_box/core/extension/context/locale.dart';
1010
import 'package:server_box/core/extension/ssh_client.dart';
11+
import 'package:server_box/core/utils/shell_quote.dart' as sh;
1112
import 'package:server_box/data/model/app/error.dart';
1213
import 'package:server_box/data/model/app/scripts/script_consts.dart';
1314
import 'package:server_box/data/model/container/image.dart';
@@ -23,6 +24,10 @@ final _dockerNotFound = RegExp(
2324
);
2425
final _podmanEmulationMsg = 'Emulate Docker CLI using podman';
2526

27+
// Forwarder to the canonical quoter so part files can reference it inside
28+
// extension method bodies (imported top-level names are not visible there).
29+
String shellSingleQuote(String value) => sh.shellSingleQuote(value);
30+
2631
@freezed
2732
abstract class ContainerState with _$ContainerState {
2833
const factory ContainerState({
@@ -465,7 +470,7 @@ class ContainerNotifier extends _$ContainerNotifier {
465470
cmd = 'export LANG=en_US.UTF-8 && $cmd';
466471
final noDockerHost = dockerHost?.isEmpty ?? true;
467472
if (!noDockerHost) {
468-
cmd = 'export DOCKER_HOST=${_shellQuote(dockerHost!)} && $cmd';
473+
cmd = 'export DOCKER_HOST=${shellSingleQuote(dockerHost!)} && $cmd';
469474
}
470475
return cmd;
471476
}
@@ -478,10 +483,6 @@ String _buildSudoCmd(String baseCmd, String password) {
478483
return 'echo "$pwdBase64" | base64 -d | sudo -S $baseCmd';
479484
}
480485

481-
String shellSingleQuote(String value) => "'${value.replaceAll("'", "'\\''")}'";
482-
483-
String _shellQuote(String value) => shellSingleQuote(value);
484-
485486
enum ContainerCmdType {
486487
version,
487488
ps,

lib/data/res/default.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import 'dart:ui';
2-
31
abstract final class Defaults {
4-
static const primaryColor = Color.fromARGB(255, 145, 58, 31);
5-
62
static const updateInterval = 3;
73

84
static const editorTheme = 'a11y-light';

lib/data/res/misc.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import 'dart:convert';
2-
31
abstract final class Miscs {
42
static final blankReg = RegExp(r'\s+');
5-
static final multiBlankReg = RegExp(r'\s{2,}');
63

74
/// RegExp for password request
85
static final pwdRequestWithUserReg = RegExp(r'\[sudo\] password for (.+):');
@@ -15,7 +12,5 @@ abstract final class Miscs {
1512

1613
static const pkgName = 'tech.lolli.toolbox';
1714

18-
static const jsonEncoder = JsonEncoder.withIndent(' ');
19-
2015
static const bakFileName = 'srvbox_bak.json';
2116
}

lib/data/res/url.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
abstract final class Urls {
2-
static const cdnBase = 'https://cdn.lpkt.cn/serverbox';
32
static const myGithub = 'https://github.com/lollipopkit';
43
static const githubApi = 'https://api.github.com/repos/lollipopkit';
54
static const thisRepo = '$myGithub/flutter_server_box';

lib/data/ssh/tmux/tmux_export.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export 'tmux_restore_state.dart';
44
export 'tmux_session.dart';
55
export 'tmux_session_info.dart';
66
export 'tmux_session_scanner.dart';
7+
export 'tmux_window_info.dart';

lib/data/ssh/tmux/tmux_session.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
22

3-
import 'package:flutter/foundation.dart';
43
import 'package:server_box/data/ssh/persistent_shell.dart';
54
import 'package:server_box/data/ssh/tmux/tmux_command_builder.dart';
65
import 'package:server_box/data/ssh/tmux/tmux_session_info.dart';
@@ -37,7 +36,6 @@ final class TmuxAttachSkip extends TmuxAttachChoice {
3736
final class TmuxSession {
3837
final PersistentShell _shell;
3938
final TmuxSessionScanner _scanner;
40-
final ValueNotifier<TmuxAttachChoice?> choiceNotifier = ValueNotifier(null);
4139
final String? _lang;
4240

4341
TmuxSession(PersistentShell shell, {String? lang})
@@ -47,9 +45,6 @@ final class TmuxSession {
4745

4846
TmuxSessionScanner get scanner => _scanner;
4947

50-
String? _lastSessionName;
51-
String? get lastSessionName => _lastSessionName;
52-
5348
/// Check if tmux is available on the remote server.
5449
Future<bool> get isAvailable => _scanner.isTmuxAvailable();
5550

@@ -60,16 +55,6 @@ final class TmuxSession {
6055
Future<List<TmuxWindowInfo>> listWindows(String sessionName) =>
6156
_scanner.listWindows(sessionName);
6257

63-
/// Set the user's choice and remember the session name for reconnection.
64-
void setChoice(TmuxAttachChoice choice) {
65-
choiceNotifier.value = choice;
66-
if (choice is TmuxAttachExisting) {
67-
_lastSessionName = choice.sessionName;
68-
} else if (choice is TmuxAttachNew) {
69-
_lastSessionName = choice.sessionName;
70-
}
71-
}
72-
7358
/// Generate the shell command to execute for tmux attachment.
7459
///
7560
/// Returns the command string to prepend to the terminal session.
@@ -103,29 +88,6 @@ final class TmuxSession {
10388
};
10489
}
10590

106-
/// Build the command for auto-reconnection.
107-
///
108-
/// If a previous session was active, try to reattach.
109-
/// Otherwise, fall back to creating a new session.
110-
String buildReconnectCommand() {
111-
if (_lastSessionName != null) {
112-
return TmuxCommandBuilder.newSessionOrAttach(
113-
_lastSessionName!,
114-
lang: _lang,
115-
);
116-
}
117-
return 'tmux new-session';
118-
}
119-
120-
/// Generate the initial auto-tmux command.
121-
///
122-
/// Uses `tmux new-session -A` which attaches to an existing session
123-
/// with the given name or creates a new one.
124-
String buildAutoCommand({String? sessionName}) {
125-
final name = sessionName ?? 'server_box';
126-
return TmuxCommandBuilder.newSessionOrAttach(name, lang: _lang);
127-
}
128-
12991
/// Kill a tmux session.
13092
Future<bool> killSession(String name) => _scanner.killSession(name);
13193

lib/data/ssh/tmux/tmux_session_info.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ final class TmuxSessionInfo {
2929
);
3030
}
3131

32-
/// Format for display in session selector.
33-
String get displayName {
34-
final parts = <String>[name];
35-
if (windows > 0) {
36-
parts.add('$windows window${windows == 1 ? '' : 's'}');
37-
}
38-
if (attached) {
39-
parts.add('(attached)');
40-
}
41-
return parts.join(' · ');
42-
}
43-
4432
@override
4533
String toString() => 'TmuxSession($name, $windows windows, attached=$attached)';
4634
}

0 commit comments

Comments
 (0)