Fix window size restore problems on macOS

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2025-06-24 01:07:14 +08:00
parent 8c41a2180f
commit 0ae6426688
2 changed files with 32 additions and 4 deletions
+31 -3
View File
@@ -100,6 +100,11 @@ class AppNetworkStateManager(NetworkStateManager):
class AppMainWindow(AppQMainWindow):
DEFAULT_WINDOW_SIZE_DARWIN = QtCore.QSize(1500, 780)
DEFAULT_WINDOW_SIZE = (
QtCore.QSize(1800, 960) if PLATFORM != 'Darwin' else DEFAULT_WINDOW_SIZE_DARWIN
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -474,18 +479,23 @@ class AppMainWindow(AppQMainWindow):
try:
windowSize = AppSettings.get('ServerWidgetWindowSize').split(',')
self.resize(*list(int(size) for size in windowSize))
width, height = tuple(int(size) for size in windowSize)
if (width, height) == (640, 480):
self.resize(AppMainWindow.DEFAULT_WINDOW_SIZE)
else:
self.resize(width, height)
except Exception:
# Any non-exit exceptions
self.resize(1800, 960)
self.resize(AppMainWindow.DEFAULT_WINDOW_SIZE)
else:
try:
self.restoreGeometry(AppSettings.get('AppMainWindowGeometry'))
except Exception:
# Any non-exit exceptions
pass
self.resize(AppMainWindow.DEFAULT_WINDOW_SIZE)
try:
self.restoreState(AppSettings.get('AppMainWindowState'))
@@ -494,6 +504,24 @@ class AppMainWindow(AppQMainWindow):
pass
if PLATFORM == 'Darwin':
APP().processEvents()
size = self.size()
if size == QtCore.QSize(640, 480):
logger.error(
f'detected unresolve Qt bug on macOS. '
f'Resizing main window to default '
f'{AppMainWindow.DEFAULT_WINDOW_SIZE.toTuple()}'
)
self.resize(AppMainWindow.DEFAULT_WINDOW_SIZE)
else:
logger.info(
f'restore main window size on macOS success: '
f'{size.toTuple()}'
)
def cleanup(self):
AppSettings.set('AppMainWindowGeometry', self.saveGeometry())
AppSettings.set('AppMainWindowState', self.saveState())
+1 -1
View File
@@ -180,7 +180,7 @@ class UserSubsWindow(AppQMainWindow):
except Exception:
# Any non-exit exceptions
self.resize(UserSubsWindow.DEFAULT_WINDOW_SIZE)
pass
def cleanup(self):
AppSettings.set('UserSubsWindowGeometry', self.saveGeometry())