|
| 1 | +import 'dart:ffi' as ffi; |
| 2 | +import 'dart:io'; |
| 3 | + |
1 | 4 | import 'package:pslab/providers/sht21_provider.dart'; |
| 5 | +import 'package:flutter/foundation.dart'; |
2 | 6 | import 'package:flutter/material.dart'; |
3 | 7 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| 8 | +import 'package:package_info_plus/package_info_plus.dart'; |
4 | 9 | import 'package:provider/provider.dart'; |
5 | 10 | import 'package:pslab/l10n/app_localizations.dart'; |
6 | 11 | import 'package:pslab/providers/board_state_provider.dart'; |
@@ -30,9 +35,22 @@ import 'package:pslab/view/wave_generator_screen.dart'; |
30 | 35 | import 'package:pslab/view/experiments_screen.dart'; |
31 | 36 | import 'constants.dart'; |
32 | 37 |
|
33 | | -void main() { |
34 | | - setupLocator(); |
| 38 | +void main(List<String> args) async { |
35 | 39 | WidgetsFlutterBinding.ensureInitialized(); |
| 40 | + |
| 41 | + if (!kIsWeb && |
| 42 | + (Platform.isWindows || Platform.isLinux || Platform.isMacOS) && |
| 43 | + args.any((a) => a == '-v' || a == '--version')) { |
| 44 | + if (Platform.isWindows) { |
| 45 | + _attachParentConsole(); |
| 46 | + } |
| 47 | + final info = await PackageInfo.fromPlatform(); |
| 48 | + stdout.writeln('${info.appName} ${info.version}+${info.buildNumber}'); |
| 49 | + await stdout.flush(); |
| 50 | + exit(0); |
| 51 | + } |
| 52 | + |
| 53 | + setupLocator(); |
36 | 54 | runApp( |
37 | 55 | MultiProvider( |
38 | 56 | providers: [ |
@@ -157,6 +175,14 @@ class _LocaleAware extends StatelessWidget { |
157 | 175 | } |
158 | 176 | } |
159 | 177 |
|
| 178 | +void _attachParentConsole() { |
| 179 | + const attachParentProcess = 0xFFFFFFFF; |
| 180 | + final kernel32 = ffi.DynamicLibrary.open('kernel32.dll'); |
| 181 | + final attachConsole = kernel32.lookupFunction<ffi.Int32 Function(ffi.Uint32), |
| 182 | + int Function(int)>('AttachConsole'); |
| 183 | + attachConsole(attachParentProcess); |
| 184 | +} |
| 185 | + |
160 | 186 | void _preCacheImages(BuildContext context) { |
161 | 187 | for (final path in instrumentIcons) { |
162 | 188 | precacheImage(AssetImage(path), context); |
|
0 commit comments