From ed74e97693be052a55ce9a4c9e9bf38c4c97b453 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 May 2026 10:53:09 +0000 Subject: [PATCH] config v1.1 --- config/settings.py | 268 +++++++++++++++------------------------------ 1 file changed, 87 insertions(+), 181 deletions(-) diff --git a/config/settings.py b/config/settings.py index 78b6b18..9996cdb 100644 --- a/config/settings.py +++ b/config/settings.py @@ -1,34 +1,62 @@ -# v3.1.1 settings.py +# v4.0.0 settings.py import json +import sys from dataclasses import dataclass from pathlib import Path from typing import Final +def resolve_app_dir() -> Path: + if getattr(sys, "frozen", False): + return Path( + sys.executable + ).resolve().parent + + return ( + Path(__file__) + .resolve() + .parent + .parent + ) + + APP_DIR: Final[Path] = ( - Path(__file__).resolve().parent.parent + resolve_app_dir() +) + +APP_DIR.mkdir( + parents=True, + exist_ok=True, ) SETTINGS_FILE: Final[Path] = ( APP_DIR / "settings.json" ) +STATE_FILE: Final[Path] = ( + APP_DIR / "active.json" +) + +MARKDOWN_FILE: Final[Path] = ( + APP_DIR / "note.md" +) + DEFAULT_SETTINGS: Final[dict] = { "active_profile": "default", "profiles": { "default": { - "theme": "macos_blue", + "theme": "dark", "window": { - "width": 260, - "height": 300, - "min_width": 220, - "min_height": 140, - "layout_margin": 4, - "layout_spacing": 4, - "drag_handle_height": 28, + "width": 250, + "height": 260, + "min_width": 200, + "min_height": 100, + "layout_margin": 0, + "layout_spacing": 0, + "drag_handle_height": 0, "resize_grip_size": 16, - "corner_radius": 16, + "corner_radius": 8, "startup_stabilize_ms": 80, }, "appearance": { @@ -36,10 +64,10 @@ DEFAULT_SETTINGS: Final[dict] = { "enable_acrylic": True, "enable_glass_blur": True, "enable_animations": True, - "enable_shadow": True, - "opacity_active": 0.99, + "enable_shadow": False, + "opacity_active": 0.97, "opacity_inactive": 0.95, - "opacity_dragging": 0.98, + "opacity_dragging": 0.89, "focus_animation_ms": 180, }, "editor": { @@ -50,7 +78,7 @@ DEFAULT_SETTINGS: Final[dict] = { "Arial", "system-ui", ], - "font_size": 15, + "font_size": 13, "preview_delay_ms": 700, "save_debounce_ms": 500, "max_note_size": 2_000_000, @@ -58,7 +86,7 @@ DEFAULT_SETTINGS: Final[dict] = { "enable_clickable_links": True, "enable_antialiasing": True, "enable_spellcheck": False, - "padding": 8, + "padding": 0, }, "behavior": { "enable_tray": True, @@ -68,127 +96,49 @@ DEFAULT_SETTINGS: Final[dict] = { "high_contrast_inactive": False, }, }, - "light": { - "theme": "light", - "window": { - "width": 260, - "height": 300, - "min_width": 220, - "min_height": 140, - "layout_margin": 4, - "layout_spacing": 4, - "drag_handle_height": 28, - "resize_grip_size": 16, - "corner_radius": 16, - "startup_stabilize_ms": 80, - }, - "appearance": { - "enable_mica": True, - "enable_acrylic": True, - "enable_glass_blur": True, - "enable_animations": True, - "enable_shadow": False, - "opacity_active": 0.99, - "opacity_inactive": 0.95, - "opacity_dragging": 0.98, - "focus_animation_ms": 120, - }, - "editor": { - "font_family": [ - "Inter", - "Segoe UI", - "Arial", - "system-ui", - ], - "font_size": 13, - "preview_delay_ms": 500, - "save_debounce_ms": 400, - "max_note_size": 2_000_000, - "enable_markdown_preview": True, - "enable_clickable_links": True, - "enable_antialiasing": True, - "enable_spellcheck": False, - "padding": 8, - }, - "behavior": { - "enable_tray": True, - "enable_persistence": True, - "enable_window_memory": True, - "enable_auto_restore": True, - "high_contrast_inactive": False, - }, - }, - "accessibility": { - "theme": "dark", - "window": { - "width": 320, - "height": 380, - "min_width": 260, - "min_height": 180, - "layout_margin": 6, - "layout_spacing": 6, - "drag_handle_height": 32, - "resize_grip_size": 18, - "corner_radius": 18, - "startup_stabilize_ms": 80, - }, - "appearance": { - "enable_mica": True, - "enable_acrylic": True, - "enable_glass_blur": True, - "enable_animations": False, - "enable_shadow": True, - "opacity_active": 0.92, - "opacity_inactive": 0.98, - "opacity_dragging": 1.0, - "focus_animation_ms": 0, - }, - "editor": { - "font_family": [ - "Inter", - "Segoe UI", - "Arial", - "system-ui", - ], - "font_size": 15, - "preview_delay_ms": 300, - "save_debounce_ms": 300, - "max_note_size": 2_000_000, - "enable_markdown_preview": True, - "enable_clickable_links": True, - "enable_antialiasing": True, - "enable_spellcheck": False, - "padding": 6, - }, - "behavior": { - "enable_tray": True, - "enable_persistence": True, - "enable_window_memory": True, - "enable_auto_restore": True, - "high_contrast_inactive": True, - }, - }, }, } +def atomic_write( + path: Path, + content: str, +) -> None: + path.parent.mkdir( + parents=True, + exist_ok=True, + ) + + temp = path.with_suffix( + f"{path.suffix}.tmp" + ) + + temp.write_text( + content, + encoding="utf-8", + ) + + temp.replace(path) + + @dataclass(slots=True) class SettingsManager: settings: dict @classmethod def load(cls) -> "SettingsManager": + SETTINGS_FILE.parent.mkdir( + parents=True, + exist_ok=True, + ) + if not SETTINGS_FILE.exists(): - SETTINGS_FILE.write_text( + atomic_write( + SETTINGS_FILE, json.dumps( DEFAULT_SETTINGS, indent=2, ), - encoding="utf-8", - ) - - return cls( - DEFAULT_SETTINGS ) try: @@ -203,9 +153,21 @@ class SettingsManager: data, ) - return cls(merged) + manager = cls(merged) + + manager.save() + + return manager except Exception: + atomic_write( + SETTINGS_FILE, + json.dumps( + DEFAULT_SETTINGS, + indent=2, + ), + ) + return cls( DEFAULT_SETTINGS ) @@ -245,12 +207,12 @@ class SettingsManager: return result def save(self) -> None: - SETTINGS_FILE.write_text( + atomic_write( + SETTINGS_FILE, json.dumps( self.settings, indent=2, ), - encoding="utf-8", ) @property @@ -284,22 +246,6 @@ class SettingsManager: return profiles[active] - def set_active_profile( - self, - profile_name: str, - ) -> None: - if ( - profile_name - not in self.profiles - ): - return - - self.settings[ - "active_profile" - ] = profile_name - - self.save() - def reload(self) -> None: loaded = ( SettingsManager.load() @@ -314,44 +260,4 @@ class SettingsManager: DEFAULT_SETTINGS ) - self.save() - - def create_profile( - self, - name: str, - data: dict, - ) -> None: - self.settings[ - "profiles" - ][name] = data - - self.save() - - def delete_profile( - self, - name: str, - ) -> None: - if name == "default": - return - - if ( - name - not in self.settings[ - "profiles" - ] - ): - return - - del self.settings[ - "profiles" - ][name] - - if ( - self.active_profile_name - == name - ): - self.settings[ - "active_profile" - ] = "default" - self.save() \ No newline at end of file