Skip to content

Commit dd3c326

Browse files
committed
Create control.dart
1 parent f140eef commit dd3c326

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

lib/service/control.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'dart:io';
2+
import 'package:mihomoR/service/path.dart';
3+
import 'package:mihomoR/service/subscriptions.dart';
4+
import 'package:quick_settings_with_flutter_plugins/quick_settings.dart';
5+
6+
Future<void> stopMihomo() async {
7+
await QuickSettings.syncTile(
8+
Tile(
9+
label: "mihomo",
10+
tileStatus: TileStatus.inactive,
11+
drawableName: 'quick_settings_base_icon',
12+
contentDescription: "mihomo 已停止",
13+
),
14+
);
15+
final settings = await readYamlAsMap(settingsPath);
16+
final stopCmd = settings['kill'] ?? '';
17+
if (stopCmd.isNotEmpty) {
18+
await Process.run("sh", ["-c", stopCmd]);
19+
}
20+
21+
}
22+
23+
Future<void> startMihomo() async {
24+
await QuickSettings.syncTile(
25+
Tile(
26+
label: "mihomo",
27+
tileStatus: TileStatus.active,
28+
drawableName: 'quick_settings_base_icon',
29+
contentDescription: "mihomo 已启动",
30+
),
31+
);
32+
final settings = await readYamlAsMap(settingsPath);
33+
final stopCmd = settings['kill'] ?? '';
34+
final startCmd = settings['start'] ?? '';
35+
36+
// 先停止
37+
if (stopCmd.isNotEmpty) {
38+
await Process.run("sh", ["-c", stopCmd]);
39+
}
40+
41+
// 再启动
42+
if (startCmd.isNotEmpty) {
43+
await Process.start("sh", ["-c", startCmd]);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)