mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-31 16:18:22 +08:00
@@ -13,6 +13,7 @@ import 'package:PiliPlus/services/logger.dart';
|
|||||||
import 'package:PiliPlus/services/service_locator.dart';
|
import 'package:PiliPlus/services/service_locator.dart';
|
||||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||||
import 'package:PiliPlus/utils/cache_manage.dart';
|
import 'package:PiliPlus/utils/cache_manage.dart';
|
||||||
|
import 'package:PiliPlus/utils/calc_window_position.dart';
|
||||||
import 'package:PiliPlus/utils/date_utils.dart';
|
import 'package:PiliPlus/utils/date_utils.dart';
|
||||||
import 'package:PiliPlus/utils/page_utils.dart';
|
import 'package:PiliPlus/utils/page_utils.dart';
|
||||||
import 'package:PiliPlus/utils/request_utils.dart';
|
import 'package:PiliPlus/utils/request_utils.dart';
|
||||||
@@ -36,7 +37,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:media_kit/media_kit.dart';
|
import 'package:media_kit/media_kit.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart' hide calcWindowPosition;
|
||||||
|
|
||||||
WebViewEnvironment? webViewEnvironment;
|
WebViewEnvironment? webViewEnvironment;
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ void main() async {
|
|||||||
title: Constants.appName,
|
title: Constants.appName,
|
||||||
);
|
);
|
||||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
await windowManager.setBounds(await Utils.windowOffset & Pref.windowSize);
|
await windowManager.setBounds(await calcWindowPosition & Pref.windowSize);
|
||||||
if (Pref.isWindowMaximized) await windowManager.maximize();
|
if (Pref.isWindowMaximized) await windowManager.maximize();
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
|
|||||||
54
lib/utils/calc_window_position.dart
Normal file
54
lib/utils/calc_window_position.dart
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:screen_retriever/screen_retriever.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
Future<Offset> get calcWindowPosition async {
|
||||||
|
Display primaryDisplay = await screenRetriever.getPrimaryDisplay();
|
||||||
|
List<Display> allDisplays = await screenRetriever.getAllDisplays();
|
||||||
|
Offset cursorScreenPoint = await screenRetriever.getCursorScreenPoint();
|
||||||
|
|
||||||
|
Display currentDisplay = allDisplays.firstWhere(
|
||||||
|
(display) => Rect.fromLTWH(
|
||||||
|
display.visiblePosition!.dx,
|
||||||
|
display.visiblePosition!.dy,
|
||||||
|
display.size.width,
|
||||||
|
display.size.height,
|
||||||
|
).contains(cursorScreenPoint),
|
||||||
|
orElse: () => primaryDisplay,
|
||||||
|
);
|
||||||
|
|
||||||
|
num visibleWidth = currentDisplay.size.width;
|
||||||
|
num visibleHeight = currentDisplay.size.height;
|
||||||
|
num visibleStartX = 0;
|
||||||
|
num visibleStartY = 0;
|
||||||
|
|
||||||
|
if (currentDisplay.visibleSize != null) {
|
||||||
|
visibleWidth = currentDisplay.visibleSize!.width;
|
||||||
|
visibleHeight = currentDisplay.visibleSize!.height;
|
||||||
|
}
|
||||||
|
if (currentDisplay.visiblePosition != null) {
|
||||||
|
visibleStartX = currentDisplay.visiblePosition!.dx;
|
||||||
|
visibleStartY = currentDisplay.visiblePosition!.dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
final windowPosition = Pref.windowPosition;
|
||||||
|
if (windowPosition != null) {
|
||||||
|
try {
|
||||||
|
final dx = windowPosition[0];
|
||||||
|
final dy = windowPosition[1];
|
||||||
|
if (dx >= visibleStartX &&
|
||||||
|
dy >= visibleStartY &&
|
||||||
|
dx < (visibleWidth - 30) &&
|
||||||
|
dy < (visibleHeight - 30)) {
|
||||||
|
return Offset(dx, dy);
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
final windowSize = await windowManager.getSize();
|
||||||
|
return Offset(
|
||||||
|
visibleStartX + (visibleWidth / 2) - (windowSize.width / 2),
|
||||||
|
visibleStartY + ((visibleHeight / 2) - (windowSize.height / 2)),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,17 +4,14 @@ import 'dart:io';
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:PiliPlus/common/constants.dart';
|
import 'package:PiliPlus/common/constants.dart';
|
||||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:flutter/material.dart' show Alignment;
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
|
||||||
|
|
||||||
abstract class Utils {
|
abstract class Utils {
|
||||||
static final Random random = Random();
|
static final Random random = Random();
|
||||||
@@ -28,17 +25,6 @@ abstract class Utils {
|
|||||||
static final bool isDesktop =
|
static final bool isDesktop =
|
||||||
Platform.isWindows || Platform.isMacOS || Platform.isLinux;
|
Platform.isWindows || Platform.isMacOS || Platform.isLinux;
|
||||||
|
|
||||||
static Future<Offset> get windowOffset async {
|
|
||||||
final windowPosition = Pref.windowPosition;
|
|
||||||
if (windowPosition != null) {
|
|
||||||
return Offset(windowPosition[0], windowPosition[1]);
|
|
||||||
}
|
|
||||||
return await calcWindowPosition(
|
|
||||||
await windowManager.getSize(),
|
|
||||||
Alignment.center,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<bool> get isWiFi async {
|
static Future<bool> get isWiFi async {
|
||||||
try {
|
try {
|
||||||
return Utils.isMobile &&
|
return Utils.isMobile &&
|
||||||
|
|||||||
@@ -1514,7 +1514,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.1.0"
|
||||||
screen_retriever:
|
screen_retriever:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: screen_retriever
|
name: screen_retriever
|
||||||
sha256: "570dbc8e4f70bac451e0efc9c9bb19fa2d6799a11e6ef04f946d7886d2e23d0c"
|
sha256: "570dbc8e4f70bac451e0efc9c9bb19fa2d6799a11e6ef04f946d7886d2e23d0c"
|
||||||
|
|||||||
@@ -229,6 +229,7 @@ dependencies:
|
|||||||
material_color_utilities: any
|
material_color_utilities: any
|
||||||
flutter_cache_manager: any
|
flutter_cache_manager: any
|
||||||
http2: any
|
http2: any
|
||||||
|
screen_retriever: any
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
# screen_brightness: ^2.1.
|
# screen_brightness: ^2.1.
|
||||||
|
|||||||
Reference in New Issue
Block a user