11import os
2+ from copy import deepcopy
23from typing import TYPE_CHECKING , TypedDict , cast
34
45import toml
56from PySide6 import QtCore , QtWidgets
7+ from typing_extensions import deprecated , override
68
79import error_messages
810from capture_method import CAPTURE_METHODS , CaptureMethodEnum , Region , change_capture_method
@@ -40,6 +42,10 @@ class UserProfileDict(TypedDict):
4042 captured_window_title : str
4143 capture_region : Region
4244
45+ @override # pyright: ignore
46+ @deprecated ("Use `copy.deepcopy` instead" )
47+ def copy (): return super ().copy ()
48+
4349
4450DEFAULT_PROFILE = UserProfileDict (
4551 split_hotkey = "" ,
@@ -70,10 +76,7 @@ class UserProfileDict(TypedDict):
7076
7177
7278def have_settings_changed (autosplit : "AutoSplit" ):
73- return (
74- autosplit .settings_dict != autosplit .last_saved_settings
75- or autosplit .settings_dict != autosplit .last_loaded_settings
76- )
79+ return autosplit .settings_dict != autosplit .last_saved_settings
7780
7881
7982def save_settings (autosplit : "AutoSplit" ):
@@ -95,6 +98,7 @@ def save_settings_as(autosplit: "AutoSplit"):
9598 or os .path .join (auto_split_directory , "settings.toml" ),
9699 "TOML (*.toml)" ,
97100 )[0 ]
101+
98102 # If user cancels save destination window, don't save settings
99103 if not save_settings_file_path :
100104 return ""
@@ -103,10 +107,10 @@ def save_settings_as(autosplit: "AutoSplit"):
103107
104108
105109def __save_settings_to_file (autosplit : "AutoSplit" , save_settings_file_path : str ):
106- autosplit .last_saved_settings = autosplit .settings_dict
107110 # Save settings to a .toml file
108111 with open (save_settings_file_path , "w" , encoding = "utf-8" ) as file :
109- toml .dump (autosplit .last_saved_settings , file )
112+ toml .dump (autosplit .settings_dict , file )
113+ autosplit .last_saved_settings = deepcopy (autosplit .settings_dict )
110114 autosplit .last_successfully_loaded_settings_file_path = save_settings_file_path
111115 return save_settings_file_path
112116
@@ -120,9 +124,10 @@ def __load_settings_from_file(autosplit: "AutoSplit", load_settings_file_path: s
120124 # Casting here just so we can build an actual UserProfileDict once we're done validating
121125 # Fallback to default settings if some are missing from the file. This happens when new settings are added.
122126 loaded_settings = DEFAULT_PROFILE | cast (UserProfileDict , toml .load (file ))
127+
123128 # TODO: Data Validation / fallbacks ?
124129 autosplit .settings_dict = UserProfileDict (** loaded_settings )
125- autosplit .last_loaded_settings = autosplit .settings_dict
130+ autosplit .last_saved_settings = deepcopy ( autosplit .settings_dict )
126131
127132 autosplit .x_spinbox .setValue (autosplit .settings_dict ["capture_region" ]["x" ])
128133 autosplit .y_spinbox .setValue (autosplit .settings_dict ["capture_region" ]["y" ])
0 commit comments