Skip to content

Commit

Permalink
Added geometry saving logic
Browse files Browse the repository at this point in the history
  • Loading branch information
brookite committed Feb 11, 2023
1 parent 26f869a commit c855735
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/appinfo.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_NAME = "1.0 RC2"
BUILD_NUMBER = 1156
VERSION_NAME = "1.0 RC3"
BUILD_NUMBER = 1158
10 changes: 8 additions & 2 deletions app/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ def backup(self, output_path, save_thumbnails=False) -> None:
zipobj.write(filepath, zippath)

def restore(self, backup_path, save_thumbnails=False) -> bool:
oldBackupPath = self.config["autobackupPath"]
restore_keys = {
"autobackupPath": self.config["autobackupPath"]
}
if "geometry" in self.config:
restore_keys["geometry"] = self.config["geometry"]

try:
if commonpath(
[os.path.abspath(backup_path), self.root]) == self.root:
Expand All @@ -214,7 +219,8 @@ def restore(self, backup_path, save_thumbnails=False) -> bool:
self.create_files()
self.config = BooksConfig(self, os.path.join(self.root, "books.json"))
self.book_paths = self._read_book_paths()
self.config["autobackupPath"] = oldBackupPath
for key, value in restore_keys.items():
self.config[key] = value
self.config.save()
return True
except Exception:
Expand Down
10 changes: 10 additions & 0 deletions app/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def __init__(self, app):
if self.settings.config["shelfs"][0]["name"] != "$DEFAULT_NAME":
self.tabWidget.setTabText(0, self.settings.config["shelfs"][0]["name"])

self.restore_geometry()

def closeEvent(self, event: QCloseEvent) -> None:
self.store_geometry()
self.settings.save()
filename = self.settings.config["autobackupPath"]
if os.path.exists(os.path.dirname(filename)) and filename.strip():
Expand All @@ -92,6 +95,13 @@ def timerEvent(self, event: QTimerEvent) -> None:
shelf.row_capacity = self.size().width() // 128
self.get_current_shelf().render_books()

def store_geometry(self):
self.settings.config["geometry"] = [self.x(), self.y(), self.width(), self.height()]

def restore_geometry(self):
if "geometry" in self.settings.config:
self.setGeometry(*self.settings.config["geometry"])

def check_autorecover(self):
if self.settings.config["recoverAutobackup"]:
path = self.settings.config["autobackupPath"]
Expand Down

0 comments on commit c855735

Please sign in to comment.