2024-04-30 23:38:49 +08:00
|
|
|
import 'dart:async';
|
2024-07-15 22:06:09 +08:00
|
|
|
import 'dart:io';
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
import 'package:fl_clash/plugins/app.dart';
|
|
|
|
|
import 'package:fl_clash/plugins/tile.dart';
|
|
|
|
|
import 'package:fl_clash/state.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-12-03 21:47:12 +08:00
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'application.dart';
|
2024-12-03 21:47:12 +08:00
|
|
|
import 'common/common.dart';
|
2025-07-31 17:09:18 +08:00
|
|
|
import 'core/controller.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
Future<void> main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2024-09-08 21:21:21 +08:00
|
|
|
final version = await system.version;
|
2025-02-09 18:39:38 +08:00
|
|
|
await globalState.initApp(version);
|
2024-08-26 20:44:30 +08:00
|
|
|
HttpOverrides.global = FlClashHttpOverrides();
|
2025-07-31 17:09:18 +08:00
|
|
|
runApp(ProviderScope(child: const Application()));
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@pragma('vm:entry-point')
|
2025-01-13 19:08:17 +08:00
|
|
|
Future<void> _service(List<String> flags) async {
|
2024-04-30 23:38:49 +08:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2025-07-31 17:09:18 +08:00
|
|
|
globalState.isService = true;
|
2025-02-09 18:39:38 +08:00
|
|
|
await globalState.init();
|
2025-07-31 17:09:18 +08:00
|
|
|
await coreController.preload();
|
2025-01-13 19:08:17 +08:00
|
|
|
tile?.addListener(
|
|
|
|
|
_TileListenerWithService(
|
|
|
|
|
onStop: () async {
|
|
|
|
|
await app?.tip(appLocalizations.stopVpn);
|
2025-07-31 17:09:18 +08:00
|
|
|
await globalState.handleStop();
|
2024-07-02 08:08:31 +08:00
|
|
|
},
|
2025-01-13 19:08:17 +08:00
|
|
|
),
|
|
|
|
|
);
|
2025-09-27 23:39:20 +08:00
|
|
|
app?.tip(appLocalizations.startVpn);
|
|
|
|
|
final version = await system.version;
|
|
|
|
|
await coreController.init(version);
|
|
|
|
|
final clashConfig = globalState.config.patchClashConfig.copyWith.tun(
|
|
|
|
|
enable: false,
|
|
|
|
|
);
|
2025-10-14 15:13:52 +08:00
|
|
|
final setupState = globalState.getSetupState(
|
|
|
|
|
globalState.config.currentProfileId,
|
|
|
|
|
);
|
|
|
|
|
globalState.setupConfig(
|
|
|
|
|
setupState: setupState,
|
|
|
|
|
patchConfig: clashConfig,
|
2025-09-27 23:39:20 +08:00
|
|
|
preloadInvoke: () {
|
|
|
|
|
globalState.handleStart();
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-15 16:14:19 +08:00
|
|
|
@immutable
|
2025-01-13 19:08:17 +08:00
|
|
|
class _TileListenerWithService with TileListener {
|
2024-04-30 23:38:49 +08:00
|
|
|
final Function() _onStop;
|
|
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
const _TileListenerWithService({required Function() onStop})
|
|
|
|
|
: _onStop = onStop;
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onStop() {
|
|
|
|
|
_onStop();
|
|
|
|
|
}
|
|
|
|
|
}
|