streamembed 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streamembed-0.3.2 → streamembed-0.3.3}/PKG-INFO +3 -2
- {streamembed-0.3.2 → streamembed-0.3.3}/PYPI.md +1 -1
- {streamembed-0.3.2 → streamembed-0.3.3}/README.md +1 -1
- {streamembed-0.3.2 → streamembed-0.3.3}/docs/reference.md +2 -2
- {streamembed-0.3.2 → streamembed-0.3.3}/pyproject.toml +4 -1
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/__init__.py +1 -1
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/api.py +4 -4
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/capture.py +49 -2
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/cli.py +41 -1
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/service.py +6 -1
- streamembed-0.3.3/tests/test_screen_permission.py +31 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/.gitignore +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/.hgignore +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/LICENSE +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/NOTICE +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/examples/main.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/__main__.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/ann.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/config.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/defaults.toml +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/encoder.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/__init__.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/config.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/engine.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/llm.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/macs.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/model.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/pause.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/qwen_embedder.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/spatial.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/temporal.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/engine/vit.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/gate.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/index.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/models.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/queryserver.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/static/results.html +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/visualize.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/src/streamembed/webui.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/conftest.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_api.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_config.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_defer.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_encoder_order.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_front.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_idle.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_models.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_pause.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_prune.py +0 -0
- {streamembed-0.3.2 → streamembed-0.3.3}/tests/test_search_wait.py +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: streamembed
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: Search your own screen history by describing what you saw, from screenshots, on your machine
|
|
5
|
+
Project-URL: Repository, https://github.com/StarTrail-org/StreamEmbed
|
|
5
6
|
License-Expression: Apache-2.0
|
|
6
7
|
License-File: LICENSE
|
|
7
8
|
License-File: NOTICE
|
|
@@ -39,7 +40,7 @@ uv tool install streamembed # the streamembed command, in an environment of
|
|
|
39
40
|
uv pip install streamembed # or into your project's environment
|
|
40
41
|
```
|
|
41
42
|
|
|
42
|
-
Python 3.12 or later. The first run downloads the model (about 4 GB). On macOS, allow
|
|
43
|
+
Python 3.12 or later. The first run downloads the model (about 4 GB). On macOS, allow screen capture for Python when asked (System Settings > Privacy & Security > Screen & System Audio Recording; nothing records audio, only the name mentions it). StreamEmbed opens that pane and prints what to turn on; then run `streamembed start` again.
|
|
43
44
|
|
|
44
45
|
## Quick Start
|
|
45
46
|
|
|
@@ -9,7 +9,7 @@ uv tool install streamembed # the streamembed command, in an environment of
|
|
|
9
9
|
uv pip install streamembed # or into your project's environment
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Python 3.12 or later. The first run downloads the model (about 4 GB). On macOS, allow
|
|
12
|
+
Python 3.12 or later. The first run downloads the model (about 4 GB). On macOS, allow screen capture for Python when asked (System Settings > Privacy & Security > Screen & System Audio Recording; nothing records audio, only the name mentions it). StreamEmbed opens that pane and prints what to turn on; then run `streamembed start` again.
|
|
13
13
|
|
|
14
14
|
## Quick Start
|
|
15
15
|
|
|
@@ -9,7 +9,7 @@ uv tool install streamembed # the streamembed command, in an environment of
|
|
|
9
9
|
uv pip install streamembed # or into your project's environment
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Python 3.12 or later. The first run downloads the model (about 4 GB). On macOS, allow
|
|
12
|
+
Python 3.12 or later. The first run downloads the model (about 4 GB). On macOS, allow screen capture for Python when asked (System Settings > Privacy & Security > Screen & System Audio Recording; nothing records audio, only the name mentions it). StreamEmbed opens that pane and prints what to turn on; then run `streamembed start` again.
|
|
13
13
|
|
|
14
14
|
## Quick Start
|
|
15
15
|
|
|
@@ -4,7 +4,7 @@ Everything the README leaves out: every command and function, all settings, the
|
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
|
-
Python 3.12 or later. Tested on macOS 15 (Apple silicon, GPU), Ubuntu 24.04 under X11 (Xvfb; CPU) and Windows Server 2025 (CPU): installing, indexing a folder, searching, capturing, and the background service (start, pause, resume, stop, restart after a reboot). Not tested: Wayland (not supported), Windows with several monitors, CUDA GPUs. On macOS, capturing the screen needs Screen Recording permission for the app that runs Python
|
|
7
|
+
Python 3.12 or later. Tested on macOS 15 (Apple silicon, GPU), Ubuntu 24.04 under X11 (Xvfb; CPU) and Windows Server 2025 (CPU): installing, indexing a folder, searching, capturing, and the background service (start, pause, resume, stop, restart after a reboot). Not tested: Wayland (not supported), Windows with several monitors, CUDA GPUs. On macOS, capturing the screen needs the Screen & System Audio Recording permission (Screen Recording before macOS 15; no audio is recorded) for the app that runs Python: the terminal app, or for the background service the Python itself. No command can grant it: `build_index_from_now` opens that pane in System Settings and raises `PermissionError` saying what to turn on, until it is granted. On Windows, capture needs a logged-in desktop session: while the screen is locked, captures fail and are retried. Indexing `~/Desktop` on macOS needs access to it for the terminal (or, for `streamembed start --folder`, the service's Python): allow it in System Settings > Privacy & Security > Files and Folders; without it, indexing stops with a permission error.
|
|
8
8
|
|
|
9
9
|
Dependencies are pinned to torch 2.8.0 and transformers 5.17.0: the stream encoder re-implements parts of the Qwen3-VL forward pass against transformers internals, and its outputs were checked for equality with these versions. Install StreamEmbed in its own environment (for example `uv tool`, `pipx`, or a venv) if your project needs other versions.
|
|
10
10
|
|
|
@@ -149,7 +149,7 @@ se.uninstall_service() # stops it and removes it; the
|
|
|
149
149
|
|
|
150
150
|
| System | Service | Notes |
|
|
151
151
|
|---|---|---|
|
|
152
|
-
| macOS | launchd user agent `org.streamembed.capture` (`~/Library/LaunchAgents/`) | The first start asks for
|
|
152
|
+
| macOS | launchd user agent `org.streamembed.capture` (`~/Library/LaunchAgents/`) | The first start asks for screen capture permission for this Python (System Settings > Privacy & Security > Screen & System Audio Recording; Screen Recording before macOS 15), opens that pane and writes the Python to turn on to `service.log`; `streamembed start` then prints it as a warning and exits with 1 (nothing when capture is allowed). Allow it, then run `streamembed start` (or `install_service()`) again. With `--folder ~/Desktop`, this Python also needs access to the Desktop folder (Files and Folders); without it, `service.log` says so and the service captures without the folder |
|
|
153
153
|
| Linux | systemd user service `streamembed-capture.service` (`~/.config/systemd/user/`) | X11 only. Install from a terminal in your desktop session: the service keeps that session's `DISPLAY` |
|
|
154
154
|
| Windows | Task Scheduler task `StreamEmbedCapture`, at logon, run with `pythonw` (no console window) | Stopping it ends the process at once; the index drops a half-written row when it is next opened |
|
|
155
155
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "streamembed"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.3"
|
|
4
4
|
description = "Search your own screen history by describing what you saw, from screenshots, on your machine"
|
|
5
5
|
readme = "PYPI.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -29,6 +29,9 @@ dependencies = [
|
|
|
29
29
|
"pyobjc-framework-Quartz>=10; sys_platform == 'darwin'",
|
|
30
30
|
]
|
|
31
31
|
|
|
32
|
+
[project.urls]
|
|
33
|
+
Repository = "https://github.com/StarTrail-org/StreamEmbed"
|
|
34
|
+
|
|
32
35
|
[project.optional-dependencies]
|
|
33
36
|
dev = ["pytest>=8"]
|
|
34
37
|
# index_type="hnsw". chroma-hnswlib is hnswlib (same module and API) with prebuilt wheels; hnswlib itself ships only a source
|
|
@@ -4,7 +4,7 @@ from .api import (Capture, Result, Results, available_index_types, available_mod
|
|
|
4
4
|
from .config import get_config, reset_config, set_config
|
|
5
5
|
from .service import install_service, service_status, uninstall_service
|
|
6
6
|
|
|
7
|
-
__version__ = "0.3.
|
|
7
|
+
__version__ = "0.3.3"
|
|
8
8
|
__all__ = ["Capture", "Result", "Results", "available_index_types", "available_models", "build_index_from_directory", "build_index_from_now", "configure", "query_index",
|
|
9
9
|
"visualize_results", "install_service", "service_status", "uninstall_service", "pause", "resume", "is_paused",
|
|
10
10
|
"get_config", "set_config", "reset_config"]
|
|
@@ -28,7 +28,8 @@ import numpy as np
|
|
|
28
28
|
from typing import Callable, Iterator
|
|
29
29
|
|
|
30
30
|
from .ann import require_hnswlib
|
|
31
|
-
from .capture import fit_width, folder_files, load_frames, screen_frames, screen_permission
|
|
31
|
+
from .capture import (fit_width, folder_files, load_frames, open_screen_settings, screen_frames, screen_permission,
|
|
32
|
+
screen_permission_help)
|
|
32
33
|
from .gate import Gate
|
|
33
34
|
from .index import INDEX_TYPES, Index
|
|
34
35
|
from . import models as _models
|
|
@@ -713,9 +714,8 @@ def build_index_from_now(interval: float | None = None, duration: float | None =
|
|
|
713
714
|
"after 30 s." if _state["capture"].stalled else ""))
|
|
714
715
|
if frames is None:
|
|
715
716
|
interval = max(interval, MIN_LIVE_INTERVAL)
|
|
716
|
-
if not screen_permission():
|
|
717
|
-
raise PermissionError(
|
|
718
|
-
"> Screen Recording, then run again.")
|
|
717
|
+
if not screen_permission(): # opens the pane too: the system prompt shows only the first time
|
|
718
|
+
raise PermissionError(screen_permission_help(opened=open_screen_settings()))
|
|
719
719
|
frames = screen_frames(_settings()["width"], monitors)
|
|
720
720
|
_index()._writable() # check the lock and load the model before the thread starts, so errors surface here
|
|
721
721
|
try:
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
import os
|
|
5
5
|
import re
|
|
6
|
+
import subprocess
|
|
6
7
|
import sys
|
|
7
8
|
import time
|
|
8
9
|
from collections import deque
|
|
@@ -170,6 +171,52 @@ def screen_permission() -> bool:
|
|
|
170
171
|
return False
|
|
171
172
|
|
|
172
173
|
|
|
174
|
+
# macOS 15 renamed the pane "Screen & System Audio Recording"; only the name changed (nothing here records audio). No command can
|
|
175
|
+
# turn the permission on (it is kept in the SIP-protected TCC database), so we open the pane and say what to turn on in it.
|
|
176
|
+
SCREEN_PANE = "System Settings > Privacy & Security > Screen & System Audio Recording (Screen Recording before macOS 15)"
|
|
177
|
+
SCREEN_SETTINGS_URL = "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"
|
|
178
|
+
TERMINALS = {"Apple_Terminal": "Terminal", "iTerm.app": "iTerm", "vscode": "Visual Studio Code (or Cursor)", "WezTerm": "WezTerm",
|
|
179
|
+
"ghostty": "Ghostty", "WarpTerminal": "Warp", "tmux": "the terminal app that runs tmux"}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def python_app() -> str:
|
|
183
|
+
"""The Python macOS lists in the pane when Python itself is asked (the background service, started by launchd): Python.app for a
|
|
184
|
+
framework build (python.org, Homebrew), else the interpreter with symlinks resolved (a venv's python links to it)."""
|
|
185
|
+
app = Path(sys.base_prefix) / "Resources" / "Python.app"
|
|
186
|
+
return str(app if app.is_dir() else Path(os.path.realpath(sys.executable)))
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def permission_app() -> str:
|
|
190
|
+
"""What to turn on in the pane: macOS asks for the app that started this process, the terminal app when it runs in one."""
|
|
191
|
+
term = os.environ.get("TERM_PROGRAM")
|
|
192
|
+
return TERMINALS.get(term, term) if term else python_app()
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def turn_on(app: str) -> str:
|
|
196
|
+
"""'turn on X' for the pane; a path is added with + when it is not listed yet."""
|
|
197
|
+
if not app.startswith("/"):
|
|
198
|
+
return f"turn on {app}"
|
|
199
|
+
name = Path(app).stem if app.endswith(".app") else Path(app).name # as the pane lists it
|
|
200
|
+
return f"turn on {name}, or add it with + (press Cmd-Shift-G and paste {app})"
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def open_screen_settings() -> bool:
|
|
204
|
+
"""Open the pane in System Settings (macOS). False when it could not be opened, or elsewhere."""
|
|
205
|
+
if not MACOS:
|
|
206
|
+
return False
|
|
207
|
+
try:
|
|
208
|
+
return subprocess.run(["open", SCREEN_SETTINGS_URL], capture_output=True, timeout=10).returncode == 0
|
|
209
|
+
except (OSError, subprocess.SubprocessError):
|
|
210
|
+
return False
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def screen_permission_help(opened: bool = False) -> str:
|
|
214
|
+
"""How to allow screen capture, in one message. `opened`: the pane was opened (open_screen_settings)."""
|
|
215
|
+
return (f"Screen capture needs a permission that only you can give: in {SCREEN_PANE}, {turn_on(permission_app())}, then run "
|
|
216
|
+
"it again. Nothing records audio; only the pane's name mentions it. "
|
|
217
|
+
+ ("System Settings is open at that pane now." if opened else f"To open the pane: open '{SCREEN_SETTINGS_URL}'"))
|
|
218
|
+
|
|
219
|
+
|
|
173
220
|
def _preflight() -> bool:
|
|
174
221
|
"""Whether this process may record the screen (macOS), without asking for it."""
|
|
175
222
|
try:
|
|
@@ -387,8 +434,8 @@ def screen_frames(width: int, monitors: str | list[int] = "all",
|
|
|
387
434
|
took = time.monotonic() - t0
|
|
388
435
|
if took > SLOW_GRAB_S and not slow:
|
|
389
436
|
slow = True
|
|
390
|
-
why = (" The app that started Python has no
|
|
391
|
-
|
|
437
|
+
why = (f" The app that started Python has no permission to record the screen: {SCREEN_PANE}."
|
|
438
|
+
if MACOS and not _preflight() else
|
|
392
439
|
" Another app that records the screen at the same time can slow it down.")
|
|
393
440
|
print(f"streamembed: a screen grab took {took:.0f} s.{why}", file=sys.stderr, flush=True)
|
|
394
441
|
img = Image.frombytes("RGB", shot.size, shot.rgb) # full size: _ingest fits it to `width`
|
|
@@ -146,6 +146,40 @@ def _service_index_dir(se, given: str | None):
|
|
|
146
146
|
return None
|
|
147
147
|
|
|
148
148
|
|
|
149
|
+
def _screen_allowed(log, offset: int, timeout: float = 20.0) -> bool | None:
|
|
150
|
+
"""Whether the service just started may record the screen (macOS): its first line in `log` after `offset` says so.
|
|
151
|
+
None when its first line is something else (a bad setting stops it before the check) or it wrote nothing within `timeout` s."""
|
|
152
|
+
from .service import SCREEN_ALLOWED, SCREEN_NOT_ALLOWED
|
|
153
|
+
end = time.monotonic() + timeout
|
|
154
|
+
while time.monotonic() < end:
|
|
155
|
+
try:
|
|
156
|
+
with open(log, encoding="utf-8", errors="replace") as f:
|
|
157
|
+
f.seek(offset)
|
|
158
|
+
lines = f.read().splitlines()
|
|
159
|
+
except FileNotFoundError:
|
|
160
|
+
lines = []
|
|
161
|
+
for line in lines:
|
|
162
|
+
if line in (SCREEN_ALLOWED, SCREEN_NOT_ALLOWED):
|
|
163
|
+
return line == SCREEN_ALLOWED
|
|
164
|
+
if line.startswith("streamembed service:"):
|
|
165
|
+
return None
|
|
166
|
+
time.sleep(0.2)
|
|
167
|
+
return None
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _warn_screen_permission() -> None:
|
|
171
|
+
"""The service cannot record the screen: say what to turn on, as a warning on stderr."""
|
|
172
|
+
import os
|
|
173
|
+
from .capture import SCREEN_PANE, python_app, turn_on
|
|
174
|
+
head = "Warning: the background service cannot record the screen yet, so it stopped."
|
|
175
|
+
if sys.stderr.isatty() and not os.environ.get("NO_COLOR"):
|
|
176
|
+
head = f"\033[1;33m{head}\033[0m"
|
|
177
|
+
print(f"{head}\n"
|
|
178
|
+
f" In {SCREEN_PANE},\n"
|
|
179
|
+
f" {turn_on(python_app())}.\n"
|
|
180
|
+
" Then run `streamembed start` again. Only the pane's name mentions audio: nothing records sound.", file=sys.stderr)
|
|
181
|
+
|
|
182
|
+
|
|
149
183
|
def _stamp(ts: float | None, default: str) -> str:
|
|
150
184
|
return time.strftime("%Y-%m-%d %H:%M", time.localtime(ts)) if ts is not None else default
|
|
151
185
|
|
|
@@ -178,7 +212,12 @@ def _run(a) -> int:
|
|
|
178
212
|
if settings:
|
|
179
213
|
se.configure(**settings)
|
|
180
214
|
if a.command == "start":
|
|
215
|
+
log = Path(_settings()["index_dir"]).expanduser().resolve() / "service.log" # where install_service points the service
|
|
216
|
+
offset = log.stat().st_size if log.is_file() else 0
|
|
181
217
|
path = se.install_service(interval=a.interval, monitors=a.monitors, skip_unchanged=a.skip_unchanged, directory=a.folder)
|
|
218
|
+
if sys.platform == "darwin" and _screen_allowed(log, offset) is False:
|
|
219
|
+
_warn_screen_permission()
|
|
220
|
+
return 1
|
|
182
221
|
print(f"Started. It runs from now on and after every login ({path}).\nstreamembed status | pause | resume | stop")
|
|
183
222
|
elif a.command == "stop":
|
|
184
223
|
paused = se.service_status()["paused"]
|
|
@@ -221,8 +260,9 @@ def _run(a) -> int:
|
|
|
221
260
|
cap = se.build_index_from_now(interval=a.interval, monitors=a.monitors, skip_unchanged=a.skip_unchanged, block=True)
|
|
222
261
|
if cap.stalled:
|
|
223
262
|
cap.stop(timeout=0)
|
|
263
|
+
from .capture import SCREEN_PANE
|
|
224
264
|
print(f"streamembed: error: screen capture has not returned for {se.api.STALL_S:.0f} s ({_n(cap.stats['encoded'], 'screen')} "
|
|
225
|
-
"indexed). Check
|
|
265
|
+
f"indexed). Check {SCREEN_PANE}, then run it again.", file=sys.stderr)
|
|
226
266
|
return 1
|
|
227
267
|
print(f"Stopped: {_n(cap.stats['encoded'], 'screen')} indexed.")
|
|
228
268
|
elif a.command == "search":
|
|
@@ -33,6 +33,8 @@ LABEL = "org.streamembed.capture" # launchd
|
|
|
33
33
|
UNIT = "streamembed-capture.service" # systemd
|
|
34
34
|
TASK = "StreamEmbedCapture" # Task Scheduler
|
|
35
35
|
ENV_KEYS = ("HF_HOME", "HF_HUB_CACHE", "STREAMEMBED_MODELS") # passed on to the service, which starts with no shell environment
|
|
36
|
+
# the service's first line on macOS; `streamembed start` waits for it to warn only when capture cannot work
|
|
37
|
+
SCREEN_ALLOWED, SCREEN_NOT_ALLOWED = "streamembed service: screen capture allowed", "streamembed service: screen capture not allowed"
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
def _run(*args: str) -> subprocess.CompletedProcess:
|
|
@@ -293,6 +295,9 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
293
295
|
interval = max(_coerce("interval", get_config("interval") if a.interval is None else a.interval), se.api.MIN_LIVE_INTERVAL)
|
|
294
296
|
except (KeyError, ValueError, ImportError) as e: # a bad setting: restarting would not help
|
|
295
297
|
return _bad_setting(e)
|
|
298
|
+
if sys.platform == "darwin": # first thing, so that `streamembed start` can say at once whether capture will work
|
|
299
|
+
from .capture import _preflight
|
|
300
|
+
print(SCREEN_ALLOWED if _preflight() else SCREEN_NOT_ALLOWED, flush=True)
|
|
296
301
|
if a.folder:
|
|
297
302
|
def interrupt(*_):
|
|
298
303
|
raise KeyboardInterrupt # build_index_from_directory stops after the screenshot in progress
|
|
@@ -312,7 +317,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
312
317
|
try:
|
|
313
318
|
cap = se.build_index_from_now(interval=interval, monitors=monitors, skip_unchanged=a.skip_unchanged)
|
|
314
319
|
except PermissionError as e:
|
|
315
|
-
print(f"streamembed service: {e}
|
|
320
|
+
print(f"streamembed service: {e} To run it again: `streamembed start` (or se.install_service()).", flush=True)
|
|
316
321
|
return 0 # a clean exit: not restarted until it is installed again
|
|
317
322
|
except (ValueError, NotImplementedError) as e:
|
|
318
323
|
return _bad_setting(e)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""`streamembed start` on macOS reads the service's first log line to warn only when screen capture is not allowed."""
|
|
2
|
+
from streamembed.cli import _screen_allowed, _warn_screen_permission
|
|
3
|
+
from streamembed.service import SCREEN_ALLOWED, SCREEN_NOT_ALLOWED
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _log(tmp_path, *lines):
|
|
7
|
+
p = tmp_path / "service.log"
|
|
8
|
+
p.write_text("".join(l + "\n" for l in lines), encoding="utf-8")
|
|
9
|
+
return p
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_allowed_and_not_allowed(tmp_path):
|
|
13
|
+
assert _screen_allowed(_log(tmp_path, SCREEN_ALLOWED), 0, timeout=1) is True
|
|
14
|
+
assert _screen_allowed(_log(tmp_path, SCREEN_NOT_ALLOWED, "streamembed service: Screen capture needs ..."), 0, timeout=1) is False
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_reads_only_after_offset(tmp_path):
|
|
18
|
+
old = SCREEN_NOT_ALLOWED + "\n" # an earlier run's line stays in the log
|
|
19
|
+
p = _log(tmp_path, SCREEN_NOT_ALLOWED, SCREEN_ALLOWED)
|
|
20
|
+
assert _screen_allowed(p, len(old.encode()), timeout=1) is True
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_other_first_line_or_nothing(tmp_path):
|
|
24
|
+
assert _screen_allowed(_log(tmp_path, "streamembed service: unknown model x. Fix the setting"), 0, timeout=5) is None
|
|
25
|
+
assert _screen_allowed(tmp_path / "missing.log", 0, timeout=0.3) is None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_warning_text(capsys):
|
|
29
|
+
_warn_screen_permission()
|
|
30
|
+
err = capsys.readouterr().err
|
|
31
|
+
assert err.startswith("Warning: ") and "Screen & System Audio Recording" in err and "streamembed start" in err
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|