lumitray 0.2.0__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.
Files changed (54) hide show
  1. lumitray-0.2.0/PKG-INFO +155 -0
  2. lumitray-0.2.0/README.md +138 -0
  3. lumitray-0.2.0/pyproject.toml +36 -0
  4. lumitray-0.2.0/setup.cfg +4 -0
  5. lumitray-0.2.0/src/lumitray/__init__.py +3 -0
  6. lumitray-0.2.0/src/lumitray/__main__.py +3 -0
  7. lumitray-0.2.0/src/lumitray/app.py +188 -0
  8. lumitray-0.2.0/src/lumitray/autostart.py +49 -0
  9. lumitray-0.2.0/src/lumitray/backends/__init__.py +1 -0
  10. lumitray-0.2.0/src/lumitray/backends/base.py +13 -0
  11. lumitray-0.2.0/src/lumitray/backends/camera_factory.py +12 -0
  12. lumitray-0.2.0/src/lumitray/backends/factory.py +15 -0
  13. lumitray-0.2.0/src/lumitray/backends/linux_brightness.py +35 -0
  14. lumitray-0.2.0/src/lumitray/backends/power.py +16 -0
  15. lumitray-0.2.0/src/lumitray/backends/windows_brightness.py +42 -0
  16. lumitray-0.2.0/src/lumitray/backends/windows_camera.py +91 -0
  17. lumitray-0.2.0/src/lumitray/camera.py +54 -0
  18. lumitray-0.2.0/src/lumitray/cli.py +255 -0
  19. lumitray-0.2.0/src/lumitray/config.py +140 -0
  20. lumitray-0.2.0/src/lumitray/estimator.py +39 -0
  21. lumitray-0.2.0/src/lumitray/instance_lock.py +61 -0
  22. lumitray-0.2.0/src/lumitray/integration.py +71 -0
  23. lumitray-0.2.0/src/lumitray/models.py +28 -0
  24. lumitray-0.2.0/src/lumitray/policy.py +89 -0
  25. lumitray-0.2.0/src/lumitray/scheduler.py +82 -0
  26. lumitray-0.2.0/src/lumitray/settings.py +31 -0
  27. lumitray-0.2.0/src/lumitray/settings_dialog.py +76 -0
  28. lumitray-0.2.0/src/lumitray/tray.py +122 -0
  29. lumitray-0.2.0/src/lumitray.egg-info/PKG-INFO +155 -0
  30. lumitray-0.2.0/src/lumitray.egg-info/SOURCES.txt +52 -0
  31. lumitray-0.2.0/src/lumitray.egg-info/dependency_links.txt +1 -0
  32. lumitray-0.2.0/src/lumitray.egg-info/entry_points.txt +5 -0
  33. lumitray-0.2.0/src/lumitray.egg-info/requires.txt +13 -0
  34. lumitray-0.2.0/src/lumitray.egg-info/top_level.txt +1 -0
  35. lumitray-0.2.0/tests/test_app.py +144 -0
  36. lumitray-0.2.0/tests/test_autostart.py +33 -0
  37. lumitray-0.2.0/tests/test_brightness_backends.py +71 -0
  38. lumitray-0.2.0/tests/test_camera.py +94 -0
  39. lumitray-0.2.0/tests/test_camera_factory.py +26 -0
  40. lumitray-0.2.0/tests/test_cli.py +55 -0
  41. lumitray-0.2.0/tests/test_cli_camera.py +26 -0
  42. lumitray-0.2.0/tests/test_cli_settings.py +50 -0
  43. lumitray-0.2.0/tests/test_config.py +99 -0
  44. lumitray-0.2.0/tests/test_estimator.py +33 -0
  45. lumitray-0.2.0/tests/test_instance_lock.py +13 -0
  46. lumitray-0.2.0/tests/test_integration.py +43 -0
  47. lumitray-0.2.0/tests/test_packaging.py +20 -0
  48. lumitray-0.2.0/tests/test_policy.py +97 -0
  49. lumitray-0.2.0/tests/test_power.py +28 -0
  50. lumitray-0.2.0/tests/test_scheduler.py +79 -0
  51. lumitray-0.2.0/tests/test_settings.py +39 -0
  52. lumitray-0.2.0/tests/test_settings_dialog.py +16 -0
  53. lumitray-0.2.0/tests/test_tray.py +108 -0
  54. lumitray-0.2.0/tests/test_windows_camera.py +119 -0
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: lumitray
3
+ Version: 0.2.0
4
+ Summary: Privacy-preserving webcam-based automatic laptop brightness
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: numpy>=1.26
8
+ Requires-Dist: opencv-python-headless<5,>=4.8
9
+ Requires-Dist: psutil>=5.9
10
+ Requires-Dist: platformdirs>=4
11
+ Requires-Dist: Pillow>=10
12
+ Requires-Dist: pystray>=0.19
13
+ Requires-Dist: screen-brightness-control>=0.24
14
+ Requires-Dist: winsdk>=1.0.0b10; platform_system == "Windows"
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8; extra == "dev"
17
+
18
+ # LumiTray
19
+
20
+ LumiTray is a background Windows/Linux application that approximates ambient light with one low-resolution webcam frame and adjusts the built-in laptop display. It samples every **30 seconds on AC power** and every **5 minutes on battery or unknown power**.
21
+
22
+ ## Privacy and accuracy
23
+
24
+ - Frames are processed in memory and are never saved.
25
+ - There is no recording, face detection, telemetry, or cloud service.
26
+ - The webcam is closed between measurements; its indicator may turn on briefly.
27
+ - A webcam is not a true ambient-light sensor. Use quick calibration and brightness bias to adapt the approximation to your laptop and room.
28
+ - Manual brightness changes pause automatic adjustment for 15 minutes.
29
+
30
+ ## Install with pipx
31
+
32
+ Requires Python 3.11 or newer:
33
+
34
+ ```bash
35
+ pipx install lumitray
36
+ lumitray install --autostart
37
+ ```
38
+
39
+ `lumitray install` creates a per-user Start Menu shortcut on Windows or application entry on Linux. `--autostart` also starts LumiTray at login. No administrator privileges are required.
40
+
41
+ To remove launchers while preserving settings:
42
+
43
+ ```bash
44
+ lumitray uninstall
45
+ pipx uninstall lumitray
46
+ ```
47
+
48
+ ## Standalone Windows and Linux packages
49
+
50
+ Download `lumitray-windows.zip` or `lumitray-linux.tar.gz` from the GitHub release and extract both executables. No system Python is required.
51
+
52
+ On Windows:
53
+
54
+ ```powershell
55
+ .\lumitray.exe install --autostart
56
+ .\lumitray-tray.exe
57
+ ```
58
+
59
+ On Linux:
60
+
61
+ ```bash
62
+ ./lumitray install --autostart
63
+ ./lumitray-tray
64
+ ```
65
+
66
+ Linux requires a V4L2-compatible webcam, a supported tray/AppIndicator environment, and `brightnessctl` with user-writable backlight permissions. Python-based Linux installations also need Tk support for the settings dialog. The installers do not change system permissions.
67
+
68
+ ## Settings
69
+
70
+ Right-click the tray icon and choose **Settings…**, or run:
71
+
72
+ ```bash
73
+ lumitray settings
74
+ lumitray settings --min 20 --max 90
75
+ lumitray settings --min 25
76
+ lumitray settings --max 90
77
+ ```
78
+
79
+ Defaults are **20–95%**. Limits must be integers satisfying `5 <= minimum < maximum <= 100`. Invalid updates leave the existing configuration untouched. Changes apply on the next scheduled sample and never save camera frames.
80
+
81
+ ## Commands
82
+
83
+ ```bash
84
+ # Check platform, power source, and brightness support
85
+ lumitray diagnose
86
+
87
+ # Capture one frame and print only numeric luminance
88
+ lumitray sample
89
+
90
+ # Run one automatic adjustment cycle
91
+ lumitray once
92
+
93
+ # Change brightness slightly, verify it, then restore the original value
94
+ lumitray brightness-test --delta 5
95
+
96
+ # Create or remove per-user application launchers
97
+ lumitray install [--autostart]
98
+ lumitray uninstall
99
+
100
+ # Run in the background tray
101
+ lumitray tray
102
+ ```
103
+
104
+ When running from the project without adding the console script to `PATH`, use `.venv\Scripts\python.exe -m lumitray ...` on Windows or `.venv/bin/python -m lumitray ...` on Linux.
105
+
106
+ ## Tray controls
107
+
108
+ The tray menu provides status, pause/resume, brightness bias, settings, quick calibration, automatic-adjustment enable/disable, login autostart, and Exit. Only one tray instance can run at a time.
109
+
110
+ ## Ambient-light response
111
+
112
+ The generic response interpolates between these normalized camera-luminance anchors:
113
+
114
+ | Camera-relative luminance | Target before bias and user limits |
115
+ | --- | --- |
116
+ | 0.00 | 20% |
117
+ | 0.08 | 25% |
118
+ | 0.20 | 40% |
119
+ | 0.40 | 55% |
120
+ | 0.60 | 70% |
121
+ | 0.80 | 85% |
122
+ | 1.00 | 95% |
123
+
124
+ The curve is inspired by adaptive-brightness research, but normalized camera luminance is **not measured lux**. Webcam exposure, gain, direction, and scene content vary. Quick calibration, brightness bias, smoothing, a deadband, and maximum-step limits let LumiTray adapt without abrupt changes.
125
+
126
+ Research references:
127
+
128
+ - Microsoft adaptive-brightness guidance: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/sensors-adaptive-brightness
129
+ - Controlled screen-brightness study: https://jps.ecnu.edu.cn/EN/abstract/abstract9078.shtml
130
+ - Example of device-specific webcam/lux calibration: https://www.medrxiv.org/content/10.1101/2020.05.28.20115725v2.full-text
131
+
132
+ ## Platform details
133
+
134
+ Windows uses native WinRT `MediaCapture` through `winsdk`, captures a 320 × 240 JPEG directly into memory, and closes the capture session after every sample. OpenCV is the camera backend on Linux.
135
+
136
+ Linux standalone artifacts are built and CLI-smoke-tested in native CI; they are not hardware-verified from a Windows development machine.
137
+
138
+ ## Configuration and logs
139
+
140
+ Settings and logs are stored in the platform-specific user configuration/log directories reported by `platformdirs`. Configuration is JSON. Logs contain numeric status and error information, never images.
141
+
142
+ ## Development verification
143
+
144
+ ```bash
145
+ python -m venv .venv
146
+ .venv/Scripts/python -m pip install -e ".[dev]" # Windows
147
+ .venv/Scripts/python -m pytest -q # Windows
148
+ .venv/Scripts/python -m build
149
+ ```
150
+
151
+ The automated suite uses fake hardware. Real display verification is performed only by the explicit `brightness-test` command, which restores the original value in a `finally` path.
152
+
153
+ ## Limitations
154
+
155
+ External monitors, macOS, and every OEM-specific display driver are not guaranteed in this release. Long-duration battery-drain measurements require separate testing on each supported laptop model.
@@ -0,0 +1,138 @@
1
+ # LumiTray
2
+
3
+ LumiTray is a background Windows/Linux application that approximates ambient light with one low-resolution webcam frame and adjusts the built-in laptop display. It samples every **30 seconds on AC power** and every **5 minutes on battery or unknown power**.
4
+
5
+ ## Privacy and accuracy
6
+
7
+ - Frames are processed in memory and are never saved.
8
+ - There is no recording, face detection, telemetry, or cloud service.
9
+ - The webcam is closed between measurements; its indicator may turn on briefly.
10
+ - A webcam is not a true ambient-light sensor. Use quick calibration and brightness bias to adapt the approximation to your laptop and room.
11
+ - Manual brightness changes pause automatic adjustment for 15 minutes.
12
+
13
+ ## Install with pipx
14
+
15
+ Requires Python 3.11 or newer:
16
+
17
+ ```bash
18
+ pipx install lumitray
19
+ lumitray install --autostart
20
+ ```
21
+
22
+ `lumitray install` creates a per-user Start Menu shortcut on Windows or application entry on Linux. `--autostart` also starts LumiTray at login. No administrator privileges are required.
23
+
24
+ To remove launchers while preserving settings:
25
+
26
+ ```bash
27
+ lumitray uninstall
28
+ pipx uninstall lumitray
29
+ ```
30
+
31
+ ## Standalone Windows and Linux packages
32
+
33
+ Download `lumitray-windows.zip` or `lumitray-linux.tar.gz` from the GitHub release and extract both executables. No system Python is required.
34
+
35
+ On Windows:
36
+
37
+ ```powershell
38
+ .\lumitray.exe install --autostart
39
+ .\lumitray-tray.exe
40
+ ```
41
+
42
+ On Linux:
43
+
44
+ ```bash
45
+ ./lumitray install --autostart
46
+ ./lumitray-tray
47
+ ```
48
+
49
+ Linux requires a V4L2-compatible webcam, a supported tray/AppIndicator environment, and `brightnessctl` with user-writable backlight permissions. Python-based Linux installations also need Tk support for the settings dialog. The installers do not change system permissions.
50
+
51
+ ## Settings
52
+
53
+ Right-click the tray icon and choose **Settings…**, or run:
54
+
55
+ ```bash
56
+ lumitray settings
57
+ lumitray settings --min 20 --max 90
58
+ lumitray settings --min 25
59
+ lumitray settings --max 90
60
+ ```
61
+
62
+ Defaults are **20–95%**. Limits must be integers satisfying `5 <= minimum < maximum <= 100`. Invalid updates leave the existing configuration untouched. Changes apply on the next scheduled sample and never save camera frames.
63
+
64
+ ## Commands
65
+
66
+ ```bash
67
+ # Check platform, power source, and brightness support
68
+ lumitray diagnose
69
+
70
+ # Capture one frame and print only numeric luminance
71
+ lumitray sample
72
+
73
+ # Run one automatic adjustment cycle
74
+ lumitray once
75
+
76
+ # Change brightness slightly, verify it, then restore the original value
77
+ lumitray brightness-test --delta 5
78
+
79
+ # Create or remove per-user application launchers
80
+ lumitray install [--autostart]
81
+ lumitray uninstall
82
+
83
+ # Run in the background tray
84
+ lumitray tray
85
+ ```
86
+
87
+ When running from the project without adding the console script to `PATH`, use `.venv\Scripts\python.exe -m lumitray ...` on Windows or `.venv/bin/python -m lumitray ...` on Linux.
88
+
89
+ ## Tray controls
90
+
91
+ The tray menu provides status, pause/resume, brightness bias, settings, quick calibration, automatic-adjustment enable/disable, login autostart, and Exit. Only one tray instance can run at a time.
92
+
93
+ ## Ambient-light response
94
+
95
+ The generic response interpolates between these normalized camera-luminance anchors:
96
+
97
+ | Camera-relative luminance | Target before bias and user limits |
98
+ | --- | --- |
99
+ | 0.00 | 20% |
100
+ | 0.08 | 25% |
101
+ | 0.20 | 40% |
102
+ | 0.40 | 55% |
103
+ | 0.60 | 70% |
104
+ | 0.80 | 85% |
105
+ | 1.00 | 95% |
106
+
107
+ The curve is inspired by adaptive-brightness research, but normalized camera luminance is **not measured lux**. Webcam exposure, gain, direction, and scene content vary. Quick calibration, brightness bias, smoothing, a deadband, and maximum-step limits let LumiTray adapt without abrupt changes.
108
+
109
+ Research references:
110
+
111
+ - Microsoft adaptive-brightness guidance: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/sensors-adaptive-brightness
112
+ - Controlled screen-brightness study: https://jps.ecnu.edu.cn/EN/abstract/abstract9078.shtml
113
+ - Example of device-specific webcam/lux calibration: https://www.medrxiv.org/content/10.1101/2020.05.28.20115725v2.full-text
114
+
115
+ ## Platform details
116
+
117
+ Windows uses native WinRT `MediaCapture` through `winsdk`, captures a 320 × 240 JPEG directly into memory, and closes the capture session after every sample. OpenCV is the camera backend on Linux.
118
+
119
+ Linux standalone artifacts are built and CLI-smoke-tested in native CI; they are not hardware-verified from a Windows development machine.
120
+
121
+ ## Configuration and logs
122
+
123
+ Settings and logs are stored in the platform-specific user configuration/log directories reported by `platformdirs`. Configuration is JSON. Logs contain numeric status and error information, never images.
124
+
125
+ ## Development verification
126
+
127
+ ```bash
128
+ python -m venv .venv
129
+ .venv/Scripts/python -m pip install -e ".[dev]" # Windows
130
+ .venv/Scripts/python -m pytest -q # Windows
131
+ .venv/Scripts/python -m build
132
+ ```
133
+
134
+ The automated suite uses fake hardware. Real display verification is performed only by the explicit `brightness-test` command, which restores the original value in a `finally` path.
135
+
136
+ ## Limitations
137
+
138
+ External monitors, macOS, and every OEM-specific display driver are not guaranteed in this release. Long-duration battery-drain measurements require separate testing on each supported laptop model.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "lumitray"
7
+ version = "0.2.0"
8
+ description = "Privacy-preserving webcam-based automatic laptop brightness"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ dependencies = [
12
+ "numpy>=1.26",
13
+ "opencv-python-headless>=4.8,<5",
14
+ "psutil>=5.9",
15
+ "platformdirs>=4",
16
+ "Pillow>=10",
17
+ "pystray>=0.19",
18
+ "screen-brightness-control>=0.24",
19
+ "winsdk>=1.0.0b10; platform_system == 'Windows'",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = ["pytest>=8"]
24
+
25
+ [project.scripts]
26
+ lumitray = "lumitray.cli:main"
27
+
28
+ [project.gui-scripts]
29
+ lumitray-tray = "lumitray.cli:tray_main"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.pytest.ini_options]
35
+ testpaths = ["tests"]
36
+ addopts = "--strict-markers"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """LumiTray automatic display brightness."""
2
+
3
+ __version__ = "0.2.0"
@@ -0,0 +1,3 @@
1
+ from lumitray.cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,188 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import time
5
+
6
+ from lumitray.camera import CameraUnavailableError
7
+ from lumitray.config import AppConfig
8
+ from lumitray.estimator import InvalidFrameError
9
+ from lumitray.models import PowerState, SampleResult
10
+ from lumitray.policy import BrightnessPolicy
11
+
12
+
13
+ class LumiTrayService:
14
+ def __init__(
15
+ self,
16
+ config: AppConfig,
17
+ sampler,
18
+ power_monitor,
19
+ brightness,
20
+ config_store=None,
21
+ clock=time.monotonic,
22
+ ):
23
+ self.config = config
24
+ self.sampler = sampler
25
+ self.power_monitor = power_monitor
26
+ self.brightness = brightness
27
+ self.config_store = config_store
28
+ self._clock = clock
29
+ self.policy = BrightnessPolicy(config)
30
+ self.pause_until = 0.0
31
+ self.last_applied: int | None = None
32
+ self.failures = 0
33
+ self.last_result = SampleResult(status="starting", power=PowerState.UNKNOWN.value)
34
+ self.logger = logging.getLogger(__name__)
35
+
36
+ def now(self) -> float:
37
+ return self._clock()
38
+
39
+ def _power_state(self) -> PowerState:
40
+ try:
41
+ return self.power_monitor.power_state()
42
+ except Exception:
43
+ return PowerState.UNKNOWN
44
+
45
+ def _finish(self, result: SampleResult, failed: bool = False) -> SampleResult:
46
+ self.failures = self.failures + 1 if failed else 0
47
+ self.last_result = result
48
+ self.logger.info(
49
+ "status=%s power=%s luminance=%s current=%s target=%s changed=%s message=%s",
50
+ result.status,
51
+ result.power,
52
+ result.luminance,
53
+ result.current_brightness,
54
+ result.target_brightness,
55
+ result.changed,
56
+ result.message,
57
+ )
58
+ return result
59
+
60
+ def run_once(self) -> SampleResult:
61
+ power = self._power_state()
62
+ if not self.config.enabled:
63
+ return self._finish(SampleResult("disabled", power.value))
64
+ now = self.now()
65
+ if self.pause_until > now:
66
+ return self._finish(SampleResult("paused", power.value))
67
+
68
+ try:
69
+ current = self.brightness.get_brightness()
70
+ except Exception as error:
71
+ return self._finish(
72
+ SampleResult("brightness_error", power.value, message=str(error)),
73
+ failed=True,
74
+ )
75
+
76
+ if (
77
+ self.last_applied is not None
78
+ and abs(current - self.last_applied) > self.config.deadband_percent
79
+ ):
80
+ self.pause_until = now + self.config.manual_pause_seconds
81
+ return self._finish(
82
+ SampleResult(
83
+ "manual_override",
84
+ power.value,
85
+ current_brightness=current,
86
+ message="Automatic adjustment paused for 15 minutes",
87
+ )
88
+ )
89
+
90
+ try:
91
+ sample = self.sampler.sample()
92
+ except (CameraUnavailableError, InvalidFrameError, OSError) as error:
93
+ return self._finish(
94
+ SampleResult(
95
+ "camera_error",
96
+ power.value,
97
+ current_brightness=current,
98
+ message=str(error),
99
+ ),
100
+ failed=True,
101
+ )
102
+
103
+ try:
104
+ target = self.policy.choose_brightness(sample.luminance, current)
105
+ if target is None:
106
+ return self._finish(
107
+ SampleResult(
108
+ "unchanged",
109
+ power.value,
110
+ sample.luminance,
111
+ current,
112
+ current,
113
+ False,
114
+ sample.acquisition_seconds,
115
+ )
116
+ )
117
+ self.brightness.set_brightness(target)
118
+ except Exception as error:
119
+ return self._finish(
120
+ SampleResult(
121
+ "brightness_error",
122
+ power.value,
123
+ sample.luminance,
124
+ current,
125
+ message=str(error),
126
+ acquisition_seconds=sample.acquisition_seconds,
127
+ ),
128
+ failed=True,
129
+ )
130
+
131
+ self.last_applied = target
132
+ return self._finish(
133
+ SampleResult(
134
+ "adjusted",
135
+ power.value,
136
+ sample.luminance,
137
+ current,
138
+ target,
139
+ True,
140
+ sample.acquisition_seconds,
141
+ )
142
+ )
143
+
144
+ def pause(self) -> None:
145
+ self.pause_until = self.now() + self.config.manual_pause_seconds
146
+
147
+ def resume(self) -> None:
148
+ self.pause_until = 0.0
149
+ self.last_applied = None
150
+ self.policy.reset_smoothing()
151
+
152
+ def set_enabled(self, enabled: bool) -> None:
153
+ self.config.enabled = enabled
154
+ self.resume()
155
+ self._save()
156
+
157
+ def adjust_bias(self, delta: int) -> int:
158
+ self.config.bias_percent = max(-100, min(100, self.config.bias_percent + delta))
159
+ self.policy.reset_smoothing()
160
+ self._save()
161
+ return self.config.bias_percent
162
+
163
+ def quick_calibrate(self) -> int:
164
+ sample = self.sampler.sample()
165
+ brightness = self.brightness.get_brightness()
166
+ self.config.add_calibration_point(sample.luminance, brightness)
167
+ self.policy.reset_smoothing()
168
+ self._save()
169
+ return brightness
170
+
171
+ def reload_config(self) -> AppConfig:
172
+ if self.config_store is not None:
173
+ self.config = self.config_store.load()
174
+ self.policy = BrightnessPolicy(self.config)
175
+ self.last_applied = None
176
+ return self.config
177
+
178
+ def _save(self) -> None:
179
+ if self.config_store is not None:
180
+ self.config_store.save(self.config)
181
+
182
+ def status_text(self) -> str:
183
+ result = self.last_result
184
+ text = f"{result.status.replace('_', ' ').title()} · {result.power}"
185
+ if self.pause_until > self.now():
186
+ remaining = max(0, round((self.pause_until - self.now()) / 60))
187
+ text += f" · resumes in {remaining} min"
188
+ return text
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import shlex
5
+ import sys
6
+ from pathlib import Path
7
+
8
+
9
+ def autostart_path() -> Path:
10
+ if sys.platform == "win32":
11
+ roaming = Path(
12
+ os.environ.get("APPDATA", str(Path.home() / "AppData" / "Roaming"))
13
+ )
14
+ return (
15
+ roaming
16
+ / "Microsoft"
17
+ / "Windows"
18
+ / "Start Menu"
19
+ / "Programs"
20
+ / "Startup"
21
+ / "LumiTray.cmd"
22
+ )
23
+ if sys.platform.startswith("linux"):
24
+ config = Path(os.environ.get("XDG_CONFIG_HOME", str(Path.home() / ".config")))
25
+ return config / "autostart" / "lumitray.desktop"
26
+ raise RuntimeError(f"Autostart is not supported on {sys.platform}")
27
+
28
+
29
+ def set_autostart(enabled: bool) -> None:
30
+ path = autostart_path()
31
+ if not enabled:
32
+ path.unlink(missing_ok=True)
33
+ return
34
+ path.parent.mkdir(parents=True, exist_ok=True)
35
+ if sys.platform == "win32":
36
+ executable = Path(sys.executable).with_name("pythonw.exe")
37
+ path.write_text(
38
+ f'@"{executable}" -m lumitray tray\r\n', encoding="utf-8"
39
+ )
40
+ else:
41
+ content = (
42
+ "[Desktop Entry]\n"
43
+ "Type=Application\n"
44
+ "Name=LumiTray\n"
45
+ f"Exec={shlex.quote(sys.executable)} -m lumitray tray\n"
46
+ "Terminal=false\n"
47
+ "X-GNOME-Autostart-enabled=true\n"
48
+ )
49
+ path.write_text(content, encoding="utf-8")
@@ -0,0 +1 @@
1
+ """Operating-system integrations for LumiTray."""
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Protocol
4
+
5
+
6
+ class BrightnessBackendError(RuntimeError):
7
+ """The operating system could not read or set display brightness."""
8
+
9
+
10
+ class BrightnessBackend(Protocol):
11
+ def get_brightness(self) -> int: ...
12
+
13
+ def set_brightness(self, percent: int) -> None: ...
@@ -0,0 +1,12 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+
5
+ from lumitray.backends.windows_camera import WinRtCameraSampler
6
+ from lumitray.camera import CameraSampler
7
+
8
+
9
+ def create_camera_sampler(camera_index: int = 0):
10
+ if sys.platform == "win32":
11
+ return WinRtCameraSampler(camera_index)
12
+ return CameraSampler(camera_index)
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ import platform
4
+
5
+ from lumitray.backends.linux_brightness import LinuxBrightnessBackend
6
+ from lumitray.backends.windows_brightness import WindowsBrightnessBackend
7
+
8
+
9
+ def create_brightness_backend(platform_name: str | None = None):
10
+ system = (platform_name or platform.system()).lower()
11
+ if system == "windows":
12
+ return WindowsBrightnessBackend()
13
+ if system == "linux":
14
+ return LinuxBrightnessBackend()
15
+ raise RuntimeError(f"Unsupported platform: {system}")
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+
5
+ from lumitray.backends.base import BrightnessBackendError
6
+
7
+
8
+ class LinuxBrightnessBackend:
9
+ def _run(self, *args: str) -> str:
10
+ try:
11
+ result = subprocess.run(
12
+ ["brightnessctl", *args],
13
+ capture_output=True,
14
+ text=True,
15
+ check=True,
16
+ timeout=5,
17
+ shell=False,
18
+ )
19
+ return result.stdout.strip()
20
+ except (OSError, subprocess.CalledProcessError, subprocess.TimeoutExpired) as error:
21
+ raise BrightnessBackendError(
22
+ "brightnessctl failed; install it and check backlight permissions"
23
+ ) from error
24
+
25
+ def get_brightness(self) -> int:
26
+ current = int(self._run("get"))
27
+ maximum = int(self._run("max"))
28
+ if maximum <= 0:
29
+ raise BrightnessBackendError("Backlight reported an invalid maximum")
30
+ return max(0, min(100, round(current * 100 / maximum)))
31
+
32
+ def set_brightness(self, percent: int) -> None:
33
+ if not 0 <= int(percent) <= 100:
34
+ raise ValueError("Brightness must be between 0 and 100")
35
+ self._run("set", f"{int(percent)}%")
@@ -0,0 +1,16 @@
1
+ from __future__ import annotations
2
+
3
+ import psutil
4
+
5
+ from lumitray.models import PowerState
6
+
7
+
8
+ class PsutilPowerMonitor:
9
+ def power_state(self) -> PowerState:
10
+ try:
11
+ battery = psutil.sensors_battery()
12
+ except (AttributeError, OSError):
13
+ return PowerState.UNKNOWN
14
+ if battery is None or battery.power_plugged is None:
15
+ return PowerState.UNKNOWN
16
+ return PowerState.AC if battery.power_plugged else PowerState.BATTERY