Build native Flutter Linux manager and deb release 0.2.5

This commit is contained in:
tongtong committed 2026-11-13 19:28:09 +08:00
1 parent 3c6c4a0e90
commit 03e729a60b
35 files changed
+757 -69

No files matched your search

+40 -5
View File
@@ -10,13 +10,33 @@ import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
import 'ui/manager_model.dart';
import 'data/daily_log.dart';
import 'ui/manager_view.dart';
Future<void> main() async {
Future<void> _closeWindowForExit() async {
// Older window_manager Linux backends try to remove Flutter's implicit view.
// Flush application state, hide the GTK window, then let process exit own cleanup.
if (Platform.isLinux) {
await windowManager.hide();
} else {
await windowManager.destroy();
}
}
Future<void> main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
final model = ManagerModel();
final packageCheck = args.contains('--package-check');
final temporary = packageCheck
? Directory.systemTemp.createTempSync('ads-flutter-package-')
: null;
final model = ManagerModel(
logWriter: temporary == null ? null : DailyLog(temporary),
);
if (temporary != null) model.repository.storage = temporary;
var failed = false;
FlutterError.onError = (details) {
failed = true;
FlutterError.presentError(details);
scheduleMicrotask(
() => model.log(
@@ -25,6 +45,7 @@ Future<void> main() async {
);
};
PlatformDispatcher.instance.onError = (error, stack) {
failed = true;
scheduleMicrotask(() => model.log('[Unhandled] $error\n$stack'));
return true;
};
@@ -41,6 +62,18 @@ Future<void> main() async {
await windowManager.focus();
},
);
if (packageCheck) {
await Future<void>.delayed(const Duration(seconds: 3));
await model.shutdown();
if (temporary != null) await temporary.delete(recursive: true);
stdout.writeln(
failed ? 'ADS_FLUTTER_PACKAGE_FAILED' : 'ADS_FLUTTER_PACKAGE_OK',
);
await stdout.flush();
await trayManager.destroy();
await _closeWindowForExit();
exit(failed ? 1 : 0);
}
unawaited(model.init());
}
@@ -64,7 +97,9 @@ class _ManagerAppState extends State<ManagerApp>
Future<void> initTray() async {
try {
await trayManager.setIcon('assets/tray.ico');
await trayManager.setIcon(
Platform.isWindows ? 'assets/tray.ico' : 'assets/tray.png',
);
await trayManager.setToolTip('ADS Flutter 设备管理');
await trayManager.setContextMenu(
Menu(
@@ -91,13 +126,13 @@ class _ManagerAppState extends State<ManagerApp>
quitting = true;
await widget.model.shutdown();
await trayManager.destroy();
await windowManager.destroy();
await _closeWindowForExit();
exit(0);
}
@override
void onWindowClose() {
if (trayReady) {
if (trayReady && Platform.isWindows) {
widget.model.repository.allowEmbeddedResume = false;
unawaited(windowManager.hide());
} else {