Skip to content

Commit f28ddf2

Browse files
committed
fix(windows): 单例启动交给原生
1 parent 4b970b4 commit f28ddf2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

simple_live_app/lib/main.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void main() async {
4343
// init-queue:
4444
// window(first)->migration->media_kit->Hive->services->start
4545
// window(second)->open
46-
await initWindow();
46+
await firstOpen();
4747
await MigrationService.migrateData();
4848
MediaKit.ensureInitialized();
4949
await Hive.initFlutter(
@@ -53,7 +53,7 @@ void main() async {
5353
);
5454
//初始化服务
5555
await initServices();
56-
WindowService.instance.init();
56+
await initWindow();
5757

5858
MigrationService.migrateDataByVersion();
5959
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
@@ -67,13 +67,9 @@ void main() async {
6767
runApp(const MyApp());
6868
}
6969

70-
Future initWindow() async {
71-
if (!(Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
72-
return;
73-
}
74-
await windowManager.ensureInitialized();
70+
Future firstOpen() async {
7571
// 判定程序是否启动-- windows 交给原生
76-
if(Platform.isWindows == false) {
72+
if (Platform.isWindows == false) {
7773
if (!await FlutterSingleInstance().isFirstInstance()) {
7874
Log.i("App is already running");
7975
final err = await FlutterSingleInstance().focus();
@@ -85,6 +81,14 @@ Future initWindow() async {
8581
}
8682
}
8783

84+
Future initWindow() async {
85+
if (!(Platform.isMacOS || Platform.isWindows || Platform.isLinux)) {
86+
return;
87+
}
88+
await windowManager.ensureInitialized();
89+
WindowService.instance.init();
90+
}
91+
8892
Future initServices() async {
8993
Hive.registerAdapter(FollowUserAdapter());
9094
Hive.registerAdapter(HistoryAdapter());

simple_live_app/windows/runner/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
3434
FlutterWindow window(project);
3535
Win32Window::Point origin(10, 10);
3636
Win32Window::Size size(1280, 720);
37-
if (!window.Create(L"simple_live_app", origin, size)) {
37+
if (!window.Create(L"Slive", origin, size)) {
3838
return EXIT_FAILURE;
3939
}
4040
window.SetQuitOnClose(true);

0 commit comments

Comments
 (0)