53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
import keyring
|
|
import json
|
|
import os
|
|
|
|
class SettingsManager:
|
|
def __init__(self, project_info):
|
|
# project_info의 'name'을 보안 저장소의 SERVICE_NAME으로 사용
|
|
self.service_name = project_info.get("name", "App")
|
|
|
|
def save_user_info(self, user_info: dict):
|
|
email = user_info.get("email", "")
|
|
password = user_info.get("password", "")
|
|
if email and password:
|
|
keyring.set_password(self.service_name, email, password)
|
|
# 민감하지 않은 정보만 JSON 파일에 저장
|
|
non_sensitive = {k: v for k, v in user_info.items() if k != "password"}
|
|
try:
|
|
with open("user_settings.json", "w", encoding="utf-8") as f:
|
|
json.dump(non_sensitive, f, indent=4, ensure_ascii=False)
|
|
except Exception as e:
|
|
print("사용자 설정 저장 중 오류:", e)
|
|
|
|
def load_user_info(self) -> dict:
|
|
user_info = {}
|
|
if os.path.exists("user_settings.json"):
|
|
try:
|
|
with open("user_settings.json", "r", encoding="utf-8") as f:
|
|
user_info = json.load(f)
|
|
except Exception as e:
|
|
print("사용자 설정 불러오기 오류:", e)
|
|
email = user_info.get("email", "")
|
|
if email:
|
|
password = keyring.get_password(self.service_name, email)
|
|
if password:
|
|
user_info["password"] = password
|
|
return user_info
|
|
|
|
def save_gui_settings(self, gui_settings: dict):
|
|
try:
|
|
with open("gui_settings.json", "w", encoding="utf-8") as f:
|
|
json.dump(gui_settings, f, indent=4, ensure_ascii=False)
|
|
except Exception as e:
|
|
print("GUI 설정 저장 중 오류:", e)
|
|
|
|
def load_gui_settings(self) -> dict:
|
|
if os.path.exists("gui_settings.json"):
|
|
try:
|
|
with open("gui_settings.json", "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
except Exception as e:
|
|
print("GUI 설정 불러오기 오류:", e)
|
|
return {}
|