mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* feat(settings): one settings.json on every OS with a one-time Windows and Linux migration AppSettings compiles on macOS, Windows, and Linux and is the only persisted settings file. Shortcuts use one HotkeyBinding: macOS identifies the key by its layout-resolved code; Windows and Linux by the key name in its label, which their input layers translate. The first launch adopts windows-settings.json or linux-settings.json and keeps the old file as *.migrated. WindowsSettings and LinuxSettings remain as runtime views projected from AppSettings for the dictation loops, and their save merges back into settings.json. * feat(ui): open the shared AppWindow on macOS, Windows, and Linux app_window.rs is the one desktop window. Each OS supplies a platform module (app_window/macos.rs, windows.rs, linux.rs) with the same items: its window state, a Capabilities struct that decides which panes and rows exist, window chrome, and the actions only its runtime can perform. - macOS keeps its look; Meetings, Commands, the HUD Lab, permission prompts, Sparkle, and the Dock icon move into app_window/macos.rs. - Windows opens AppWindow under its 40 px caption with a full-height sidebar, Segoe UI, and Fluent icons. The tray, HUD window, and listener host stay in windows_app.rs; saved settings reach the host through WindowsDesktopHost::apply_settings. Shortcuts record by polling the keyboard state. - Linux's Settings process opens AppWindow, saves settings.json, and asks hex.service to reload it (Request::ReloadSettings). - New shared rows, shown only where a capability allows: the Enabled/Disabled listener card, Enable on launch, Recording indicator, Interface language, Software updates, and Terminal paste. - onboarding, login_item, application_catalog, transcription_preparation, personal_commands, and the command modules compile on every OS. - HEX_LEGACY_UI=1 keeps the previous Windows and Linux screens until they are deleted. * test(linux): service IPC checks read settings.json and cover ReloadSettings * fix(ui): drag the window by its caption and empty sidebar, and keep settings controls unclipped - The Windows caption row occludes the shared window's focus-on-click so Windows receives the press for dragging, Aero Snap, double-click maximize, and the caption buttons. - Empty sidebar space moves the window on every OS: the caption hit test on Windows, performWindowDragWithEvent on macOS, start_window_move on Linux. - Settings rows keep their controls at intrinsic width; the copy column shrinks and wraps, and a control wraps below the copy only when the row is narrower than both. Shortcut controls size word keycaps (Ctrl, Space) by their labels. * fix(macos): pass the main-thread marker to NSEvent::window * refactor(windows): delete the legacy Windows screens and WindowsSettings The Windows host keeps the listener, tray, and HUD and reads AppSettings directly. WindowsHotkey moves into windows_input as the keyboard hook's binding type; windows_migration reads the beta's windows-settings.json once. The Windows-only desktop_* panes, windows_desktop_host, and HEX_LEGACY_UI on Windows are gone. * refactor(linux): delete LinuxApp and LinuxSettings; the service records shortcuts and prepares models The Settings window asks hex.service to record the dictation shortcut (Wayland reads physical keys in the service; X11 records in the window and the service registers it) and to prepare models, so closing Settings never cancels a download. The service saves only what it owns on top of the current settings.json. LinuxHotkey moves into linux_input; linux_migration reads the beta's linux-settings.json once. Modes > Transformations shows the custom transformations workspace setup where there is no Commands pane. * fix(linux): compile the service tests and IPC check against settings.json * fix(ui): hide While dictating, Microphone mode, and Double-tap only where the runtime lacks them * feat(settings): switch English dictation to Parakeet Unified English once On the first load of settings that predate it, every user dictating in English moves to the streaming English model, on every OS and for migrated Windows and Linux beta files. settings.json records the switch in a new migrations list, so it runs once and a later choice sticks. The previous model stays downloaded and in the recent models. Other languages and Auto keep their model. * fix(linux): start the listener at service launch only when Enable on launch is on
152 lines
5.8 KiB
Python
152 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Display-free service/IPC regression. Never uses personal settings or a microphone."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import socket
|
|
import stat
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
binary = str(Path(sys.argv[1]).resolve())
|
|
|
|
|
|
def wait_for(check, timeout=8):
|
|
deadline = time.monotonic() + timeout
|
|
while time.monotonic() < deadline:
|
|
result = check()
|
|
if result:
|
|
return result
|
|
time.sleep(0.025)
|
|
raise AssertionError("timed out waiting for the service")
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="hex-service-", dir=os.environ.get("TMPDIR")) as directory:
|
|
root = Path(directory)
|
|
support = root / "data"
|
|
alsa = root / "alsa.conf"
|
|
alsa.write_text("# No physical audio devices in this test.\n")
|
|
env = os.environ | {"HEX_APPLICATION_SUPPORT_DIR": str(support), "ALSA_CONFIG_PATH": str(alsa)}
|
|
env.pop("DISPLAY", None)
|
|
env.pop("WAYLAND_DISPLAY", None)
|
|
path = support / "service.sock"
|
|
children = []
|
|
|
|
def launch():
|
|
child = subprocess.Popen([binary, "service"], env=env, stdin=subprocess.DEVNULL,
|
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
children.append(child)
|
|
return child
|
|
|
|
def connection():
|
|
client = socket.socket(socket.AF_UNIX)
|
|
client.settimeout(4)
|
|
client.connect(str(path))
|
|
return client
|
|
|
|
def exact(client, size):
|
|
data = b""
|
|
while len(data) < size:
|
|
chunk = client.recv(size - len(data))
|
|
assert chunk, "service disconnected"
|
|
data += chunk
|
|
return data
|
|
|
|
def call(client, request="Snapshot", version=1):
|
|
body = json.dumps({"version": version, "request": request}).encode()
|
|
client.sendall(struct.pack(">I", len(body)) + body)
|
|
size, = struct.unpack(">I", exact(client, 4))
|
|
return json.loads(exact(client, size))
|
|
|
|
def snapshot():
|
|
try:
|
|
with connection() as client:
|
|
return call(client)["state"]
|
|
except (OSError, AssertionError):
|
|
return None
|
|
|
|
try:
|
|
service = launch()
|
|
state = wait_for(snapshot)
|
|
assert state["pid"] == service.pid
|
|
assert state["desktop"]["listener"]["status"] == "Model required"
|
|
assert state["desktop"]["listener"]["warning"] is None
|
|
assert stat.S_IMODE(path.stat().st_mode) == 0o600
|
|
assert stat.S_IMODE(support.stat().st_mode) == 0o700
|
|
|
|
duplicate = launch()
|
|
assert duplicate.wait(timeout=5) != 0
|
|
assert snapshot()["pid"] == service.pid
|
|
|
|
# A Settings client can leave and reconnect without replacing the service.
|
|
with connection() as client:
|
|
assert call(client)["state"]["pid"] == service.pid
|
|
assert snapshot()["pid"] == service.pid
|
|
|
|
# Settings saves settings.json itself and asks the service to adopt it.
|
|
(support / "settings.json").write_text(
|
|
json.dumps({"sound_effects": False, "paste_with_shift": True})
|
|
)
|
|
with connection() as client:
|
|
reply = call(client, "ReloadSettings")
|
|
assert reply["error"] is None
|
|
assert reply["state"]["settings"]["sound_effects"] is False
|
|
assert reply["state"]["settings"]["paste_with_shift"] is True
|
|
|
|
# Disconnecting an uncommitted focused shortcut capture releases only that edit.
|
|
with connection() as client:
|
|
assert call(client, "CaptureShortcut")["state"]["capturing"]
|
|
with connection() as other:
|
|
assert call(other, "CancelShortcut")["error"]
|
|
wait_for(lambda: (s := snapshot()) and not s["editing"])
|
|
assert service.poll() is None
|
|
|
|
with connection() as client:
|
|
assert call(client, version=999)["error"]
|
|
with connection() as client:
|
|
client.sendall(struct.pack(">I", 128 * 1024 + 1))
|
|
assert client.recv(1) == b""
|
|
# A stalled request cannot stall other clients or live runtime state.
|
|
with connection() as stalled:
|
|
stalled.sendall(b"\x00")
|
|
assert snapshot()["pid"] == service.pid
|
|
assert stalled.recv(1) == b""
|
|
|
|
status = subprocess.run([binary, "status"], env=env, check=True, capture_output=True, text=True)
|
|
status_state = json.loads(status.stdout)
|
|
assert status_state["pid"] == service.pid
|
|
assert status_state["desktop"]["listener"]["warning"] is None
|
|
|
|
# Crash leaves a socket, not a permanent instance lock. No stale state is reported.
|
|
service.kill()
|
|
service.wait(timeout=5)
|
|
assert subprocess.run([binary, "status"], env=env, capture_output=True).returncode != 0
|
|
service = launch()
|
|
state = wait_for(snapshot)
|
|
assert state["pid"] == service.pid
|
|
assert state["settings"]["sound_effects"] is False
|
|
subprocess.run([binary, "stop"], env=env, check=True, capture_output=True)
|
|
assert service.wait(timeout=8) == 0
|
|
assert not path.exists()
|
|
assert (support / "settings.json").exists()
|
|
# Custom data roots must never start/restart the user's real installed unit.
|
|
fakebin = root / "bin"
|
|
fakebin.mkdir()
|
|
marker = root / "unexpected-systemctl"
|
|
fake = fakebin / "systemctl"
|
|
fake.write_text(f'#!/bin/sh\ntouch "{marker}"\nexit 0\n')
|
|
fake.chmod(0o755)
|
|
isolated_env = env | {"DISPLAY": ":invalid", "PATH": f'{fakebin}:{env["PATH"]}'}
|
|
for command in ("start", "restart"):
|
|
assert subprocess.run([binary, command], env=isolated_env, capture_output=True).returncode != 0
|
|
assert not marker.exists()
|
|
finally:
|
|
for child in children:
|
|
if child.poll() is None:
|
|
child.kill()
|
|
child.wait(timeout=5)
|
|
|
|
print("Linux service IPC/lifecycle checks passed.")
|