mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-18 06:10:43 -07:00
fix(captures): use platform hotkey defaults
This commit is contained in:
@@ -17,11 +17,17 @@ Adding a new migration:
|
||||
(idempotent) and print a short message when it does real work.
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import sqlite3
|
||||
|
||||
from sqlalchemy import inspect, text
|
||||
|
||||
from ..utils.capture_chords import (
|
||||
default_push_to_talk_chord,
|
||||
default_toggle_to_talk_chord,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -200,6 +206,8 @@ def _migrate_capture_settings(engine, inspector, tables: set[str]) -> None:
|
||||
if "capture_settings" not in tables:
|
||||
return
|
||||
columns = _get_columns(inspector, "capture_settings")
|
||||
push_default = json.dumps(default_push_to_talk_chord())
|
||||
toggle_default = json.dumps(default_toggle_to_talk_chord())
|
||||
if "allow_auto_paste" not in columns:
|
||||
_add_column(
|
||||
engine,
|
||||
@@ -218,14 +226,14 @@ def _migrate_capture_settings(engine, inspector, tables: set[str]) -> None:
|
||||
_add_column(
|
||||
engine,
|
||||
"capture_settings",
|
||||
"chord_push_to_talk_keys TEXT NOT NULL DEFAULT '[\"MetaRight\",\"AltGr\"]'",
|
||||
f"chord_push_to_talk_keys TEXT NOT NULL DEFAULT '{push_default}'",
|
||||
"chord_push_to_talk_keys",
|
||||
)
|
||||
if "chord_toggle_to_talk_keys" not in columns:
|
||||
_add_column(
|
||||
engine,
|
||||
"capture_settings",
|
||||
"chord_toggle_to_talk_keys TEXT NOT NULL DEFAULT '[\"MetaRight\",\"AltGr\",\"Space\"]'",
|
||||
f"chord_toggle_to_talk_keys TEXT NOT NULL DEFAULT '{toggle_default}'",
|
||||
"chord_toggle_to_talk_keys",
|
||||
)
|
||||
if "hotkey_enabled" not in columns:
|
||||
|
||||
@@ -6,6 +6,11 @@ import uuid
|
||||
from sqlalchemy import Column, String, Integer, Float, DateTime, Text, ForeignKey, Boolean, JSON
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
from ..utils.capture_chords import (
|
||||
default_push_to_talk_chord,
|
||||
default_toggle_to_talk_chord,
|
||||
)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
@@ -205,14 +210,13 @@ class CaptureSettings(Base):
|
||||
# "Voicebox would like to receive keystrokes from any application" dialog
|
||||
# before they've even opened the Captures tab.
|
||||
hotkey_enabled = Column(Boolean, nullable=False, default=False)
|
||||
# Lists of rdev::Key variant names (e.g. "MetaRight", "AltGr"). Right-hand
|
||||
# modifiers by default so they don't collide with left-hand system
|
||||
# shortcuts (Cmd+Opt+I devtools, Cmd+Opt+Esc force-quit).
|
||||
# Lists of keytap key names (e.g. "MetaRight", "ControlRight"). Right-hand
|
||||
# modifiers by default so they don't collide with left-hand shortcuts.
|
||||
chord_push_to_talk_keys = Column(
|
||||
JSON, nullable=False, default=lambda: ["MetaRight", "AltGr"]
|
||||
JSON, nullable=False, default=default_push_to_talk_chord
|
||||
)
|
||||
chord_toggle_to_talk_keys = Column(
|
||||
JSON, nullable=False, default=lambda: ["MetaRight", "AltGr", "Space"]
|
||||
JSON, nullable=False, default=default_toggle_to_talk_chord
|
||||
)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
|
||||
+9
-2
@@ -6,6 +6,11 @@ from pydantic import BaseModel, Field
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
|
||||
from .utils.capture_chords import (
|
||||
default_push_to_talk_chord,
|
||||
default_toggle_to_talk_chord,
|
||||
)
|
||||
|
||||
|
||||
class VoiceProfileCreate(BaseModel):
|
||||
"""Request model for creating a voice profile."""
|
||||
@@ -253,9 +258,11 @@ class CaptureSettingsResponse(BaseModel):
|
||||
allow_auto_paste: bool = True
|
||||
default_playback_voice_id: Optional[str] = None
|
||||
hotkey_enabled: bool = False
|
||||
chord_push_to_talk_keys: List[str] = Field(default_factory=lambda: ["MetaRight", "AltGr"])
|
||||
chord_push_to_talk_keys: List[str] = Field(
|
||||
default_factory=default_push_to_talk_chord
|
||||
)
|
||||
chord_toggle_to_talk_keys: List[str] = Field(
|
||||
default_factory=lambda: ["MetaRight", "AltGr", "Space"]
|
||||
default_factory=default_toggle_to_talk_chord
|
||||
)
|
||||
|
||||
class Config:
|
||||
|
||||
@@ -13,6 +13,10 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from ..database import CaptureSettings as DBCaptureSettings
|
||||
from ..database import GenerationSettings as DBGenerationSettings
|
||||
from ..utils.capture_chords import (
|
||||
default_push_to_talk_chord,
|
||||
default_toggle_to_talk_chord,
|
||||
)
|
||||
|
||||
|
||||
SINGLETON_ID = 1
|
||||
@@ -21,7 +25,11 @@ SINGLETON_ID = 1
|
||||
def _get_or_create_capture_row(db: Session) -> DBCaptureSettings:
|
||||
row = db.query(DBCaptureSettings).filter(DBCaptureSettings.id == SINGLETON_ID).first()
|
||||
if row is None:
|
||||
row = DBCaptureSettings(id=SINGLETON_ID)
|
||||
row = DBCaptureSettings(
|
||||
id=SINGLETON_ID,
|
||||
chord_push_to_talk_keys=default_push_to_talk_chord(),
|
||||
chord_toggle_to_talk_keys=default_toggle_to_talk_chord(),
|
||||
)
|
||||
db.add(row)
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Platform defaults for capture hotkey chords."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
MAC_PUSH_TO_TALK = ["MetaRight", "AltGr"]
|
||||
MAC_TOGGLE_TO_TALK = ["MetaRight", "AltGr", "Space"]
|
||||
NON_MAC_PUSH_TO_TALK = ["ControlRight", "ShiftRight"]
|
||||
NON_MAC_TOGGLE_TO_TALK = ["ControlRight", "ShiftRight", "Space"]
|
||||
|
||||
|
||||
def default_push_to_talk_chord() -> list[str]:
|
||||
if sys.platform == "darwin":
|
||||
return MAC_PUSH_TO_TALK.copy()
|
||||
return NON_MAC_PUSH_TO_TALK.copy()
|
||||
|
||||
|
||||
def default_toggle_to_talk_chord() -> list[str]:
|
||||
if sys.platform == "darwin":
|
||||
return MAC_TOGGLE_TO_TALK.copy()
|
||||
return NON_MAC_TOGGLE_TO_TALK.copy()
|
||||
Reference in New Issue
Block a user