Skip to content

Commit

Permalink
🔨 Switch config updates to use update_configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Jan 9, 2025
1 parent 974ffaf commit f4dcd04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
13 changes: 9 additions & 4 deletions src/braindrop/app/braindrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
##############################################################################
# Local imports.
from ..raindrop import API
from .data import ExitState, load_configuration, save_configuration, token_file
from .data import (
ExitState,
load_configuration,
save_configuration,
token_file,
update_configuration,
)
from .screens import Main, TokenInput


Expand Down Expand Up @@ -71,9 +77,8 @@ def __init__(self) -> None:

def watch_theme(self) -> None:
"""Save the application's theme when it's changed."""
configuration = load_configuration()
configuration.theme = self.theme
save_configuration(configuration)
with update_configuration() as config:
config.theme = self.theme

@staticmethod
def environmental_token() -> str | None:
Expand Down
16 changes: 7 additions & 9 deletions src/braindrop/app/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
local_data_file,
save_configuration,
token_file,
update_configuration,
)
from ..messages import ShowCollection, ShowTagged
from ..providers import CollectionCommands, CommandsProvider, MainCommands, TagCommands
Expand Down Expand Up @@ -379,9 +380,8 @@ def action_tag_order_command(self) -> None:
self.query_one(Navigation).tags_by_count = (
by_count := not self.query_one(Navigation).tags_by_count
)
config = load_configuration()
config.show_tags_by_count = by_count
save_configuration(config)
with update_configuration() as config:
config.show_tags_by_count = by_count

@on(ShowAll)
def action_show_all_command(self) -> None:
Expand Down Expand Up @@ -426,19 +426,17 @@ def action_escape_command(self) -> None:
def action_details_command(self) -> None:
"""Toggle the details of the raindrop details view."""
self.toggle_class("details-hidden")
config = load_configuration()
config.details_visible = not self.has_class("details-hidden")
save_configuration(config)
with update_configuration() as config:
config.details_visible = not self.has_class("details-hidden")

@on(CompactMode)
def action_compact_mode_command(self) -> None:
"""Toggle the compact mode for the list of raindrops."""
self.query_one(RaindropsView).compact = not self.query_one(
RaindropsView
).compact
config = load_configuration()
config.compact_mode = self.query_one(RaindropsView).compact
save_configuration(config)
with update_configuration() as config:
config.compact_mode = self.query_one(RaindropsView).compact

@on(Search)
@work
Expand Down

0 comments on commit f4dcd04

Please sign in to comment.