Update to not create default config as RNS does that (should), also update to config name.
This commit is contained in:
@@ -28,11 +28,9 @@ def log_ret(msg, *args, **kwargs):
|
|||||||
def setup_rns_logging():
|
def setup_rns_logging():
|
||||||
"""Set up RNS log replacement. Call this after RNS.Reticulum initialization."""
|
"""Set up RNS log replacement. Call this after RNS.Reticulum initialization."""
|
||||||
global _original_rns_log
|
global _original_rns_log
|
||||||
_original_rns_log = RNS.log
|
if _original_rns_log != log_ret: # Prevent recursion
|
||||||
RNS.log = log_ret
|
_original_rns_log = RNS.log
|
||||||
|
RNS.log = log_ret
|
||||||
# Initial setup
|
|
||||||
setup_rns_logging()
|
|
||||||
|
|
||||||
def log_error(msg: str):
|
def log_error(msg: str):
|
||||||
"""Log error messages to both error and application logs.
|
"""Log error messages to both error and application logs.
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ class StorageManager:
|
|||||||
# Desktop (Linux, Windows, macOS) - use home directory
|
# Desktop (Linux, Windows, macOS) - use home directory
|
||||||
if "APPDATA" in os.environ: # Windows
|
if "APPDATA" in os.environ: # Windows
|
||||||
storage_dir = pathlib.Path(os.environ["APPDATA"]) / "ren_browser"
|
storage_dir = pathlib.Path(os.environ["APPDATA"]) / "ren_browser"
|
||||||
|
elif "XDG_CONFIG_HOME" in os.environ: # Linux XDG standard
|
||||||
|
storage_dir = pathlib.Path(os.environ["XDG_CONFIG_HOME"]) / "ren_browser"
|
||||||
else:
|
else:
|
||||||
storage_dir = pathlib.Path.home() / ".ren_browser"
|
storage_dir = pathlib.Path.home() / ".ren_browser"
|
||||||
|
|
||||||
@@ -61,13 +63,20 @@ class StorageManager:
|
|||||||
|
|
||||||
def get_config_path(self) -> pathlib.Path:
|
def get_config_path(self) -> pathlib.Path:
|
||||||
"""Get the path to the main configuration file."""
|
"""Get the path to the main configuration file."""
|
||||||
return self._storage_dir / "config.txt"
|
return self._storage_dir / "config"
|
||||||
|
|
||||||
def get_reticulum_config_path(self) -> pathlib.Path:
|
def get_reticulum_config_path(self) -> pathlib.Path:
|
||||||
"""Get the path to the Reticulum configuration directory."""
|
"""Get the path to the Reticulum configuration directory."""
|
||||||
config_dir = self._storage_dir / "reticulum"
|
# Check for global override from app
|
||||||
config_dir.mkdir(exist_ok=True)
|
try:
|
||||||
return config_dir
|
from ren_browser.app import RNS_CONFIG_DIR
|
||||||
|
if RNS_CONFIG_DIR:
|
||||||
|
return pathlib.Path(RNS_CONFIG_DIR)
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Default to standard RNS config directory
|
||||||
|
return pathlib.Path.home() / ".reticulum"
|
||||||
|
|
||||||
def save_config(self, config_content: str) -> bool:
|
def save_config(self, config_content: str) -> bool:
|
||||||
"""Save configuration content to file.
|
"""Save configuration content to file.
|
||||||
@@ -83,12 +92,14 @@ class StorageManager:
|
|||||||
if self.page and hasattr(self.page, "client_storage"):
|
if self.page and hasattr(self.page, "client_storage"):
|
||||||
self.page.client_storage.set("ren_browser_config", config_content)
|
self.page.client_storage.set("ren_browser_config", config_content)
|
||||||
|
|
||||||
|
# Save to reticulum config directory for RNS to use
|
||||||
|
reticulum_config_path = self.get_reticulum_config_path() / "config"
|
||||||
|
reticulum_config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
reticulum_config_path.write_text(config_content, encoding="utf-8")
|
||||||
|
|
||||||
|
# Also save to local config path as backup
|
||||||
config_path = self.get_config_path()
|
config_path = self.get_config_path()
|
||||||
config_path.write_text(config_content, encoding="utf-8")
|
config_path.write_text(config_content, encoding="utf-8")
|
||||||
|
|
||||||
# Also save to reticulum config directory for RNS to use
|
|
||||||
reticulum_config_path = self.get_reticulum_config_path() / "config"
|
|
||||||
reticulum_config_path.write_text(config_content, encoding="utf-8")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except (OSError, PermissionError, UnicodeEncodeError) as e:
|
except (OSError, PermissionError, UnicodeEncodeError) as e:
|
||||||
@@ -121,11 +132,9 @@ class StorageManager:
|
|||||||
"""Load configuration content from storage.
|
"""Load configuration content from storage.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Configuration text, or default config if not found
|
Configuration text, or empty string if not found
|
||||||
|
|
||||||
"""
|
"""
|
||||||
default_config = """default config"""
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reticulum_config_path = self.get_reticulum_config_path() / "config"
|
reticulum_config_path = self.get_reticulum_config_path() / "config"
|
||||||
if reticulum_config_path.exists():
|
if reticulum_config_path.exists():
|
||||||
@@ -143,7 +152,7 @@ class StorageManager:
|
|||||||
except (OSError, PermissionError, UnicodeDecodeError):
|
except (OSError, PermissionError, UnicodeDecodeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return default_config
|
return ""
|
||||||
|
|
||||||
def save_bookmarks(self, bookmarks: list) -> bool:
|
def save_bookmarks(self, bookmarks: list) -> bool:
|
||||||
"""Save bookmarks to storage."""
|
"""Save bookmarks to storage."""
|
||||||
@@ -261,6 +270,5 @@ def get_rns_config_directory() -> str:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Fallback to default storage manager behavior
|
# Default to standard RNS config directory
|
||||||
storage = get_storage_manager()
|
return str(pathlib.Path.home() / ".reticulum")
|
||||||
return str(storage.get_reticulum_config_path())
|
|
||||||
|
|||||||
Reference in New Issue
Block a user