Load bundled personal defaults when no saved profile exists
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# Personal builds: copy to default.private.toml and fill in your network.
|
||||
# This file is bundled only when no private default exists.
|
||||
hostname = "MeshPort"
|
||||
ipv4 = "10.77.0.11/24"
|
||||
listeners = []
|
||||
|
||||
[[peer]]
|
||||
uri = "tcp://relay.example.com:11010"
|
||||
|
||||
[network_identity]
|
||||
network_name = "game-net"
|
||||
network_secret = ""
|
||||
|
||||
[flags]
|
||||
no_tun = false
|
||||
use_smoltcp = false
|
||||
enable_encryption = true
|
||||
default_protocol = "udp"
|
||||
latency_first = true
|
||||
enable_ipv6 = true
|
||||
|
||||
[runtime]
|
||||
mode = "system_vpn"
|
||||
|
||||
[optimization]
|
||||
mode = "adaptive"
|
||||
prefer_udp = true
|
||||
relay_peer_ids = []
|
||||
@@ -73,6 +73,7 @@ class _LabScreenState extends State<LabScreen> {
|
||||
}
|
||||
client = applicationClient = opened;
|
||||
log('原生库已加载 · ABI v1');
|
||||
bool restored = false;
|
||||
if (profileSupported) {
|
||||
try {
|
||||
final stored = (await vpnChannel.invokeMethod<String>(
|
||||
@@ -80,6 +81,7 @@ class _LabScreenState extends State<LabScreen> {
|
||||
))?.replaceAll(RegExp(r'^subnet_routes\s*=.*$', multiLine: true), '');
|
||||
if (stored != null) {
|
||||
await loadForm(stored);
|
||||
restored = true;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
savedConfig = stored;
|
||||
@@ -92,6 +94,29 @@ class _LabScreenState extends State<LabScreen> {
|
||||
log('读取已保存配置失败,请在设置中重试');
|
||||
}
|
||||
}
|
||||
if (!restored) {
|
||||
try {
|
||||
String defaults;
|
||||
try {
|
||||
defaults = await rootBundle.loadString(
|
||||
'assets/config/default.toml',
|
||||
);
|
||||
} on FlutterError {
|
||||
defaults = await rootBundle.loadString(
|
||||
'assets/config/default.example.toml',
|
||||
);
|
||||
}
|
||||
await loadForm(defaults);
|
||||
if (mounted) setState(() => rememberConfig = profileSupported);
|
||||
log(
|
||||
secret.text.isEmpty
|
||||
? '已载入默认配置,首次填写网络密钥后保存即可'
|
||||
: '已载入默认网络配置,点击连接即可组网',
|
||||
);
|
||||
} catch (_) {
|
||||
log('默认配置加载失败,请在设置中导入配置');
|
||||
}
|
||||
}
|
||||
final diagnostics = await opened.enableDiagnostics();
|
||||
log(diagnostics['enabled'] == true ? '穿透详细日志采集已开启' : '穿透日志未接管:宿主已有日志订阅器');
|
||||
if (Platform.isAndroid) {
|
||||
|
||||
@@ -62,6 +62,8 @@ flutter:
|
||||
uses-material-design: true
|
||||
assets:
|
||||
- assets/branding/meshport.png
|
||||
- assets/config/default.toml
|
||||
- assets/config/default.example.toml
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
|
||||
@@ -44,6 +44,16 @@ void main() {
|
||||
Future<void> openSettings(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: LabScreen()));
|
||||
await waitFor(tester, find.textContaining('原生库已加载'));
|
||||
await waitFor(
|
||||
tester,
|
||||
find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Text &&
|
||||
(widget.data?.contains('已载入默认配置') == true ||
|
||||
widget.data?.contains('已载入默认网络配置') == true ||
|
||||
widget.data?.contains('已自动载入保存的网络配置') == true),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('设置').last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user