You've already forked OneDriveGUI
mirror of
https://github.com/bpozdena/OneDriveGUI.git
synced 2026-10-24 04:59:17 +03:00
Remember the window size and position between sessions
New setting "Remember window size and position" (enabled by default). The main window geometry is saved when the window is hidden to the tray, closed or when the application quits, and restored on the next start instead of always opening at the default position. The tooltip notes that on Wayland the compositor controls the position and it may not be restored exactly. Fixes #280
This commit is contained in:
@@ -34,6 +34,9 @@ class GuiSettingsWindow(QWidget, Ui_gui_settings_window):
|
||||
self.checkBox_stop_clients_on_exit.setChecked(self.get_check_box_state("stop_clients_on_exit"))
|
||||
self.checkBox_stop_clients_on_exit.stateChanged.connect(self.set_check_box_state)
|
||||
|
||||
self.checkBox_remember_window_geometry.setChecked(self.get_check_box_state("remember_window_geometry"))
|
||||
self.checkBox_remember_window_geometry.stateChanged.connect(self.set_check_box_state)
|
||||
|
||||
self.lineEdit_client_bin_path.setText(gui_settings.get("client_bin_path"))
|
||||
self.lineEdit_client_bin_path.textChanged.connect(self.set_client_bin_path)
|
||||
self.pushButton_client_bin_path.clicked.connect(self.get_bin_path)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from PySide6.QtCore import QTimer, QUrl, QFileInfo, Qt, Signal, Slot
|
||||
from PySide6.QtCore import QTimer, QUrl, QFileInfo, Qt, Signal, Slot, QByteArray
|
||||
from PySide6.QtGui import QIcon, QPixmap, QDesktopServices
|
||||
from PySide6.QtWidgets import (
|
||||
QWidget,
|
||||
@@ -220,6 +220,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
# Whether the clients are stopped (or left running in the background) is
|
||||
# controlled by the 'stop_clients_on_exit' setting.
|
||||
QApplication.instance().aboutToQuit.connect(self.stop_all_workers)
|
||||
QApplication.instance().aboutToQuit.connect(self.save_window_geometry)
|
||||
|
||||
# Restore the window size and position from the previous session.
|
||||
stored_geometry = gui_settings.get("window_geometry")
|
||||
if gui_settings.get("remember_window_geometry") != "False" and stored_geometry:
|
||||
self.restoreGeometry(QByteArray.fromBase64(stored_geometry.encode()))
|
||||
|
||||
# End-of-session signals: the desktop environment sends SIGTERM/SIGHUP to
|
||||
# the session processes on logout. The Python handler only schedules the
|
||||
@@ -315,6 +321,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
elif close_question == QMessageBox.No:
|
||||
logging.info("[GUI] Keeping OneDriveGUI running.")
|
||||
|
||||
def save_window_geometry(self):
|
||||
"""Persist the window size and position for the next session."""
|
||||
if gui_settings.get("remember_window_geometry") != "False" and not self.isMinimized():
|
||||
gui_settings.set("window_geometry", bytes(self.saveGeometry().toBase64()).decode())
|
||||
gui_settings.save()
|
||||
|
||||
def stop_all_workers(self, force=False):
|
||||
"""
|
||||
Stop every running worker and its OneDrive client.
|
||||
@@ -346,6 +358,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Minimize main window to system tray if it is available. Otherwise minimize to taskbar.
|
||||
self.save_window_geometry()
|
||||
event.ignore()
|
||||
try:
|
||||
if self.tray.isSystemTrayAvailable():
|
||||
@@ -1782,6 +1795,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.show()
|
||||
|
||||
def hide_main_window(self):
|
||||
self.save_window_geometry()
|
||||
self.hide()
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ class GuiSettings:
|
||||
"client_bin_path": "onedrive",
|
||||
"QWebEngine_login": "False",
|
||||
"stop_clients_on_exit": "True",
|
||||
"remember_window_geometry": "True",
|
||||
"window_geometry": "",
|
||||
"autostart_enabled": "False",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_remember_window_geometry">
|
||||
<property name="toolTip">
|
||||
<string>Restore the size and position of the OneDriveGUI window from the previous session.<br/>Note: on Wayland, the position is controlled by the compositor and may not be restored exactly.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remember window size and position</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_start_minimized">
|
||||
|
||||
@@ -46,6 +46,11 @@ class Ui_gui_settings_window(object):
|
||||
|
||||
self.formLayout.setWidget(2, QFormLayout.ItemRole.LabelRole, self.checkBox_stop_clients_on_exit)
|
||||
|
||||
self.checkBox_remember_window_geometry = QCheckBox(self.groupBox)
|
||||
self.checkBox_remember_window_geometry.setObjectName(u"checkBox_remember_window_geometry")
|
||||
|
||||
self.formLayout.setWidget(3, QFormLayout.ItemRole.LabelRole, self.checkBox_remember_window_geometry)
|
||||
|
||||
self.checkBox_start_minimized = QCheckBox(self.groupBox)
|
||||
self.checkBox_start_minimized.setObjectName(u"checkBox_start_minimized")
|
||||
|
||||
@@ -241,6 +246,10 @@ class Ui_gui_settings_window(object):
|
||||
self.checkBox_stop_clients_on_exit.setToolTip(QCoreApplication.translate("gui_settings_window", u"Stop the OneDrive client of every profile when OneDriveGUI exits or the session logs out. The client finishes in-flight transfers before it exits.<br/>When disabled, the clients keep running in the background; OneDriveGUI offers to reconnect to them on the next start.", None))
|
||||
#endif // QT_CONFIG(tooltip)
|
||||
self.checkBox_stop_clients_on_exit.setText(QCoreApplication.translate("gui_settings_window", u"Stop OneDrive clients when OneDriveGUI exits", None))
|
||||
#if QT_CONFIG(tooltip)
|
||||
self.checkBox_remember_window_geometry.setToolTip(QCoreApplication.translate("gui_settings_window", u"Restore the size and position of the OneDriveGUI window from the previous session.<br/>Note: on Wayland, the position is controlled by the compositor and may not be restored exactly.", None))
|
||||
#endif // QT_CONFIG(tooltip)
|
||||
self.checkBox_remember_window_geometry.setText(QCoreApplication.translate("gui_settings_window", u"Remember window size and position", None))
|
||||
self.checkBox_start_minimized.setText(QCoreApplication.translate("gui_settings_window", u"Start OneDriveGUI minimized", None))
|
||||
self.checkBox_autostart_enabled.setText(QCoreApplication.translate("gui_settings_window", u"Start OneDriveGUI automatically on login", None))
|
||||
self.groupBox_4.setTitle(QCoreApplication.translate("gui_settings_window", u"OneDrive client options", None))
|
||||
|
||||
Reference in New Issue
Block a user