mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
The macOS backends were already here: CoreAudio capture through ffmpeg, pbcopy and CoreGraphics, Carbon hotkeys, the paths under ~/Library. What was missing was everything that installs them, so install.sh hands over to install-mac.sh on Darwin rather than growing a branch per line: the XDG directories, the .desktop files and the shortcut registry mean nothing there, and an application is a bundle rather than a path. The bundle carries a copy of the interpreter, because macOS files the microphone and Accessibility permissions against the process that asks, and a launcher running Homebrew's python3 would have asked as python3 and shared the grant with everything else on that interpreter. It is signed ad-hoc so a reinstall is the same application rather than two more dialogs, and it says so plainly when a brew upgrade has moved the tree it needs. uninstall.sh and update.sh follow it. The tray icon was invisible: QIcon.fromTheme wants a freedesktop icon theme and hands back a null icon without one, which in a menu bar is the whole interface gone. trayicon.py draws the three shapes as template images, so they follow the menu bar into dark mode, and the bundle's icon comes off the same glyph rather than a binary in the repository. Linux keeps its own icons; these are used only where the theme has nothing. paths.py is the fix that was never about a Mac. config.py imports ggml.py, so ggml.py could not ask it where the data goes; each worked it out for itself and only one of them knew about macOS. Settings went to ~/Library while several gigabytes of models went to ~/.local/share, which is not a place a Mac user looks and not a place uninstall.sh --purge would have deleted from. Ctrl+Space is the input-source switch there and Cmd+Space is Spotlight, so the default is Ctrl+Option+Space, and hotkey.default_combo is the one place that difference lives. The first paste asks for Accessibility with kAXTrustedCheckOptionPrompt, which is what creates the row to switch on; asking the other way opens a pane Dikte is not listed in. `dikte shortcut status` asks the running instance, since the combination is held by that process and by nothing else. Local speech to text is the one piece a Mac builds by hand. whisper.cpp publishes no macOS binary and Homebrew's is configured with WHISPER_BUILD_SERVER=OFF, so it installs whisper-cli and not the server Dikte talks to; program_path already takes a whisper-server off the PATH or out of Settings, so the answer is the one a Linux distribution gets, and the README carries the cmake line. CI grows a macOS job on 3.11 and 3.13, the only place the Carbon and CoreGraphics libraries have to be there to be opened. Written and tested on macOS 27.0 arm64. Two things are still unverified on a Mac: the paste end to end, which waits on the Accessibility toggle, and a meeting recording, which needs a loopback driver.
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
"""Where the settings and the data are kept, per system.
|
|
|
|
Its own file because the answer has to be one answer: config.py and ggml.py
|
|
both need it, and when each worked it out for itself only one of them knew
|
|
about macOS.
|
|
"""
|
|
|
|
import os
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
import config as cfg
|
|
import ggml
|
|
import paths
|
|
|
|
|
|
class Directories(unittest.TestCase):
|
|
def test_linux_keeps_them_apart_and_follows_xdg(self):
|
|
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c",
|
|
"XDG_DATA_HOME": "/d"}):
|
|
config_dir, data_dir = paths.directories("linux")
|
|
self.assertEqual(str(config_dir), "/c/dikte")
|
|
self.assertEqual(str(data_dir), "/d/dikte")
|
|
|
|
def test_linux_without_the_variables_set(self):
|
|
with mock.patch.dict(os.environ, {}, clear=True):
|
|
config_dir, data_dir = paths.directories("linux")
|
|
self.assertTrue(str(config_dir).endswith("/.config/dikte"))
|
|
self.assertTrue(str(data_dir).endswith("/.local/share/dikte"))
|
|
|
|
def test_a_mac_keeps_both_in_application_support(self):
|
|
config_dir, data_dir = paths.directories("darwin")
|
|
self.assertEqual(config_dir, data_dir)
|
|
self.assertTrue(str(config_dir).endswith("/Library/Application Support/Dikte"))
|
|
|
|
def test_a_mac_does_not_read_the_xdg_variables(self):
|
|
"""A Mac with them set from some other tool still stores in one place."""
|
|
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c"}):
|
|
config_dir, _ = paths.directories("darwin")
|
|
self.assertNotIn("/c", str(config_dir))
|
|
|
|
|
|
class OnePlace(unittest.TestCase):
|
|
"""The programs and the models go where everything else goes.
|
|
|
|
ggml.py used to read XDG_DATA_HOME itself, which is right on Linux and
|
|
wrong on a Mac: the settings and the dictations went to ~/Library while
|
|
several gigabytes of models went to ~/.local/share, where no Mac user looks
|
|
and where `uninstall.sh --purge` would never have found them.
|
|
"""
|
|
|
|
def test_the_models_live_under_the_data_directory(self):
|
|
self.assertEqual(ggml.DATA_DIR, paths.DATA_DIR)
|
|
self.assertEqual(ggml.MODELS_DIR.parent, paths.DATA_DIR)
|
|
self.assertEqual(ggml.BIN_DIR.parent, paths.DATA_DIR)
|
|
|
|
def test_config_and_ggml_cannot_disagree(self):
|
|
self.assertEqual(cfg.DATA_DIR, ggml.DATA_DIR)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|