def get_settings(self):
        settings_path = MiscUtils.get_settings_path()
        settings: Settings = None

        if os.path.exists(settings_path) and os.path.isfile(settings_path):
            with open(settings_path) as file:
                try:
                    settings_dict = json.load(file)
                    settings = Settings()
                    for key in settings_dict:
                        if key in settings.__dict__:  # Don't keep stale keys
                            settings.__dict__[key] = settings_dict[key]
                except:
                    logging.exception(
                        "Failed to load settings from JSON file. Restoring defaults."
                    )

        if settings is None:
            settings = Settings()
            self.save_settings(settings)

        return settings
 def save_settings(self, settings: Settings):
     settings_path = MiscUtils.get_settings_path()
     with open(settings_path, 'w') as file:
         data = settings.__dict__
         json.dump(data, file, sort_keys=True, indent=4)