|
45 | 45 | config.btdevicesmanager.audioaddress = ConfigText(default="", fixed_size=False) |
46 | 46 |
|
47 | 47 |
|
| 48 | +def applyBTAudioState(): |
| 49 | + if not isfile("/proc/stb/audio/btaudio"): |
| 50 | + return |
| 51 | + |
| 52 | + newState = "off" |
| 53 | + if config.btdevicesmanager.audioaddress.value and config.av.btaudio.value: |
| 54 | + newState = "on" |
| 55 | + |
| 56 | + print(f"[BluetoothManager] newState: {newState}") |
| 57 | + config.btdevicesmanager.audioaddress.save() |
| 58 | + config.btdevicesmanager.audioconnect.save() |
| 59 | + if hasattr(config, "av") and hasattr(config.av, "btaudio"): |
| 60 | + config.av.btaudio.save() |
| 61 | + |
| 62 | + try: |
| 63 | + with open("/proc/stb/audio/btaudio", "w") as fn: |
| 64 | + fn.write(newState) |
| 65 | + except Exception as e: |
| 66 | + print(f"[BluetoothManager] Error writing btaudio: {e}") |
| 67 | + |
| 68 | + commandconnect = resolveFilename(SCOPE_CURRENT_PLUGIN, "Extensions/BTDevicesManager/BTAudioConnect") |
| 69 | + audioaddress = config.btdevicesmanager.audioaddress.value |
| 70 | + audioaddress = f" {audioaddress}" if audioaddress and config.btdevicesmanager.audioconnect.value else "" |
| 71 | + system(f"{commandconnect}{audioaddress}") |
| 72 | + |
| 73 | + |
48 | 74 | class BluetoothDevicesManagerSetup(Setup): |
49 | 75 | def __init__(self, session): |
50 | 76 | Setup.__init__(self, session, "BluetoothDevicesManager", plugin="Extensions/BTDevicesManager", PluginLanguageDomain="BTDevicesManager") |
@@ -152,7 +178,7 @@ def readDeviceList(self): |
152 | 178 | if self.devicelist: |
153 | 179 | self["ConnStatus"].setText("") |
154 | 180 | else: |
155 | | - self["ConnStatus"].setText(_("No connected to any device")) |
| 181 | + self["ConnStatus"].setText(_("Not connected to any device")) |
156 | 182 | self["devicelist"].setList(self.devicelist) |
157 | 183 | self.selectionChanged() |
158 | 184 |
|
@@ -280,22 +306,19 @@ def keyBlue(self): |
280 | 306 | if current[3] and isAudio: |
281 | 307 | if config.btdevicesmanager.audioaddress.value == current[1]: |
282 | 308 | config.btdevicesmanager.audioaddress.value = "" |
| 309 | + config.btdevicesmanager.audioconnect.value = False |
| 310 | + config.av.btaudio.value = False |
283 | 311 | else: |
284 | 312 | config.btdevicesmanager.audioaddress.value = current[1] |
285 | | - config.btdevicesmanager.audioaddress.save() |
286 | | - commandconnect = resolveFilename(SCOPE_CURRENT_PLUGIN, "Extensions/BTDevicesManager/BTAudioConnect") |
287 | | - audioaddress = config.btdevicesmanager.audioaddress.value |
288 | | - audioaddress = f" {audioaddress}" if audioaddress and config.btdevicesmanager.audioconnect.value else "" |
289 | | - system(f"{commandconnect}{audioaddress}") |
| 313 | + config.btdevicesmanager.audioconnect.value = True |
| 314 | + config.av.btaudio.value = True |
| 315 | + applyBTAudioState() |
290 | 316 | self.selectionChanged() |
291 | 317 |
|
292 | 318 | def keyMenu(self): |
293 | 319 | if self.hasBTAudio: |
294 | 320 | def setupCallback(*args): |
295 | | - commandconnect = resolveFilename(SCOPE_CURRENT_PLUGIN, "Extensions/BTDevicesManager/BTAudioConnect") |
296 | | - audioaddress = config.btdevicesmanager.audioaddress.value |
297 | | - audioaddress = f" {audioaddress}" if audioaddress and config.btdevicesmanager.audioconnect.value else "" |
298 | | - system(f"{commandconnect}{audioaddress}") |
| 321 | + applyBTAudioState() |
299 | 322 | self.session.openWithCallback(setupCallback, BluetoothDevicesManagerSetup) |
300 | 323 |
|
301 | 324 | def setListOnView(self): |
@@ -346,6 +369,7 @@ def sessionstart(session, reason, **kwargs): |
346 | 369 | global iBluetoothDevicesTask |
347 | 370 | if reason == 0: |
348 | 371 | if isfile("/proc/stb/audio/btaudio"): |
| 372 | + applyBTAudioState() |
349 | 373 | if iBluetoothDevicesTask is None: |
350 | 374 | iBluetoothDevicesTask = BluetoothDevicesTask(session) |
351 | 375 |
|
|
0 commit comments