mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-26 11:08:44 +00: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 {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
MediaKit.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);
|
Get.lazyPut(AccountService.new);
|
||||||
HttpOverrides.global = _CustomHttpOverrides();
|
HttpOverrides.global = _CustomHttpOverrides();
|
||||||
|
|
||||||
@@ -78,15 +84,23 @@ void main() async {
|
|||||||
);
|
);
|
||||||
} else if (Utils.isDesktop) {
|
} else if (Utils.isDesktop) {
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
WindowOptions windowOptions = const WindowOptions(
|
final windowSize = Pref.windowSize;
|
||||||
minimumSize: Size(400, 720),
|
final windowPosition = Pref.windowPosition;
|
||||||
size: Size(1180, 720),
|
final hasPos = windowPosition != null;
|
||||||
center: true,
|
WindowOptions windowOptions = WindowOptions(
|
||||||
|
minimumSize: const Size(400, 720),
|
||||||
|
size: Size(windowSize[0], windowSize[1]),
|
||||||
|
center: !hasPos,
|
||||||
skipTaskbar: false,
|
skipTaskbar: false,
|
||||||
titleBarStyle: TitleBarStyle.normal,
|
titleBarStyle: TitleBarStyle.normal,
|
||||||
title: Constants.appName,
|
title: Constants.appName,
|
||||||
);
|
);
|
||||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
|
if (hasPos) {
|
||||||
|
await windowManager.setPosition(
|
||||||
|
Offset(windowPosition[0], windowPosition[1]),
|
||||||
|
);
|
||||||
|
}
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import 'package:PiliPlus/utils/context_ext.dart';
|
|||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/page_utils.dart';
|
import 'package:PiliPlus/utils/page_utils.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
|
import 'package:PiliPlus/utils/storage_key.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -96,6 +97,32 @@ class _MainAppState extends State<MainApp>
|
|||||||
super.dispose();
|
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
|
@override
|
||||||
void onWindowClose() {
|
void onWindowClose() {
|
||||||
if (_mainController.minimizeOnExit) {
|
if (_mainController.minimizeOnExit) {
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ abstract class SettingBoxKey {
|
|||||||
showFsLockBtn = 'showFsLockBtn',
|
showFsLockBtn = 'showFsLockBtn',
|
||||||
silentDownImg = 'silentDownImg',
|
silentDownImg = 'silentDownImg',
|
||||||
showMemberShop = 'showMemberShop',
|
showMemberShop = 'showMemberShop',
|
||||||
minimizeOnExit = 'minimizeOnExit';
|
minimizeOnExit = 'minimizeOnExit',
|
||||||
|
windowSize = 'windowSize',
|
||||||
|
windowPosition = 'windowPosition';
|
||||||
|
|
||||||
static const String subtitlePreferenceV2 = 'subtitlePreferenceV2',
|
static const String subtitlePreferenceV2 = 'subtitlePreferenceV2',
|
||||||
enableDragSubtitle = 'enableDragSubtitle',
|
enableDragSubtitle = 'enableDragSubtitle',
|
||||||
|
|||||||
@@ -815,4 +815,12 @@ abstract class Pref {
|
|||||||
|
|
||||||
static bool get minimizeOnExit =>
|
static bool get minimizeOnExit =>
|
||||||
_setting.get(SettingBoxKey.minimizeOnExit, defaultValue: true);
|
_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, {
|
String text, {
|
||||||
bool needToast = true,
|
bool needToast = true,
|
||||||
String? toastText,
|
String? toastText,
|
||||||
}) {
|
}) {
|
||||||
Clipboard.setData(ClipboardData(text: text));
|
|
||||||
if (needToast) {
|
if (needToast) {
|
||||||
SmartDialog.showToast(toastText ?? '已复制');
|
SmartDialog.showToast(toastText ?? '已复制');
|
||||||
}
|
}
|
||||||
|
return Clipboard.setData(ClipboardData(text: text));
|
||||||
}
|
}
|
||||||
|
|
||||||
static String makeHeroTag(v) {
|
static String makeHeroTag(v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user