mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt set window size/pos
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -84,22 +84,25 @@ void main() async {
|
||||
);
|
||||
} else if (Utils.isDesktop) {
|
||||
await windowManager.ensureInitialized();
|
||||
final windowSize = Pref.windowSize;
|
||||
final windowPosition = Pref.windowPosition;
|
||||
final hasPos = windowPosition != null;
|
||||
WindowOptions windowOptions = WindowOptions(
|
||||
minimumSize: const Size(400, 720),
|
||||
size: Size(windowSize[0], windowSize[1]),
|
||||
center: !hasPos,
|
||||
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
minimumSize: Size(400, 720),
|
||||
skipTaskbar: false,
|
||||
titleBarStyle: TitleBarStyle.normal,
|
||||
title: Constants.appName,
|
||||
);
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
if (hasPos) {
|
||||
await windowManager.setPosition(
|
||||
Offset(windowPosition[0], windowPosition[1]),
|
||||
);
|
||||
final windowSize = Pref.windowSize;
|
||||
final windowOffset = await Utils.windowOffset;
|
||||
final bounds = Rect.fromLTWH(
|
||||
windowOffset.left,
|
||||
windowOffset.top,
|
||||
windowSize[0],
|
||||
windowSize[1],
|
||||
);
|
||||
await windowManager.setBounds(bounds);
|
||||
if (Pref.isWindowMaximized) {
|
||||
await windowManager.maximize();
|
||||
}
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
|
||||
@@ -33,6 +33,7 @@ class MainApp extends StatefulWidget {
|
||||
class _MainAppState extends State<MainApp>
|
||||
with RouteAware, WidgetsBindingObserver, WindowListener, TrayListener {
|
||||
final MainController _mainController = Get.put(MainController());
|
||||
late final _setting = GStorage.setting;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -98,29 +99,32 @@ class _MainAppState extends State<MainApp>
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowMoved() {
|
||||
updateWindowOffset();
|
||||
void onWindowMaximize() {
|
||||
_setting.put(SettingBoxKey.isWindowMaximized, true);
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowResized() {
|
||||
updateWindowSize();
|
||||
updateWindowOffset();
|
||||
void onWindowUnmaximize() {
|
||||
_setting.put(SettingBoxKey.isWindowMaximized, false);
|
||||
}
|
||||
|
||||
Future<void> updateWindowOffset() async {
|
||||
@override
|
||||
Future<void> onWindowMoved() async {
|
||||
if (!await windowManager.isMaximized()) {
|
||||
final Offset offset = await windowManager.getPosition();
|
||||
GStorage.setting.put(SettingBoxKey.windowPosition, [
|
||||
_setting.put(SettingBoxKey.windowPosition, [
|
||||
offset.dx,
|
||||
offset.dy,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateWindowSize() async {
|
||||
final Size size = await windowManager.getSize();
|
||||
GStorage.setting.put(SettingBoxKey.windowSize, [size.width, size.height]);
|
||||
@override
|
||||
Future<void> onWindowResized() async {
|
||||
final Rect bounds = await windowManager.getBounds();
|
||||
_setting
|
||||
..put(SettingBoxKey.windowSize, [bounds.width, bounds.height])
|
||||
..put(SettingBoxKey.windowPosition, [bounds.left, bounds.top]);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -135,10 +135,12 @@ abstract class SettingBoxKey {
|
||||
showFsScreenshotBtn = 'showFsScreenshotBtn',
|
||||
showFsLockBtn = 'showFsLockBtn',
|
||||
silentDownImg = 'silentDownImg',
|
||||
showMemberShop = 'showMemberShop',
|
||||
minimizeOnExit = 'minimizeOnExit',
|
||||
showMemberShop = 'showMemberShop';
|
||||
|
||||
static const String minimizeOnExit = 'minimizeOnExit',
|
||||
windowSize = 'windowSize',
|
||||
windowPosition = 'windowPosition';
|
||||
windowPosition = 'windowPosition',
|
||||
isWindowMaximized = 'isWindowMaximized';
|
||||
|
||||
static const String subtitlePreferenceV2 = 'subtitlePreferenceV2',
|
||||
enableDragSubtitle = 'enableDragSubtitle',
|
||||
|
||||
@@ -823,4 +823,7 @@ abstract class Pref {
|
||||
|
||||
static List<double>? get windowPosition =>
|
||||
_setting.get(SettingBoxKey.windowPosition);
|
||||
|
||||
static bool get isWindowMaximized =>
|
||||
_setting.get(SettingBoxKey.isWindowMaximized, defaultValue: false);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,17 @@ import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:connectivity_plus/connectivity_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_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
abstract class Utils {
|
||||
static final Random random = Random();
|
||||
@@ -25,6 +28,19 @@ abstract class Utils {
|
||||
static final bool isDesktop =
|
||||
Platform.isWindows || Platform.isMacOS || Platform.isLinux;
|
||||
|
||||
static Future<({double left, double top})> get windowOffset async {
|
||||
final windowPosition = Pref.windowPosition;
|
||||
if (windowPosition != null) {
|
||||
return (left: windowPosition[0], top: windowPosition[1]);
|
||||
}
|
||||
final Size windowSize = await windowManager.getSize();
|
||||
final Offset position = await calcWindowPosition(
|
||||
windowSize,
|
||||
Alignment.center,
|
||||
);
|
||||
return (left: position.dx, top: position.dy);
|
||||
}
|
||||
|
||||
static Future<bool> get isWiFi async {
|
||||
try {
|
||||
return Utils.isMobile &&
|
||||
|
||||
Reference in New Issue
Block a user