✨ Memorable window size
This commit is contained in:
		@@ -937,5 +937,7 @@
 | 
			
		||||
  "settingsAprilFoolFeatures": "April Fool Features",
 | 
			
		||||
  "settingsAprilFoolFeaturesDescription": "Enable April Fool features during April Fool, this option will only be visible during April Fool.",
 | 
			
		||||
  "settingsSoundEffects": "Sound Effects",
 | 
			
		||||
  "settingsSoundEffectsDescription": "Enable the sound effects around the app."
 | 
			
		||||
  "settingsSoundEffectsDescription": "Enable the sound effects around the app.",
 | 
			
		||||
  "settingsResetMemorizedWindowSize": "Reset Window Size",
 | 
			
		||||
  "settingsResetMemorizedWindowSizeDescription": "Reset the memorized window size, and set it to the default size."
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -934,5 +934,7 @@
 | 
			
		||||
  "settingsAprilFoolFeatures": "愚人节特性",
 | 
			
		||||
  "settingsAprilFoolFeaturesDescription": "在愚人节期间启用愚人节特性,该选项只会在愚人节期间显示。",
 | 
			
		||||
  "settingsSoundEffects": "声音效果",
 | 
			
		||||
  "settingsSoundEffectsDescription": "在一些场合下启用声音特效。"
 | 
			
		||||
  "settingsSoundEffectsDescription": "在一些场合下启用声音特效。",
 | 
			
		||||
  "settingsResetMemorizedWindowSize": "重置窗口大小",
 | 
			
		||||
  "settingsResetMemorizedWindowSizeDescription": "重置记忆的窗口大小,以重新设置为默认大小。"
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -75,13 +75,40 @@ void appBackgroundDispatcher() {
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Desktop size tools
 | 
			
		||||
 | 
			
		||||
Future<Size> _getSavedWindowSize() async {
 | 
			
		||||
  final prefs = await SharedPreferences.getInstance();
 | 
			
		||||
  String? sizeString = prefs.getString(kAppWindowSize);
 | 
			
		||||
 | 
			
		||||
  if (sizeString != null) {
 | 
			
		||||
    List<String> parts = sizeString.split('x');
 | 
			
		||||
    if (parts.length == 2) {
 | 
			
		||||
      double? width = double.tryParse(parts[0]);
 | 
			
		||||
      double? height = double.tryParse(parts[1]);
 | 
			
		||||
      if (width != null && height != null) {
 | 
			
		||||
        return Size(width, height);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return const Size(1280, 720); // Default size
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Future<void> _saveWindowSize() async {
 | 
			
		||||
  final prefs = await SharedPreferences.getInstance();
 | 
			
		||||
  final size = appWindow.size;
 | 
			
		||||
  await prefs.setString(kAppWindowSize, '${size.width}x${size.height}');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void main() async {
 | 
			
		||||
  WidgetsFlutterBinding.ensureInitialized();
 | 
			
		||||
 | 
			
		||||
  if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
 | 
			
		||||
    final Size savedSize = await _getSavedWindowSize();
 | 
			
		||||
    doWhenWindowReady(() {
 | 
			
		||||
      appWindow.minSize = Size(480, 640);
 | 
			
		||||
      appWindow.size = Size(1280, 720);
 | 
			
		||||
      appWindow.size = savedSize;
 | 
			
		||||
      appWindow.alignment = Alignment.center;
 | 
			
		||||
      appWindow.show();
 | 
			
		||||
    });
 | 
			
		||||
@@ -211,7 +238,9 @@ class _AppDelegate extends StatelessWidget {
 | 
			
		||||
      routerConfig: appRouter,
 | 
			
		||||
      builder: (context, child) {
 | 
			
		||||
        return _AppSplashScreen(
 | 
			
		||||
            key: const Key('global-splash-screen'), child: child!);
 | 
			
		||||
          key: const Key('global-splash-screen'),
 | 
			
		||||
          child: child!,
 | 
			
		||||
        );
 | 
			
		||||
      },
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
@@ -444,6 +473,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _quitApp() {
 | 
			
		||||
    _saveWindowSize();
 | 
			
		||||
    _appLifecycleListener?.dispose();
 | 
			
		||||
    if (Platform.isWindows) {
 | 
			
		||||
      appWindow.close();
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ const kAppAutoTranslate = 'app_auto_translate';
 | 
			
		||||
const kAppHideBottomNav = 'app_hide_bottom_nav';
 | 
			
		||||
const kAppSoundEffects = 'app_sound_effects';
 | 
			
		||||
const kAppAprilFoolFeatures = 'app_april_fool_features';
 | 
			
		||||
const kAppWindowSize = 'app_window_size';
 | 
			
		||||
 | 
			
		||||
const Map<String, FilterQuality> kImageQualityLevel = {
 | 
			
		||||
  'settingsImageQualityLowest': FilterQuality.none,
 | 
			
		||||
 
 | 
			
		||||
@@ -363,6 +363,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
 | 
			
		||||
                  subtitle: Text('settingsSoundEffectsDescription').tr(),
 | 
			
		||||
                  secondary: const Icon(Symbols.sound_sampler),
 | 
			
		||||
                ),
 | 
			
		||||
                if (!kIsWeb && !(Platform.isAndroid || Platform.isIOS))
 | 
			
		||||
                  ListTile(
 | 
			
		||||
                    leading: const Icon(Symbols.window),
 | 
			
		||||
                    title: Text('settingsResetMemorizedWindowSize').tr(),
 | 
			
		||||
                    subtitle:
 | 
			
		||||
                        Text('settingsResetMemorizedWindowSizeDescription')
 | 
			
		||||
                            .tr(),
 | 
			
		||||
                    trailing: const Icon(Symbols.chevron_right),
 | 
			
		||||
                    contentPadding: const EdgeInsets.only(left: 24, right: 24),
 | 
			
		||||
                    onTap: () {
 | 
			
		||||
                      final prefs = context.read<ConfigProvider>().prefs;
 | 
			
		||||
                      prefs.remove(kAppWindowSize);
 | 
			
		||||
                    },
 | 
			
		||||
                  ),
 | 
			
		||||
                ListTile(
 | 
			
		||||
                  leading: const Icon(Symbols.font_download),
 | 
			
		||||
                  title: Text('settingsCustomFonts').tr(),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user