something-x-dev 1.2.3.dev1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SoaOaoS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: something-x-dev
3
+ Version: 1.2.3.dev1
4
+ Summary: Something X device manager for Omarchy / Linux
5
+ Author: Raphael
6
+ License: MIT
7
+ Keywords: nothing,bluetooth,gtk4,linux,omarchy,ear
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Environment :: X11 Applications :: GTK
10
+ Classifier: Intended Audience :: End Users/Desktop
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Utilities
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: PyGObject>=3.42
19
+ Requires-Dist: dbus-python>=1.3
20
+ Provides-Extra: dev
21
+ Requires-Dist: ruff; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # Something X — for Linux
25
+
26
+ > A Linux-native companion app for **Nothing** and **CMF** Bluetooth devices.
27
+ > Built for [Omarchy](https://omarchy.org) (Hyprland / Wayland) — pure black, JetBrains Mono, Nothing Red.
28
+
29
+ ```
30
+ ● SOMETHING X
31
+ FOR LINUX
32
+ ```
33
+
34
+ [![PyPI](https://img.shields.io/pypi/v/something-x)](https://pypi.org/project/something-x/)
35
+ [![License: MIT](https://img.shields.io/badge/license-MIT-red.svg)](LICENSE)
36
+ [![Platform](https://img.shields.io/badge/platform-Linux-blue)](https://github.com/SoaOaoS/something-x)
37
+
38
+ ---
39
+
40
+ ## Features
41
+
42
+ - **Animated splash screen** — Nothing-branded intro with typewriter effect and ripple rings
43
+ - **Earbud visual** — Cairo-rendered glowing battery rings with radial gradients for L / R / Case
44
+ - **ANC control** — Off · Noise Cancellation · Transparency (real RFCOMM protocol)
45
+ - **EQ presets** — Balanced · More Bass · More Treble · Voice
46
+ - **Volume slider** — controls the PulseAudio/PipeWire A2DP sink directly
47
+ - **Per-device profiles** — ANC and EQ saved per device, restored automatically on reconnect
48
+ - **Background mode** — closing the window keeps the app running; relaunch to reopen
49
+ - **CLI quick-toggles** — control your earbuds without opening the GUI (see [CLI usage](#cli-usage))
50
+ - **Low battery notifications** — `notify-send` alert when any bud drops below 20 %
51
+ - **Firmware version & serial number** — read from the device over RFCOMM
52
+ - **In-ear detection toggle**
53
+ - **Device discovery** — BlueZ D-Bus; Nothing/CMF devices highlighted with a badge
54
+ - **Scan for new devices** — 30 s BlueZ discovery window
55
+ - **Glass morphism UI** — pure black base, frosted glass cards, red gradient accents
56
+
57
+ ---
58
+
59
+ ## Device support
60
+
61
+ | Device | Discovery | Battery | ANC | EQ | Volume | Firmware |
62
+ |---|---|---|---|---|---|---|
63
+ | Nothing Ear (1) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
64
+ | Nothing Ear (2) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
65
+ | Nothing Ear (a) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
66
+ | Nothing Ear (stick) | ✅ | ✅ | — | ✅ | ✅ | ✅ |
67
+ | CMF Buds / Buds Pro | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
68
+ | Nothing Phone (1/2) | ✅ | — | — | — | — | — |
69
+ | Other BT devices | ✅ | ✅* | — | — | ✅ | — |
70
+
71
+ \* via BlueZ `Battery1` interface · RFCOMM features require the device to be connected
72
+
73
+ ---
74
+
75
+ ## Requirements
76
+
77
+ ### System packages (Arch / Omarchy)
78
+
79
+ ```bash
80
+ sudo pacman -S python-gobject python-dbus python-cairo gtk4 libadwaita
81
+ ```
82
+
83
+ | Package | Purpose |
84
+ |---|---|
85
+ | `python-gobject` | GTK4, libadwaita, GLib bindings |
86
+ | `python-dbus` | BlueZ D-Bus access |
87
+ | `python-cairo` | Cairo drawing (earbud visual, splash) |
88
+ | `gtk4` | UI toolkit |
89
+ | `libadwaita` | Navigation, dark theme |
90
+
91
+ > `pactl` (from `libpulse` / `pipewire-pulse`) is used for volume control — already present on any PulseAudio/PipeWire system.
92
+
93
+ ---
94
+
95
+ ## Installation
96
+
97
+ ### Recommended — pip (after system packages above)
98
+
99
+ ```bash
100
+ pip install something-x
101
+ something-x
102
+ ```
103
+
104
+ ### Run from source
105
+
106
+ ```bash
107
+ git clone https://github.com/SoaOaoS/something-x
108
+ cd something-x
109
+ ./somethingx
110
+ ```
111
+
112
+ ### Desktop launcher (Walker / Rofi / app menu)
113
+
114
+ ```bash
115
+ cp nothing_app/data/com.something.x.omarchy.desktop ~/.local/share/applications/
116
+ update-desktop-database ~/.local/share/applications/
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Usage
122
+
123
+ ```
124
+ ./somethingx # from source
125
+ something-x # if installed via pip
126
+ ```
127
+
128
+ 1. **Splash** — animated intro, main window opens after ~2.3 s
129
+ 2. **Home** — all paired BT devices; Nothing/CMF get a `NOTHING` badge
130
+ 3. **Scan** — "SCAN FOR DEVICES" runs 30 s BlueZ discovery
131
+ 4. **Device page** — tap a card to open controls:
132
+ - Battery rings (L / R / Case) update in real time
133
+ - ANC and EQ apply immediately over RFCOMM; settings saved automatically
134
+ - Volume slider controls the A2DP sink via `pactl`
135
+ - Firmware and serial number shown after connection
136
+ 5. **Disconnect** — red button sends a clean BlueZ disconnect
137
+ 6. **Close** — hides to background; run `something-x` again to reopen
138
+
139
+ ---
140
+
141
+ ## CLI usage
142
+
143
+ After connecting to a device at least once via the GUI, you can control it from the terminal:
144
+
145
+ ```bash
146
+ something-x --battery # print battery levels
147
+ something-x --anc off|on|transparency # set ANC mode
148
+ something-x --eq balanced|bass|treble|voice # set EQ preset
149
+ something-x --anc on --eq bass # combine actions
150
+ something-x --device AA:BB:CC:DD:EE:FF --battery # target a specific device
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Releases & versioning
156
+
157
+ This project uses **Conventional Commits**. Pushing to `main` triggers automatic versioning and a PyPI release:
158
+
159
+ | Commit prefix | Version bump | Example |
160
+ |---|---|---|
161
+ | `feat!:` / `BREAKING CHANGE` | Major (`x.0.0`) | `feat!: new protocol engine` |
162
+ | `feat:` | Minor (`1.x.0`) | `feat: add Ear (open) support` |
163
+ | `fix:` / `perf:` / `refactor:` | Patch (`1.0.x`) | `fix: ANC off not applying` |
164
+ | `docs:` / `chore:` / `style:` / `ci:` | — (no release) | `chore: update readme` |
165
+
166
+ ---
167
+
168
+ ## Architecture
169
+
170
+ ```
171
+ nothing_app/
172
+ ├── application.py Adw.Application — CSS, dark theme, splash, background mode, CLI
173
+ ├── splash.py Animated splash screen (Cairo, typewriter, ripples)
174
+ ├── window.py AdwNavigationView — home ↔ device routing
175
+ ├── bluetooth.py BlueZ D-Bus manager (discovery, connect/disconnect signals)
176
+ ├── protocol.py Nothing Ear RFCOMM 0x55 binary protocol (reverse-engineered)
177
+ ├── profiles.py Per-device ANC/EQ profile persistence (~/.config/something-x/)
178
+ ├── data/
179
+ │ └── style.css Nothing X glass-morphism CSS theme
180
+ └── pages/
181
+ ├── home.py Device list + scan button
182
+ └── device.py ANC / EQ / volume / settings + Cairo earbud visual
183
+ ```
184
+
185
+ ### Protocol notes
186
+
187
+ Frame format: `[SOF=0x55][ctrl:2 LE][cmd:2 LE][len:2 LE][FSN:1][payload][crc16:2 LE]`
188
+
189
+ All outgoing frames use `ctrl=0x0160` with CRC16-ARC — the device silently drops SET commands if any frame in the session was sent without CRC.
190
+
191
+ ---
192
+
193
+ ## Contributing
194
+
195
+ The RFCOMM protocol in [nothing_app/protocol.py](nothing_app/protocol.py) is reverse-engineered from the official Android APK. If your device uses different command IDs or channel numbers, patches are very welcome.
196
+
197
+ ---
198
+
199
+ ## License
200
+
201
+ MIT
@@ -0,0 +1,178 @@
1
+ # Something X — for Linux
2
+
3
+ > A Linux-native companion app for **Nothing** and **CMF** Bluetooth devices.
4
+ > Built for [Omarchy](https://omarchy.org) (Hyprland / Wayland) — pure black, JetBrains Mono, Nothing Red.
5
+
6
+ ```
7
+ ● SOMETHING X
8
+ FOR LINUX
9
+ ```
10
+
11
+ [![PyPI](https://img.shields.io/pypi/v/something-x)](https://pypi.org/project/something-x/)
12
+ [![License: MIT](https://img.shields.io/badge/license-MIT-red.svg)](LICENSE)
13
+ [![Platform](https://img.shields.io/badge/platform-Linux-blue)](https://github.com/SoaOaoS/something-x)
14
+
15
+ ---
16
+
17
+ ## Features
18
+
19
+ - **Animated splash screen** — Nothing-branded intro with typewriter effect and ripple rings
20
+ - **Earbud visual** — Cairo-rendered glowing battery rings with radial gradients for L / R / Case
21
+ - **ANC control** — Off · Noise Cancellation · Transparency (real RFCOMM protocol)
22
+ - **EQ presets** — Balanced · More Bass · More Treble · Voice
23
+ - **Volume slider** — controls the PulseAudio/PipeWire A2DP sink directly
24
+ - **Per-device profiles** — ANC and EQ saved per device, restored automatically on reconnect
25
+ - **Background mode** — closing the window keeps the app running; relaunch to reopen
26
+ - **CLI quick-toggles** — control your earbuds without opening the GUI (see [CLI usage](#cli-usage))
27
+ - **Low battery notifications** — `notify-send` alert when any bud drops below 20 %
28
+ - **Firmware version & serial number** — read from the device over RFCOMM
29
+ - **In-ear detection toggle**
30
+ - **Device discovery** — BlueZ D-Bus; Nothing/CMF devices highlighted with a badge
31
+ - **Scan for new devices** — 30 s BlueZ discovery window
32
+ - **Glass morphism UI** — pure black base, frosted glass cards, red gradient accents
33
+
34
+ ---
35
+
36
+ ## Device support
37
+
38
+ | Device | Discovery | Battery | ANC | EQ | Volume | Firmware |
39
+ |---|---|---|---|---|---|---|
40
+ | Nothing Ear (1) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
41
+ | Nothing Ear (2) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
42
+ | Nothing Ear (a) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
43
+ | Nothing Ear (stick) | ✅ | ✅ | — | ✅ | ✅ | ✅ |
44
+ | CMF Buds / Buds Pro | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
45
+ | Nothing Phone (1/2) | ✅ | — | — | — | — | — |
46
+ | Other BT devices | ✅ | ✅* | — | — | ✅ | — |
47
+
48
+ \* via BlueZ `Battery1` interface · RFCOMM features require the device to be connected
49
+
50
+ ---
51
+
52
+ ## Requirements
53
+
54
+ ### System packages (Arch / Omarchy)
55
+
56
+ ```bash
57
+ sudo pacman -S python-gobject python-dbus python-cairo gtk4 libadwaita
58
+ ```
59
+
60
+ | Package | Purpose |
61
+ |---|---|
62
+ | `python-gobject` | GTK4, libadwaita, GLib bindings |
63
+ | `python-dbus` | BlueZ D-Bus access |
64
+ | `python-cairo` | Cairo drawing (earbud visual, splash) |
65
+ | `gtk4` | UI toolkit |
66
+ | `libadwaita` | Navigation, dark theme |
67
+
68
+ > `pactl` (from `libpulse` / `pipewire-pulse`) is used for volume control — already present on any PulseAudio/PipeWire system.
69
+
70
+ ---
71
+
72
+ ## Installation
73
+
74
+ ### Recommended — pip (after system packages above)
75
+
76
+ ```bash
77
+ pip install something-x
78
+ something-x
79
+ ```
80
+
81
+ ### Run from source
82
+
83
+ ```bash
84
+ git clone https://github.com/SoaOaoS/something-x
85
+ cd something-x
86
+ ./somethingx
87
+ ```
88
+
89
+ ### Desktop launcher (Walker / Rofi / app menu)
90
+
91
+ ```bash
92
+ cp nothing_app/data/com.something.x.omarchy.desktop ~/.local/share/applications/
93
+ update-desktop-database ~/.local/share/applications/
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Usage
99
+
100
+ ```
101
+ ./somethingx # from source
102
+ something-x # if installed via pip
103
+ ```
104
+
105
+ 1. **Splash** — animated intro, main window opens after ~2.3 s
106
+ 2. **Home** — all paired BT devices; Nothing/CMF get a `NOTHING` badge
107
+ 3. **Scan** — "SCAN FOR DEVICES" runs 30 s BlueZ discovery
108
+ 4. **Device page** — tap a card to open controls:
109
+ - Battery rings (L / R / Case) update in real time
110
+ - ANC and EQ apply immediately over RFCOMM; settings saved automatically
111
+ - Volume slider controls the A2DP sink via `pactl`
112
+ - Firmware and serial number shown after connection
113
+ 5. **Disconnect** — red button sends a clean BlueZ disconnect
114
+ 6. **Close** — hides to background; run `something-x` again to reopen
115
+
116
+ ---
117
+
118
+ ## CLI usage
119
+
120
+ After connecting to a device at least once via the GUI, you can control it from the terminal:
121
+
122
+ ```bash
123
+ something-x --battery # print battery levels
124
+ something-x --anc off|on|transparency # set ANC mode
125
+ something-x --eq balanced|bass|treble|voice # set EQ preset
126
+ something-x --anc on --eq bass # combine actions
127
+ something-x --device AA:BB:CC:DD:EE:FF --battery # target a specific device
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Releases & versioning
133
+
134
+ This project uses **Conventional Commits**. Pushing to `main` triggers automatic versioning and a PyPI release:
135
+
136
+ | Commit prefix | Version bump | Example |
137
+ |---|---|---|
138
+ | `feat!:` / `BREAKING CHANGE` | Major (`x.0.0`) | `feat!: new protocol engine` |
139
+ | `feat:` | Minor (`1.x.0`) | `feat: add Ear (open) support` |
140
+ | `fix:` / `perf:` / `refactor:` | Patch (`1.0.x`) | `fix: ANC off not applying` |
141
+ | `docs:` / `chore:` / `style:` / `ci:` | — (no release) | `chore: update readme` |
142
+
143
+ ---
144
+
145
+ ## Architecture
146
+
147
+ ```
148
+ nothing_app/
149
+ ├── application.py Adw.Application — CSS, dark theme, splash, background mode, CLI
150
+ ├── splash.py Animated splash screen (Cairo, typewriter, ripples)
151
+ ├── window.py AdwNavigationView — home ↔ device routing
152
+ ├── bluetooth.py BlueZ D-Bus manager (discovery, connect/disconnect signals)
153
+ ├── protocol.py Nothing Ear RFCOMM 0x55 binary protocol (reverse-engineered)
154
+ ├── profiles.py Per-device ANC/EQ profile persistence (~/.config/something-x/)
155
+ ├── data/
156
+ │ └── style.css Nothing X glass-morphism CSS theme
157
+ └── pages/
158
+ ├── home.py Device list + scan button
159
+ └── device.py ANC / EQ / volume / settings + Cairo earbud visual
160
+ ```
161
+
162
+ ### Protocol notes
163
+
164
+ Frame format: `[SOF=0x55][ctrl:2 LE][cmd:2 LE][len:2 LE][FSN:1][payload][crc16:2 LE]`
165
+
166
+ All outgoing frames use `ctrl=0x0160` with CRC16-ARC — the device silently drops SET commands if any frame in the session was sent without CRC.
167
+
168
+ ---
169
+
170
+ ## Contributing
171
+
172
+ The RFCOMM protocol in [nothing_app/protocol.py](nothing_app/protocol.py) is reverse-engineered from the official Android APK. If your device uses different command IDs or channel numbers, patches are very welcome.
173
+
174
+ ---
175
+
176
+ ## License
177
+
178
+ MIT
@@ -0,0 +1,2 @@
1
+ __version__ = "1.0.0"
2
+ APP_ID = "com.something.x.omarchy"
@@ -0,0 +1,244 @@
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import sys
5
+ import importlib.resources
6
+ import gi
7
+
8
+ gi.require_version("Gtk", "4.0")
9
+ gi.require_version("Adw", "1")
10
+ gi.require_version("Gdk", "4.0")
11
+ from gi.repository import Gtk, Adw, Gdk, Gio, GLib
12
+
13
+ from .bluetooth import BluetoothManager
14
+ from .window import SomethingXWindow
15
+ from .splash import SplashScreen
16
+
17
+
18
+ def _install_desktop_file():
19
+ dest_dir = os.path.expanduser("~/.local/share/applications")
20
+ dest = os.path.join(dest_dir, "com.something.x.omarchy.desktop")
21
+ if os.path.exists(dest):
22
+ return
23
+ try:
24
+ ref = importlib.resources.files("nothing_app.data").joinpath("com.something.x.omarchy.desktop")
25
+ os.makedirs(dest_dir, exist_ok=True)
26
+ with importlib.resources.as_file(ref) as src:
27
+ shutil.copy2(src, dest)
28
+ subprocess.run(["update-desktop-database", dest_dir], capture_output=True)
29
+ print("[app] desktop file installed to ~/.local/share/applications/")
30
+ except Exception as exc:
31
+ print(f"[app] desktop file install skipped: {exc}")
32
+
33
+
34
+ def _css_path() -> str:
35
+ try:
36
+ ref = importlib.resources.files("nothing_app.data").joinpath("style.css")
37
+ return str(ref)
38
+ except Exception:
39
+ import os
40
+
41
+ return os.path.join(os.path.dirname(__file__), "data", "style.css")
42
+
43
+
44
+ class SomethingXApplication(Adw.Application):
45
+ def __init__(self):
46
+ super().__init__(
47
+ application_id="com.something.x.omarchy",
48
+ flags=Gio.ApplicationFlags.DEFAULT_FLAGS,
49
+ )
50
+ self._bt: BluetoothManager | None = None
51
+ self._splash: SplashScreen | None = None
52
+ self._window: SomethingXWindow | None = None
53
+ self.connect("activate", self._on_activate)
54
+
55
+ def _on_activate(self, _app):
56
+ # Second launch while already running: just show the existing window
57
+ if self._window is not None:
58
+ self._window.present()
59
+ return
60
+
61
+ _install_desktop_file()
62
+ Adw.StyleManager.get_default().set_color_scheme(Adw.ColorScheme.FORCE_DARK)
63
+ self._load_css()
64
+ self._bt = BluetoothManager()
65
+ splash = SplashScreen(on_done=self._on_splash_done)
66
+ splash.set_application(self)
67
+ self._splash = splash
68
+ splash.present()
69
+ splash.start()
70
+
71
+ def _on_splash_done(self):
72
+ win = SomethingXWindow(bt_manager=self._bt, application=self)
73
+ win.connect("close-request", self._on_window_close)
74
+ self._window = win
75
+ win.present()
76
+ if self._splash:
77
+ self._splash.destroy()
78
+ self._splash = None
79
+
80
+ def _on_window_close(self, _win):
81
+ # Hide instead of destroy so the app keeps running in background
82
+ self._window.hide()
83
+ subprocess.Popen(
84
+ [
85
+ "notify-send",
86
+ "-i",
87
+ "audio-headphones",
88
+ "Something X",
89
+ "Running in background. Launch again to reopen.",
90
+ ],
91
+ start_new_session=True,
92
+ )
93
+ return True # prevent default close/destroy
94
+
95
+ def _load_css(self):
96
+ provider = Gtk.CssProvider()
97
+ css = _css_path()
98
+ try:
99
+ provider.load_from_path(css)
100
+ except Exception as exc:
101
+ print(f"[app] CSS load failed ({css}): {exc}")
102
+
103
+ display = Gdk.Display.get_default()
104
+ if display:
105
+ Gtk.StyleContext.add_provider_for_display(
106
+ display,
107
+ provider,
108
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
109
+ )
110
+
111
+
112
+ # ── CLI quick-toggle mode ─────────────────────────────────────────────────────
113
+
114
+ _ANC_ALIASES = {
115
+ "off": 0,
116
+ "0": 0,
117
+ "on": 1,
118
+ "anc": 1,
119
+ "noise": 1,
120
+ "transparency": 2,
121
+ "trans": 2,
122
+ "passthrough": 2,
123
+ }
124
+
125
+ _EQ_ALIASES = {
126
+ "balanced": "Balanced",
127
+ "bass": "More Bass",
128
+ "treble": "More Treble",
129
+ "voice": "Voice",
130
+ }
131
+
132
+
133
+ def _run_cli(argv: list[str]) -> int:
134
+ from . import protocol as _proto
135
+
136
+ _proto._QUIET = True
137
+ from .protocol import NothingDevice, ANCMode
138
+ from . import profiles
139
+
140
+ address = None
141
+ if "--device" in argv:
142
+ idx = argv.index("--device")
143
+ if idx + 1 < len(argv):
144
+ address = argv[idx + 1]
145
+
146
+ if address is None:
147
+ address = profiles.get_last_device()
148
+
149
+ if address is None:
150
+ print(
151
+ "No known device. Open the GUI and connect to a device first,\n"
152
+ "or pass --device AA:BB:CC:DD:EE:FF.",
153
+ file=sys.stderr,
154
+ )
155
+ return 1
156
+
157
+ loop = GLib.MainLoop()
158
+ dev = NothingDevice(address)
159
+ exit_code = [0]
160
+ _acted = [False]
161
+
162
+ def _act():
163
+ if _acted[0]:
164
+ return False
165
+ _acted[0] = True
166
+
167
+ if "--battery" in argv:
168
+ s = dev.state
169
+ parts = []
170
+ if s.left_battery >= 0:
171
+ parts.append(f"Left: {s.left_battery}%")
172
+ if s.right_battery >= 0:
173
+ parts.append(f"Right: {s.right_battery}%")
174
+ if s.case_battery >= 0:
175
+ parts.append(f"Case: {s.case_battery}%")
176
+ print(" ".join(parts) if parts else "No battery data received.")
177
+
178
+ if "--anc" in argv:
179
+ idx = argv.index("--anc")
180
+ val = argv[idx + 1] if idx + 1 < len(argv) else ""
181
+ mode = _ANC_ALIASES.get(val.lower())
182
+ if mode is None:
183
+ print(f"Unknown ANC value '{val}'. Use: off, on, transparency", file=sys.stderr)
184
+ exit_code[0] = 1
185
+ else:
186
+ dev.set_anc_mode(mode)
187
+ print(f"ANC → {ANCMode.LABELS.get(mode)}")
188
+
189
+ if "--eq" in argv:
190
+ idx = argv.index("--eq")
191
+ val = argv[idx + 1] if idx + 1 < len(argv) else ""
192
+ preset = _EQ_ALIASES.get(val.lower())
193
+ if preset is None:
194
+ print(f"Unknown EQ preset '{val}'. Use: balanced, bass, treble, voice", file=sys.stderr)
195
+ exit_code[0] = 1
196
+ else:
197
+ dev.set_eq_preset(preset)
198
+ print(f"EQ → {preset}")
199
+
200
+ GLib.timeout_add(600, loop.quit)
201
+ return False
202
+
203
+ def _on_state_changed(_d):
204
+ if dev.state.left_battery >= 0 or dev.state.right_battery >= 0:
205
+ _act()
206
+
207
+ def _on_timeout():
208
+ print("Timeout: device did not respond in time.", file=sys.stderr)
209
+ exit_code[0] = 1
210
+ loop.quit()
211
+ return False
212
+
213
+ dev.connect("state-changed", _on_state_changed)
214
+ dev.connect_rfcomm()
215
+ GLib.timeout_add(12000, _on_timeout)
216
+ loop.run()
217
+ dev.disconnect_rfcomm()
218
+ return exit_code[0]
219
+
220
+
221
+ def _print_help():
222
+ print(
223
+ "Usage:\n"
224
+ " something-x launch GUI\n"
225
+ " something-x --battery print battery levels\n"
226
+ " something-x --anc off|on|transparency set ANC mode\n"
227
+ " something-x --eq balanced|bass|treble|voice set EQ preset\n"
228
+ " something-x --device AA:BB:CC:DD:EE:FF target specific device\n"
229
+ )
230
+
231
+
232
+ def main():
233
+ argv = sys.argv[1:]
234
+ cli_flags = {"--battery", "--anc", "--eq"}
235
+
236
+ if "--help" in argv or "-h" in argv:
237
+ _print_help()
238
+ sys.exit(0)
239
+
240
+ if any(f in argv for f in cli_flags):
241
+ sys.exit(_run_cli(argv))
242
+
243
+ app = SomethingXApplication()
244
+ sys.exit(app.run(sys.argv))