2023-02-11 06:16:38 +00:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/core/helpers/helpers.dart';
|
2023-05-17 03:03:33 +00:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-05-30 03:06:23 +00:00
|
|
|
import 'package:appflowy/startup/tasks/app_window_size_manager.dart';
|
2023-02-11 06:16:38 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2023-05-30 03:06:23 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-02-11 06:16:38 +00:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
|
2023-05-30 03:06:23 +00:00
|
|
|
class InitAppWindowTask extends LaunchTask with WindowListener {
|
2023-05-17 03:03:33 +00:00
|
|
|
const InitAppWindowTask({
|
2023-05-21 10:53:59 +00:00
|
|
|
this.minimumSize = const Size(800, 600),
|
2023-05-17 03:03:33 +00:00
|
|
|
this.title = 'AppFlowy',
|
|
|
|
});
|
2023-02-11 06:16:38 +00:00
|
|
|
|
2023-05-17 03:03:33 +00:00
|
|
|
final Size minimumSize;
|
|
|
|
final String title;
|
2023-02-11 06:16:38 +00:00
|
|
|
|
2023-05-17 03:03:33 +00:00
|
|
|
@override
|
|
|
|
Future<void> initialize(LaunchContext context) async {
|
2023-02-11 06:16:38 +00:00
|
|
|
// Don't initialize on mobile or web.
|
|
|
|
if (!defaultTargetPlatform.isDesktop) {
|
2023-05-17 03:03:33 +00:00
|
|
|
return;
|
2023-02-11 06:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await windowManager.ensureInitialized();
|
2023-05-30 03:06:23 +00:00
|
|
|
windowManager.addListener(this);
|
2023-02-11 06:16:38 +00:00
|
|
|
|
2023-06-15 14:43:07 +00:00
|
|
|
Size windowSize = await WindowSizeManager().getSize();
|
2023-07-02 15:37:30 +00:00
|
|
|
if (context.env.isIntegrationTest) {
|
2023-06-15 14:43:07 +00:00
|
|
|
windowSize = const Size(1600, 1200);
|
|
|
|
}
|
2023-05-30 03:06:23 +00:00
|
|
|
|
|
|
|
final windowOptions = WindowOptions(
|
|
|
|
size: windowSize,
|
|
|
|
minimumSize: const Size(
|
|
|
|
WindowSizeManager.minWindowWidth,
|
|
|
|
WindowSizeManager.minWindowHeight,
|
|
|
|
),
|
2023-05-17 03:03:33 +00:00
|
|
|
title: title,
|
2023-02-11 06:16:38 +00:00
|
|
|
);
|
|
|
|
|
2023-06-12 06:29:09 +00:00
|
|
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
2023-02-11 06:16:38 +00:00
|
|
|
await windowManager.show();
|
|
|
|
await windowManager.focus();
|
|
|
|
});
|
|
|
|
}
|
2023-05-30 03:06:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> onWindowResize() async {
|
|
|
|
final currentWindowSize = await windowManager.getSize();
|
|
|
|
WindowSizeManager().saveSize(currentWindowSize);
|
|
|
|
}
|
2023-02-11 06:16:38 +00:00
|
|
|
}
|