config v1.1

This commit is contained in:
admin
2026-05-24 10:53:09 +00:00
parent 9eb1d2cc88
commit ed74e97693

View File

@@ -1,34 +1,62 @@
# v3.1.1 settings.py # v4.0.0 settings.py
import json import json
import sys
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import Final 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] = ( APP_DIR: Final[Path] = (
Path(__file__).resolve().parent.parent resolve_app_dir()
)
APP_DIR.mkdir(
parents=True,
exist_ok=True,
) )
SETTINGS_FILE: Final[Path] = ( SETTINGS_FILE: Final[Path] = (
APP_DIR / "settings.json" APP_DIR / "settings.json"
) )
STATE_FILE: Final[Path] = (
APP_DIR / "active.json"
)
MARKDOWN_FILE: Final[Path] = (
APP_DIR / "note.md"
)
DEFAULT_SETTINGS: Final[dict] = { DEFAULT_SETTINGS: Final[dict] = {
"active_profile": "default", "active_profile": "default",
"profiles": { "profiles": {
"default": { "default": {
"theme": "macos_blue", "theme": "dark",
"window": { "window": {
"width": 260, "width": 250,
"height": 300, "height": 260,
"min_width": 220, "min_width": 200,
"min_height": 140, "min_height": 100,
"layout_margin": 4, "layout_margin": 0,
"layout_spacing": 4, "layout_spacing": 0,
"drag_handle_height": 28, "drag_handle_height": 0,
"resize_grip_size": 16, "resize_grip_size": 16,
"corner_radius": 16, "corner_radius": 8,
"startup_stabilize_ms": 80, "startup_stabilize_ms": 80,
}, },
"appearance": { "appearance": {
@@ -36,10 +64,10 @@ DEFAULT_SETTINGS: Final[dict] = {
"enable_acrylic": True, "enable_acrylic": True,
"enable_glass_blur": True, "enable_glass_blur": True,
"enable_animations": True, "enable_animations": True,
"enable_shadow": True, "enable_shadow": False,
"opacity_active": 0.99, "opacity_active": 0.97,
"opacity_inactive": 0.95, "opacity_inactive": 0.95,
"opacity_dragging": 0.98, "opacity_dragging": 0.89,
"focus_animation_ms": 180, "focus_animation_ms": 180,
}, },
"editor": { "editor": {
@@ -50,7 +78,7 @@ DEFAULT_SETTINGS: Final[dict] = {
"Arial", "Arial",
"system-ui", "system-ui",
], ],
"font_size": 15, "font_size": 13,
"preview_delay_ms": 700, "preview_delay_ms": 700,
"save_debounce_ms": 500, "save_debounce_ms": 500,
"max_note_size": 2_000_000, "max_note_size": 2_000_000,
@@ -58,7 +86,7 @@ DEFAULT_SETTINGS: Final[dict] = {
"enable_clickable_links": True, "enable_clickable_links": True,
"enable_antialiasing": True, "enable_antialiasing": True,
"enable_spellcheck": False, "enable_spellcheck": False,
"padding": 8, "padding": 0,
}, },
"behavior": { "behavior": {
"enable_tray": True, "enable_tray": True,
@@ -68,127 +96,49 @@ DEFAULT_SETTINGS: Final[dict] = {
"high_contrast_inactive": False, "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) @dataclass(slots=True)
class SettingsManager: class SettingsManager:
settings: dict settings: dict
@classmethod @classmethod
def load(cls) -> "SettingsManager": def load(cls) -> "SettingsManager":
SETTINGS_FILE.parent.mkdir(
parents=True,
exist_ok=True,
)
if not SETTINGS_FILE.exists(): if not SETTINGS_FILE.exists():
SETTINGS_FILE.write_text( atomic_write(
SETTINGS_FILE,
json.dumps( json.dumps(
DEFAULT_SETTINGS, DEFAULT_SETTINGS,
indent=2, indent=2,
), ),
encoding="utf-8",
)
return cls(
DEFAULT_SETTINGS
) )
try: try:
@@ -203,9 +153,21 @@ class SettingsManager:
data, data,
) )
return cls(merged) manager = cls(merged)
manager.save()
return manager
except Exception: except Exception:
atomic_write(
SETTINGS_FILE,
json.dumps(
DEFAULT_SETTINGS,
indent=2,
),
)
return cls( return cls(
DEFAULT_SETTINGS DEFAULT_SETTINGS
) )
@@ -245,12 +207,12 @@ class SettingsManager:
return result return result
def save(self) -> None: def save(self) -> None:
SETTINGS_FILE.write_text( atomic_write(
SETTINGS_FILE,
json.dumps( json.dumps(
self.settings, self.settings,
indent=2, indent=2,
), ),
encoding="utf-8",
) )
@property @property
@@ -284,22 +246,6 @@ class SettingsManager:
return profiles[active] 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: def reload(self) -> None:
loaded = ( loaded = (
SettingsManager.load() SettingsManager.load()
@@ -314,44 +260,4 @@ class SettingsManager:
DEFAULT_SETTINGS 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() self.save()