Skip to content

Commit b0310ed

Browse files
FichteFollclaude
andcommitted
Load the package settings through a shared module
`session.py`, `setup.py` and `keystate_helper.py` each defined their own `_SETTINGS_FILE` constant. `plugin/settings.py` now holds the file name together with `load_settings()` and `save_settings()` accessors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 192dcd0 commit b0310ed

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎plugin/ctrl_release/linux/keystate_helper.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
import sublime
1212

13+
from ...settings import load_settings
14+
1315
HANDSHAKE = "tabstack-keystate 2"
1416
DEFAULT_HELPER_PATH = "/usr/local/libexec/tabstack-keystate"
1517
DEFAULT_CTRL_KEYS = ("leftctrl", "rightctrl")
1618

1719
_HANDSHAKE_PREFIX = "tabstack-keystate "
18-
_SETTINGS_FILE = "TabStack.sublime-settings"
1920
_SETTINGS_WATCH_KEY = "tab_stack_keystate_helper"
2021
_PROBE_TIMEOUT_S = 2
2122
_EXIT_TIMEOUT_S = 1
@@ -52,14 +53,14 @@ def command(self) -> list[str]:
5253

5354

5455
def helper_path() -> str:
55-
path = sublime.load_settings(_SETTINGS_FILE).get("keystate_helper_path", DEFAULT_HELPER_PATH)
56+
path = load_settings().get("keystate_helper_path", DEFAULT_HELPER_PATH)
5657
if not isinstance(path, str) or not path:
5758
path = DEFAULT_HELPER_PATH
5859
return os.path.expanduser(path)
5960

6061

6162
def helper_ctrl_keys() -> tuple[str, ...]:
62-
keys: object = sublime.load_settings(_SETTINGS_FILE).get("keystate_ctrl_keys")
63+
keys: object = load_settings().get("keystate_ctrl_keys")
6364
if not isinstance(keys, list) or not keys:
6465
return DEFAULT_CTRL_KEYS
6566
# The helper validates the names against its allowlist and reports a usage error.
@@ -191,7 +192,7 @@ def on_settings_changed() -> None:
191192
if _helper_config() != _probed_config:
192193
on_invalidated()
193194

194-
sublime.load_settings(_SETTINGS_FILE).add_on_change(_SETTINGS_WATCH_KEY, on_settings_changed)
195+
load_settings().add_on_change(_SETTINGS_WATCH_KEY, on_settings_changed)
195196

196197

197198
def _invalidate_probe(probe: HelperProbe) -> None:
@@ -333,6 +334,6 @@ def _terminate(self, process: subprocess.Popen[str]) -> None:
333334

334335
def plugin_unloaded() -> None:
335336
global _on_invalidated
336-
sublime.load_settings(_SETTINGS_FILE).clear_on_change(_SETTINGS_WATCH_KEY)
337+
load_settings().clear_on_change(_SETTINGS_WATCH_KEY)
337338
_on_invalidated = None
338339
reset_helper_probe()

‎plugin/session.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from .constants import KIND_MODIFIED
66
from .ctrl_release import create_poller
7+
from .settings import load_settings
78
from .sheets import apply_group_selection
89
from .state import TabStackWindowState
910

@@ -12,8 +13,6 @@
1213
CTRL_STATE_TIMEOUT_MS = 1000
1314
CTRL_STATE_RETRY_MS = 10
1415

15-
_SETTINGS_FILE = "TabStack.sublime-settings"
16-
1716

1817
def _ensure_ctrl_release_poller(window: sublime.Window, state: TabStackWindowState) -> None:
1918
if state.ctrl_release_poller:
@@ -47,7 +46,7 @@ def show_panel(window: sublime.Window, state: TabStackWindowState) -> None:
4746
for entry in entries
4847
]
4948

50-
preview_tabs = bool(sublime.load_settings(_SETTINGS_FILE).get("preview_tabs", True))
49+
preview_tabs = bool(load_settings().get("preview_tabs", True))
5150

5251
def on_select(index: int) -> None:
5352
if index < 0:

‎plugin/settings.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import annotations
2+
3+
import sublime
4+
5+
SETTINGS_FILE = "TabStack.sublime-settings"
6+
7+
8+
def load_settings() -> sublime.Settings:
9+
return sublime.load_settings(SETTINGS_FILE)
10+
11+
12+
def save_settings() -> None:
13+
sublime.save_settings(SETTINGS_FILE)

‎plugin/setup.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
HelperStatus,
1414
get_helper_probe,
1515
)
16+
from .settings import load_settings, save_settings
1617

1718
__all__ = ["TabStackReplaceContentsCommand", "TabStackSetupKeystateHelperCommand"]
1819

1920
assert __package__ is not None
2021
# This module lives in the `plugin` subpackage; resources are addressed by the top-level package.
2122
_PACKAGE_NAME = __package__.split(".")[0]
22-
_SETTINGS_FILE = "TabStack.sublime-settings"
2323
_SOURCE_NAME = "tabstack-keystate.c"
2424
_SETUP_COMMAND = "tab_stack_setup_keystate_helper"
2525
_SETUP_CAPTION = "TabStack: Set Up Ctrl Detection for Wayland"
@@ -91,7 +91,7 @@ def offer_wayland_setup(window: sublime.Window) -> bool:
9191
if get_helper_probe() is None:
9292
# The background probe has not finished; the helper may still turn out to work.
9393
return False
94-
settings = sublime.load_settings(_SETTINGS_FILE)
94+
settings = load_settings()
9595
if not settings.get("show_wayland_setup_dialog", True):
9696
return False
9797

@@ -105,7 +105,7 @@ def offer_wayland_setup(window: sublime.Window) -> bool:
105105
window.run_command(_SETUP_COMMAND)
106106
elif result == sublime.DIALOG_NO:
107107
settings.set("show_wayland_setup_dialog", False)
108-
sublime.save_settings(_SETTINGS_FILE)
108+
save_settings()
109109
return True
110110

111111

0 commit comments

Comments
 (0)