Update for desktop executable file
This commit is contained in:
+1075
-4
File diff suppressed because it is too large
Load Diff
+51
-2
@@ -60,6 +60,8 @@ class ImportSettings:
|
|||||||
date_format: str = "%Y-%m-%d"
|
date_format: str = "%Y-%m-%d"
|
||||||
decimal_separator: str = "."
|
decimal_separator: str = "."
|
||||||
thousand_separator: str = ","
|
thousand_separator: str = ","
|
||||||
|
skip_empty_rows: bool = True
|
||||||
|
stop_on_error: bool = False
|
||||||
|
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
@@ -87,8 +89,36 @@ class Settings:
|
|||||||
|
|
||||||
def _get_config_dir(self) -> Path:
|
def _get_config_dir(self) -> Path:
|
||||||
"""Get platform-specific config directory."""
|
"""Get platform-specific config directory."""
|
||||||
# For web app, use a local directory
|
import sys
|
||||||
|
|
||||||
|
# Use user's AppData folder for persistent storage
|
||||||
|
# This works correctly for both normal Python and PyInstaller executables
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
# Windows: Use AppData/Local
|
||||||
|
app_data = os.environ.get('LOCALAPPDATA')
|
||||||
|
if app_data:
|
||||||
|
return Path(app_data) / self.APP_NAME
|
||||||
|
# Fallback to APPDATA if LOCALAPPDATA not available
|
||||||
|
app_data = os.environ.get('APPDATA')
|
||||||
|
if app_data:
|
||||||
|
return Path(app_data) / self.APP_NAME
|
||||||
|
elif sys.platform == 'darwin':
|
||||||
|
# macOS: Use ~/Library/Application Support
|
||||||
|
home = Path.home()
|
||||||
|
return home / "Library" / "Application Support" / self.APP_NAME
|
||||||
|
else:
|
||||||
|
# Linux/Unix: Use ~/.config
|
||||||
|
home = Path.home()
|
||||||
|
return home / ".config" / self.APP_NAME.lower()
|
||||||
|
|
||||||
|
# Final fallback: Use a 'data' folder relative to executable/script
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
# Running as PyInstaller executable
|
||||||
|
base = Path(sys.executable).parent
|
||||||
|
else:
|
||||||
|
# Running as script
|
||||||
base = Path(__file__).parent.parent.parent
|
base = Path(__file__).parent.parent.parent
|
||||||
|
|
||||||
return base / "data"
|
return base / "data"
|
||||||
|
|
||||||
def _load_config(self) -> Dict[str, Any]:
|
def _load_config(self) -> Dict[str, Any]:
|
||||||
@@ -136,6 +166,21 @@ class Settings:
|
|||||||
self.save()
|
self.save()
|
||||||
logger.info("Import settings updated")
|
logger.info("Import settings updated")
|
||||||
|
|
||||||
|
def get_import_settings(self) -> ImportSettings:
|
||||||
|
"""Get import settings (method version for compatibility)."""
|
||||||
|
try:
|
||||||
|
settings_data = self._config.get("import_settings", {})
|
||||||
|
return ImportSettings(**settings_data)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Error loading import settings: {e}")
|
||||||
|
return ImportSettings()
|
||||||
|
|
||||||
|
def save_import_settings(self, settings: ImportSettings):
|
||||||
|
"""Save import settings (method version for compatibility)."""
|
||||||
|
self._config["import_settings"] = asdict(settings)
|
||||||
|
self.save()
|
||||||
|
logger.info("Import settings saved")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def recent_files(self) -> List[str]:
|
def recent_files(self) -> List[str]:
|
||||||
"""Get list of recently opened files."""
|
"""Get list of recently opened files."""
|
||||||
@@ -186,7 +231,11 @@ class Settings:
|
|||||||
try:
|
try:
|
||||||
with open(self.credentials_file, 'w') as f:
|
with open(self.credentials_file, 'w') as f:
|
||||||
json.dump(asdict(credentials), f)
|
json.dump(asdict(credentials), f)
|
||||||
os.chmod(self.credentials_file, 0o600) # Restrict permissions
|
# Restrict file permissions (Unix only, skip on Windows)
|
||||||
|
try:
|
||||||
|
os.chmod(self.credentials_file, 0o600)
|
||||||
|
except (OSError, AttributeError):
|
||||||
|
pass # chmod not supported on Windows
|
||||||
logger.info("Credentials saved successfully")
|
logger.info("Credentials saved successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to save credentials: {e}")
|
logger.error(f"Failed to save credentials: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user