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.
|
2023-07-09 03:03:22 +00:00
|
|
|
if (!defaultTargetPlatform.isDesktop || context.env.isIntegrationTest) {
|
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-07-09 03:03:22 +00:00
|
|
|
final windowSize = await WindowSizeManager().getSize();
|
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-07-18 02:45:06 +00:00
|
|
|
|
|
|
|
final position = await WindowSizeManager().getPosition();
|
|
|
|
if (position != null) {
|
|
|
|
await windowManager.setPosition(position);
|
|
|
|
}
|
2023-02-11 06:16:38 +00:00
|
|
|
});
|
|
|
|
}
|
2023-05-30 03:06:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> onWindowResize() async {
|
2023-07-18 02:45:06 +00:00
|
|
|
super.onWindowResize();
|
|
|
|
|
2023-05-30 03:06:23 +00:00
|
|
|
final currentWindowSize = await windowManager.getSize();
|
2023-07-18 02:45:06 +00:00
|
|
|
WindowSizeManager().setSize(currentWindowSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onWindowMaximize() async {
|
|
|
|
super.onWindowMaximize();
|
|
|
|
|
|
|
|
final currentWindowSize = await windowManager.getSize();
|
|
|
|
WindowSizeManager().setSize(currentWindowSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onWindowMoved() async {
|
|
|
|
super.onWindowMoved();
|
|
|
|
|
|
|
|
final position = await windowManager.getPosition();
|
|
|
|
WindowSizeManager().setPosition(position);
|
2023-05-30 03:06:23 +00:00
|
|
|
}
|
2023-02-11 06:16:38 +00:00
|
|
|
}
|