83 lines
2.3 KiB
Dart
Executable File
83 lines
2.3 KiB
Dart
Executable File
import 'dart:io';
|
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
import 'package:fl_clash/models/config.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:screen_retriever/screen_retriever.dart';
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
class Window {
|
|
init(WindowProps props, int version) async {
|
|
final acquire = await singleInstanceLock.acquire();
|
|
if (!acquire) {
|
|
exit(0);
|
|
}
|
|
if (Platform.isWindows) {
|
|
protocol.register("clash");
|
|
protocol.register("clashmeta");
|
|
protocol.register("flclash");
|
|
}
|
|
await windowManager.ensureInitialized();
|
|
WindowOptions windowOptions = WindowOptions(
|
|
size: Size(props.width, props.height),
|
|
minimumSize: const Size(380, 500),
|
|
);
|
|
if (!Platform.isMacOS || version > 10) {
|
|
await windowManager.setTitleBarStyle(TitleBarStyle.hidden);
|
|
final left = props.left ?? 0;
|
|
final top = props.top ?? 0;
|
|
final right = left + props.width;
|
|
final bottom = top + props.height;
|
|
if (left == 0 && top == 0) {
|
|
await windowManager.setAlignment(Alignment.center);
|
|
} else {
|
|
final displays = await screenRetriever.getAllDisplays();
|
|
final isPositionValid = displays.any(
|
|
(display) {
|
|
final displayBounds = Rect.fromLTWH(
|
|
display.visiblePosition!.dx,
|
|
display.visiblePosition!.dy,
|
|
display.size.width,
|
|
display.size.height,
|
|
);
|
|
return displayBounds.contains(Offset(left, top)) ||
|
|
displayBounds.contains(Offset(right, bottom));
|
|
},
|
|
);
|
|
if (isPositionValid) {
|
|
await windowManager.setPosition(
|
|
Offset(
|
|
left,
|
|
top,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
await windowManager.waitUntilReadyToShow(windowOptions, () async {
|
|
await windowManager.setPreventClose(true);
|
|
});
|
|
}
|
|
|
|
show() async {
|
|
await windowManager.show();
|
|
await windowManager.focus();
|
|
await windowManager.setSkipTaskbar(false);
|
|
}
|
|
|
|
Future<bool> isVisible() async {
|
|
return await windowManager.isVisible();
|
|
}
|
|
|
|
close() async {
|
|
exit(0);
|
|
}
|
|
|
|
hide() async {
|
|
await windowManager.hide();
|
|
await windowManager.setSkipTaskbar(true);
|
|
}
|
|
}
|
|
|
|
final window = system.isDesktop ? Window() : null;
|