mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
cache window size/pos
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -35,7 +35,13 @@ import 'package:window_manager/window_manager.dart';
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
MediaKit.ensureInitialized();
|
||||
await GStorage.init();
|
||||
try {
|
||||
await GStorage.init();
|
||||
} catch (e) {
|
||||
await Utils.copyText(e.toString());
|
||||
if (kDebugMode) debugPrint('GStorage init error: $e');
|
||||
exit(0);
|
||||
}
|
||||
Get.lazyPut(AccountService.new);
|
||||
HttpOverrides.global = _CustomHttpOverrides();
|
||||
|
||||
@@ -78,15 +84,23 @@ void main() async {
|
||||
);
|
||||
} else if (Utils.isDesktop) {
|
||||
await windowManager.ensureInitialized();
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
minimumSize: Size(400, 720),
|
||||
size: Size(1180, 720),
|
||||
center: true,
|
||||
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,
|
||||
skipTaskbar: false,
|
||||
titleBarStyle: TitleBarStyle.normal,
|
||||
title: Constants.appName,
|
||||
);
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
if (hasPos) {
|
||||
await windowManager.setPosition(
|
||||
Offset(windowPosition[0], windowPosition[1]),
|
||||
);
|
||||
}
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:PiliPlus/utils/context_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -96,6 +97,32 @@ class _MainAppState extends State<MainApp>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowMoved() {
|
||||
updateWindowOffset();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowResized() {
|
||||
updateWindowSize();
|
||||
updateWindowOffset();
|
||||
}
|
||||
|
||||
Future<void> updateWindowOffset() async {
|
||||
if (!await windowManager.isMaximized()) {
|
||||
final Offset offset = await windowManager.getPosition();
|
||||
GStorage.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
|
||||
void onWindowClose() {
|
||||
if (_mainController.minimizeOnExit) {
|
||||
|
||||
@@ -136,7 +136,9 @@ abstract class SettingBoxKey {
|
||||
showFsLockBtn = 'showFsLockBtn',
|
||||
silentDownImg = 'silentDownImg',
|
||||
showMemberShop = 'showMemberShop',
|
||||
minimizeOnExit = 'minimizeOnExit';
|
||||
minimizeOnExit = 'minimizeOnExit',
|
||||
windowSize = 'windowSize',
|
||||
windowPosition = 'windowPosition';
|
||||
|
||||
static const String subtitlePreferenceV2 = 'subtitlePreferenceV2',
|
||||
enableDragSubtitle = 'enableDragSubtitle',
|
||||
|
||||
@@ -815,4 +815,12 @@ abstract class Pref {
|
||||
|
||||
static bool get minimizeOnExit =>
|
||||
_setting.get(SettingBoxKey.minimizeOnExit, defaultValue: true);
|
||||
|
||||
static List<double> get windowSize => _setting.get(
|
||||
SettingBoxKey.windowSize,
|
||||
defaultValue: const [1180.0, 720.0],
|
||||
);
|
||||
|
||||
static List<double>? get windowPosition =>
|
||||
_setting.get(SettingBoxKey.windowPosition);
|
||||
}
|
||||
|
||||
@@ -115,15 +115,15 @@ abstract class Utils {
|
||||
);
|
||||
}
|
||||
|
||||
static void copyText(
|
||||
static Future<void> copyText(
|
||||
String text, {
|
||||
bool needToast = true,
|
||||
String? toastText,
|
||||
}) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
if (needToast) {
|
||||
SmartDialog.showToast(toastText ?? '已复制');
|
||||
}
|
||||
return Clipboard.setData(ClipboardData(text: text));
|
||||
}
|
||||
|
||||
static String makeHeroTag(v) {
|
||||
|
||||
Reference in New Issue
Block a user