Skip to content

Commit

Permalink
fix: zone mismatch (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint authored Feb 1, 2024
1 parent 76dfe67 commit 3294ef8
Showing 1 changed file with 64 additions and 61 deletions.
125 changes: 64 additions & 61 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,73 +22,76 @@ import 'package:miru_app/views/widgets/platform_widget.dart';
import 'package:window_manager/window_manager.dart';

void main(List<String> args) async {
FlutterError.onError = (FlutterErrorDetails details) {
logger.severe("", details.exception, details.stack);
};
runZonedGuarded(() async {
FlutterError.onError = (FlutterErrorDetails details) {
logger.severe("", details.exception, details.stack);
};

WidgetsFlutterBinding.ensureInitialized();
WidgetsFlutterBinding.ensureInitialized();

// 多窗口
if (args.firstOrNull == 'multi_window') {
final windowId = int.parse(args[1]);
final arguments = args[2].isEmpty
? const {}
: jsonDecode(args[2]) as Map<String, dynamic>;
// 多窗口
if (args.firstOrNull == 'multi_window') {
final windowId = int.parse(args[1]);
final arguments = args[2].isEmpty
? const {}
: jsonDecode(args[2]) as Map<String, dynamic>;

Map windows = {
"debug": ExtensionDebugWindow(
windowController: WindowController.fromWindowId(windowId),
),
};
runApp(windows[arguments["name"]]);
return;
}
Map windows = {
"debug": ExtensionDebugWindow(
windowController: WindowController.fromWindowId(windowId),
),
};
runApp(windows[arguments["name"]]);
return;
}

// 主窗口
await MiruDirectory.ensureInitialized();
await MiruStorage.ensureInitialized();
MiruLog.ensureInitialized();
await ApplicationUtils.ensureInitialized();
await MiruRequest.ensureInitialized();
ExtensionUtils.ensureInitialized();
MediaKit.ensureInitialized();
// 主窗口
await MiruDirectory.ensureInitialized();
await MiruStorage.ensureInitialized();
MiruLog.ensureInitialized();
await ApplicationUtils.ensureInitialized();
await MiruRequest.ensureInitialized();
ExtensionUtils.ensureInitialized();
MediaKit.ensureInitialized();

if (!Platform.isAndroid) {
await windowManager.ensureInitialized();
final sizeArr = MiruStorage.getSetting(SettingKey.windowSize).split(",");
final size = Size(double.parse(sizeArr[0]), double.parse(sizeArr[1]));
WindowOptions windowOptions = WindowOptions(
size: size,
center: true,
minimumSize: const Size(600, 500),
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
final position = MiruStorage.getSetting(SettingKey.windowPosition);
if (position != null) {
final offsetArr = position.split(",");
final offset = Offset(
double.parse(offsetArr[0]),
double.parse(offsetArr[1]),
);
await windowManager.setPosition(
offset,
);
}
await windowManager.show();
await windowManager.focus();
});
}
if (!Platform.isAndroid) {
await windowManager.ensureInitialized();
final sizeArr = MiruStorage.getSetting(SettingKey.windowSize).split(",");
final size = Size(double.parse(sizeArr[0]), double.parse(sizeArr[1]));
WindowOptions windowOptions = WindowOptions(
size: size,
center: true,
minimumSize: const Size(600, 500),
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
final position = MiruStorage.getSetting(SettingKey.windowPosition);
if (position != null) {
final offsetArr = position.split(",");
final offset = Offset(
double.parse(offsetArr[0]),
double.parse(offsetArr[1]),
);
await windowManager.setPosition(
offset,
);
}
await windowManager.show();
await windowManager.focus();
});
}

if (Platform.isAndroid) {
SystemUiOverlayStyle style = const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
);
SystemChrome.setSystemUIOverlayStyle(style);
}
runZonedGuarded(() => runApp(const MainApp()), (error, stack) {
if (Platform.isAndroid) {
SystemUiOverlayStyle style = const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
);
SystemChrome.setSystemUIOverlayStyle(style);
}

runApp(const MainApp());
}, (error, stack) {
logger.severe("", error, stack);
});
}
Expand Down

0 comments on commit 3294ef8

Please sign in to comment.