diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index 9775992..45c8d56 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -71,5 +71,5 @@ jobs: uses: actions/upload-artifact@v4 with: name: Debian package - path: ./scripts/build_debian/openfreebuds_*.deb + path: ./scripts/build_debian/openfreebuds* if-no-files-found: error diff --git a/openfreebuds/driver/huawei/handler/service_language.py b/openfreebuds/driver/huawei/handler/service_language.py index adb5db0..905715f 100644 --- a/openfreebuds/driver/huawei/handler/service_language.py +++ b/openfreebuds/driver/huawei/handler/service_language.py @@ -11,7 +11,7 @@ class OfbHuaweiVoiceLanguageHandler(OfbDriverHandlerHuawei): properties = [ ("service", "language") ] - handle_commands = [b'\x0c\x02'] + commands = [b'\x0c\x02'] ignore_commands = [b"\x0c\x01"] async def on_init(self): diff --git a/openfreebuds/driver/huawei/package.py b/openfreebuds/driver/huawei/package.py index 7cd8215..1ce12a7 100644 --- a/openfreebuds/driver/huawei/package.py +++ b/openfreebuds/driver/huawei/package.py @@ -1,4 +1,4 @@ -from openfreebuds.driver.huawei.utils import crc16char, build_table_row +from openfreebuds.driver.huawei.utils import crc16_xmodem, build_table_row from openfreebuds.exceptions import OfbPackageChecksumError @@ -85,7 +85,7 @@ def to_bytes(self): # Build package result = b"Z" + (len(body) + 1).to_bytes(2, byteorder="big") + b"\x00" + body - result += crc16char(result) + result += crc16_xmodem(result) return result @staticmethod @@ -104,8 +104,8 @@ def from_bytes(data: bytes, validate_checksum=False): if validate_checksum: crc_data = data[0:-2] crc_value = data[-2:] - if crc16char(crc_data) != crc_value: - raise OfbPackageChecksumError(f"{crc16char(crc_data)} != {crc_value}") + if crc16_xmodem(crc_data) != crc_value: + raise OfbPackageChecksumError(f"{crc16_xmodem(crc_data)} != {crc_value}") length = int.from_bytes(data[1:3], byteorder="big") diff --git a/openfreebuds/driver/huawei/utils.py b/openfreebuds/driver/huawei/utils.py index e7c0eaf..e957bdb 100644 --- a/openfreebuds/driver/huawei/utils.py +++ b/openfreebuds/driver/huawei/utils.py @@ -7,7 +7,7 @@ def build_table_row(ln, val, description_table=None): return str(val).ljust(ln) + " | " -def crc16char(data): +def crc16_xmodem(data): crc16_tab = [0, 4129, 8258, 12387, 16516, 20645, 24774, 28903, -32504, -28375, -24246, -20117, -15988, -11859, -7730, -3601, 4657, 528, 12915, 8786, 21173, 17044, 29431, 25302, -27847, -31976, -19589, -23718, -11331, @@ -35,83 +35,3 @@ def crc16char(data): s = s & 0b1111111111111111 # use only 16 bits return s.to_bytes(2, "big") - - -def bytes2array(data): - out = [] - for i in range(len(data)): - out.append(int.from_bytes(data[i:i + 1], "big", signed=True)) - return out - - -def array2bytes(data): - b = b"" - for a in data: - b += a.to_bytes(1, 'big', signed=True) - return b - - -class TLVPackage: - def __init__(self, pkg_type: int, data: array): - self.type = pkg_type - self.data = data - self.length = len(data) - - def get_bytes(self): - return self.data.tobytes() - - def get_string(self): - return self.data.tobytes().decode("utf8") - - -class TLVResponse: - def __init__(self): - self.contents: list[TLVPackage] = [] - - def __iter__(self): - return self.contents.__iter__() - - def append(self, item): - self.contents.append(item) - - def find_by_type(self, type_key) -> TLVPackage: - for a in self.contents: - if a.type == type_key: - return a - return TLVPackage(type_key, array("b", b"")) - - def find_by_types(self, types_list): - for a in self.contents: - if a.type in types_list: - return a - return TLVPackage(types_list[0], array("b", b"")) - - -class TLVException(Exception): - pass - - -def parse_tlv(data: array) -> TLVResponse: - response = TLVResponse() - i = 0 - - while i <= len(data) - 2: - b_cur = data[i] - b_next = data[i + 1] - if (b_next & 128) != 0: - b_post = data[i + 2] - length = ((b_next & 127) << 7) + (b_post & 127) - pos = i + 3 - else: - length = b_next & 127 - pos = i + 2 - i = pos + length - if length != 0: - if i > len(data): - raise TLVException("TLV Package overflow") - arr = data[pos:pos + length] - response.append(TLVPackage(b_cur, arr)) - else: - response.append(TLVPackage(b_cur, array("b", b""))) - - return response diff --git a/openfreebuds/manager/generic.py b/openfreebuds/manager/generic.py index 1da7f4c..a0c0b58 100644 --- a/openfreebuds/manager/generic.py +++ b/openfreebuds/manager/generic.py @@ -4,8 +4,6 @@ class IOpenFreebuds(Subscription): - MAINLOOP_TIMEOUT = 1 - STATE_DESTROYED = -1 STATE_STOPPED = 0 STATE_DISCONNECTED = 1 diff --git a/openfreebuds/manager/standalone.py b/openfreebuds/manager/standalone.py index 44818de..6db6582 100644 --- a/openfreebuds/manager/standalone.py +++ b/openfreebuds/manager/standalone.py @@ -169,11 +169,6 @@ async def _mainloop_inner(self): await asyncio.sleep(2) - async def _use_device_driver(self, driver: OfbDriverGeneric): - if self._driver: - await self._driver.stop() - self._driver = driver - async def _set_state(self, new_state: int): if self._state == new_state: return diff --git a/openfreebuds/utils/stupid_rpc.py b/openfreebuds/utils/stupid_rpc.py index cc9051f..056ab4d 100644 --- a/openfreebuds/utils/stupid_rpc.py +++ b/openfreebuds/utils/stupid_rpc.py @@ -16,7 +16,6 @@ class RemoteError(Exception): def __init__(self, data): super().__init__(data) - self.rpc_error_name = data["class"] self.rpc_trace = data["trace"] self.args = data["args"] diff --git a/openfreebuds_backend/dummy.py b/openfreebuds_backend/dummy.py index 573d3de..6d9da94 100644 --- a/openfreebuds_backend/dummy.py +++ b/openfreebuds_backend/dummy.py @@ -8,10 +8,6 @@ def get_app_storage_path(): return os.getcwd() + "/data" -def open_in_file_manager(path): - log.info("open_dir " + path) - - def open_file(path): log.info("open_file " + path) @@ -43,11 +39,5 @@ def bt_list_devices(): return [] -def ask_string(message, callback): - logging.info("ask_str" + message) - if callback: - callback(None) - - def is_dark_taskbar(): return False diff --git a/openfreebuds_backend/linux/linux_misc.py b/openfreebuds_backend/linux/linux_misc.py index e4bf3e4..a2beead 100644 --- a/openfreebuds_backend/linux/linux_misc.py +++ b/openfreebuds_backend/linux/linux_misc.py @@ -10,10 +10,6 @@ def get_app_storage_path(): return pathlib.Path.home() / ".config" -def open_in_file_manager(path): - subprocess.Popen(["xdg-open", path]) - - def open_file(path): subprocess.Popen(["xdg-open", path]) diff --git a/openfreebuds_backend/windows/misc_win32.py b/openfreebuds_backend/windows/misc_win32.py index bec46b1..c0b0fd6 100644 --- a/openfreebuds_backend/windows/misc_win32.py +++ b/openfreebuds_backend/windows/misc_win32.py @@ -12,10 +12,6 @@ def get_app_storage_path(): return pathlib.Path.home() / "AppData/Roaming" -def open_in_file_manager(path): - os.startfile(path) - - def open_file(path): subprocess.Popen(["notepad.exe", path]) diff --git a/openfreebuds_backend/windows/ui_win32.py b/openfreebuds_backend/windows/ui_win32.py index ad39d6c..3395cb7 100644 --- a/openfreebuds_backend/windows/ui_win32.py +++ b/openfreebuds_backend/windows/ui_win32.py @@ -1,21 +1,6 @@ import logging -import threading -import tkinter.simpledialog import winreg -# noinspection PyUnresolvedReferences -from winsdk.windows.ui.viewmanagement import UISettings, UIColorType - -log = logging.getLogger("OfbWindowsBackend") - - -# noinspection PyUnusedLocal -def ask_string(message, callback): - def run_async(): - result = tkinter.simpledialog.askstring("OpenFreebuds", prompt=message) - callback(result) - threading.Thread(target=run_async).start() - def is_dark_taskbar(): with winreg.OpenKey( diff --git a/openfreebuds_qt/app/helper/setting_tab_helper.py b/openfreebuds_qt/app/helper/setting_tab_helper.py index 4819b92..7fffba0 100644 --- a/openfreebuds_qt/app/helper/setting_tab_helper.py +++ b/openfreebuds_qt/app/helper/setting_tab_helper.py @@ -68,13 +68,6 @@ def set_active_tab(self, section: int, tab: int): def active_tab(self): return self._active_entry - def retranslate_ui(self): - for section in self._sections: - if section.list_item is not None: - section.list_item.setText(self.root.tr(section.label)) - for item in section.items: - item.list_item.label.setText(self.root.tr(item.label)) - def add_tab(self, label: str, content: QWidget): section_num = len(self._sections) - 1 tab = len(self._sections[section_num].items) diff --git a/openfreebuds_qt/app/main.py b/openfreebuds_qt/app/main.py index dcc2fbf..c58cdab 100644 --- a/openfreebuds_qt/app/main.py +++ b/openfreebuds_qt/app/main.py @@ -30,7 +30,6 @@ def __init__(self, ctx: IOfbQtApplication): self.ctx = ctx self.ofb = ctx.ofb - self._exit_started: bool = False self.setupUi(self) diff --git a/openfreebuds_qt/app/module/__init__.py b/openfreebuds_qt/app/module/__init__.py index 5bbbae9..934bc09 100644 --- a/openfreebuds_qt/app/module/__init__.py +++ b/openfreebuds_qt/app/module/__init__.py @@ -1,7 +1,6 @@ from .about import OfbQtAboutModule from .choose_device import OfbQtChooseDeviceModule from .common import OfbQtCommonModule -from .common_with_shortcuts import OfbQtCommonWithShortcutsModule from .device_info import OfbQtDeviceInfoModule from .device_other import OfbQtDeviceOtherSettingsModule from .dual_connect import OfbQtDualConnectModule diff --git a/openfreebuds_qt/app/module/about.py b/openfreebuds_qt/app/module/about.py index 227b737..efcf062 100644 --- a/openfreebuds_qt/app/module/about.py +++ b/openfreebuds_qt/app/module/about.py @@ -43,6 +43,3 @@ def open_website(self): @pyqtSlot() def open_github(self): webbrowser.open(LINK_GITHUB) - - def retranslate_ui(self): - self.retranslateUi(self) diff --git a/openfreebuds_qt/app/module/choose_device.py b/openfreebuds_qt/app/module/choose_device.py index 8e9d8a7..be1f9ce 100644 --- a/openfreebuds_qt/app/module/choose_device.py +++ b/openfreebuds_qt/app/module/choose_device.py @@ -91,6 +91,3 @@ async def on_auto_config_toggle(self, value): if value is True: await OfbQtDeviceAutoSelect.trigger(self.ofb) - - def retranslate_ui(self): - self.retranslateUi(self) diff --git a/openfreebuds_qt/app/module/common.py b/openfreebuds_qt/app/module/common.py index ef4c048..6e0831e 100644 --- a/openfreebuds_qt/app/module/common.py +++ b/openfreebuds_qt/app/module/common.py @@ -14,8 +14,5 @@ def __init__(self, parent: QWidget, context: IOfbQtApplication): self.ofb = context.ofb self.list_item: Optional[OfbQListItem] = None - def retranslate_ui(self): - pass - async def update_ui(self, event: OfbCoreEvent): pass diff --git a/openfreebuds_qt/app/module/common_with_shortcuts.py b/openfreebuds_qt/app/module/common_with_shortcuts.py deleted file mode 100644 index 1949f61..0000000 --- a/openfreebuds_qt/app/module/common_with_shortcuts.py +++ /dev/null @@ -1,17 +0,0 @@ -from openfreebuds_qt.app.module.common import OfbQtCommonModule - - -class OfbQtCommonWithShortcutsModule(OfbQtCommonModule): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - self.shortcut_names = { - "connect": self.tr("Connect device"), - "disconnect": self.tr("Disconnect device"), - "toggle_connect": self.tr("Connect/disconnect device"), - "next_mode": self.tr("Next noise control mode"), - "mode_normal": self.tr("Disable noise control"), - "mode_cancellation": self.tr("Enable noise cancellation"), - "mode_awareness": self.tr("Enable awareness mode"), - "enable_low_latency": self.tr("Enable low-latency mode"), - } diff --git a/openfreebuds_qt/app/module/device_info.py b/openfreebuds_qt/app/module/device_info.py index 9ad106a..aa7ec46 100644 --- a/openfreebuds_qt/app/module/device_info.py +++ b/openfreebuds_qt/app/module/device_info.py @@ -13,9 +13,6 @@ def __init__(self, *args, **kwargs): self.setupUi(self) - def retranslate_ui(self): - self.retranslateUi(self) - async def update_ui(self, event: OfbCoreEvent): async with qt_error_handler("OfbQtDeviceInfoModule_UpdateUi", self.ctx): if event.is_changed("info") or event.kind_match(OfbEventKind.DEVICE_CHANGED): diff --git a/openfreebuds_qt/app/module/device_other.py b/openfreebuds_qt/app/module/device_other.py index 6b31533..abf4d9f 100644 --- a/openfreebuds_qt/app/module/device_other.py +++ b/openfreebuds_qt/app/module/device_other.py @@ -56,9 +56,6 @@ async def update_ui(self, event: OfbCoreEvent): ) self.service_language_box.setCurrentIndex(-1) - def retranslate_ui(self): - self.retranslateUi(self) - @asyncSlot(bool) async def on_low_latency_toggle(self, value: bool): async with qt_error_handler("OfbQtDeviceOtherSettingsModule_SetLowLatency", self.ctx): diff --git a/openfreebuds_qt/app/module/dual_connect.py b/openfreebuds_qt/app/module/dual_connect.py index ca61ca4..7e56d18 100644 --- a/openfreebuds_qt/app/module/dual_connect.py +++ b/openfreebuds_qt/app/module/dual_connect.py @@ -23,9 +23,6 @@ def __init__(self, *args, **kwargs): self.setupUi(self) - def retranslate_ui(self): - self.retranslateUi(self) - async def update_ui(self, event: OfbCoreEvent): async with qt_error_handler("OfbQtDualConnectModule_UpdateUi", self.ctx): # Setup visibility diff --git a/openfreebuds_qt/app/module/gestures.py b/openfreebuds_qt/app/module/gestures.py index 723e399..5281a3e 100644 --- a/openfreebuds_qt/app/module/gestures.py +++ b/openfreebuds_qt/app/module/gestures.py @@ -41,7 +41,7 @@ def set_right_available(self, value: bool): return if self.right_combo is not None: index = self.grid.indexOf(self.left_combo) - r, c, rs, cs = self.grid.getItemPosition(index) + r, c, rs, _ = self.grid.getItemPosition(index) self.grid.takeAt(index) self.grid.addWidget(self.left_combo, r, c, rs, 1 if value else 2) self.right_combo.setVisible(value) diff --git a/openfreebuds_qt/app/module/hotkeys_module.py b/openfreebuds_qt/app/module/hotkeys_module.py index 4bc0cb6..2a7a519 100644 --- a/openfreebuds_qt/app/module/hotkeys_module.py +++ b/openfreebuds_qt/app/module/hotkeys_module.py @@ -6,20 +6,22 @@ from openfreebuds.shortcuts import OfbShortcuts from openfreebuds.utils.logger import create_logger +from openfreebuds_qt.app.module import OfbQtCommonModule +from openfreebuds_qt.config import OfbQtConfigParser +from openfreebuds_qt.designer.hotkeys import Ui_OfbQtHotkeysModule +from openfreebuds_qt.qt_i18n import get_shortcut_names from openfreebuds_qt.utils.hotkeys.recorder import OfbQtHotkeyRecorder from openfreebuds_qt.utils.hotkeys.service import OfbQtHotkeyService -from openfreebuds_qt.app.module.common_with_shortcuts import OfbQtCommonWithShortcutsModule from openfreebuds_qt.utils.qt_utils import qt_error_handler, blocked_signals -from openfreebuds_qt.config import OfbQtConfigParser -from openfreebuds_qt.designer.hotkeys import Ui_OfbQtHotkeysModule log = create_logger("OfbQtHotkeysModule") -class OfbQtHotkeysModule(Ui_OfbQtHotkeysModule, OfbQtCommonWithShortcutsModule): +class OfbQtHotkeysModule(Ui_OfbQtHotkeysModule, OfbQtCommonModule): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.shortcut_names = get_shortcut_names() self.service = OfbQtHotkeyService.get_instance(self.ofb) self.config = OfbQtConfigParser.get_instance() self.recorder = OfbQtHotkeyRecorder() @@ -70,6 +72,3 @@ async def on_edit_shortcut(self, index: int, column: int): self.service.start() self.table.setItem(index, column, QTableWidgetItem(self.config.get("hotkeys", shortcut, "Disabled"))) - - def retranslate_ui(self): - self.retranslateUi(self) diff --git a/openfreebuds_qt/app/module/sound_quality.py b/openfreebuds_qt/app/module/sound_quality.py index 813634c..c506977 100644 --- a/openfreebuds_qt/app/module/sound_quality.py +++ b/openfreebuds_qt/app/module/sound_quality.py @@ -72,9 +72,6 @@ async def _on_change(value: int): self.custom_eq_rows_layout.addWidget(slider) self._eq_rows.append(slider) - def retranslate_ui(self): - self.retranslateUi(self) - async def update_ui(self, event: OfbCoreEvent): sound = await self.ofb.get_property("sound") self.list_item.setVisible(sound is not None) diff --git a/openfreebuds_qt/app/module/ui_settings.py b/openfreebuds_qt/app/module/ui_settings.py index 647d9ab..a971052 100644 --- a/openfreebuds_qt/app/module/ui_settings.py +++ b/openfreebuds_qt/app/module/ui_settings.py @@ -5,19 +5,20 @@ from openfreebuds.shortcuts import OfbShortcuts from openfreebuds.utils.logger import create_logger from openfreebuds_backend import is_run_at_boot, set_run_at_boot -from openfreebuds_qt.app.module import OfbQtCommonWithShortcutsModule +from openfreebuds_qt.app.module import OfbQtCommonModule from openfreebuds_qt.config import OfbQtConfigParser from openfreebuds_qt.designer.ui_settings import Ui_OfbQtUiSettingsModule +from openfreebuds_qt.qt_i18n import get_shortcut_names from openfreebuds_qt.utils import blocked_signals, list_available_locales - log = create_logger("OfbQtUiSettingsModule") -class OfbQtUiSettingsModule(Ui_OfbQtUiSettingsModule, OfbQtCommonWithShortcutsModule): +class OfbQtUiSettingsModule(Ui_OfbQtUiSettingsModule, OfbQtCommonModule): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.shortcut_names = get_shortcut_names() self.available_shortcuts = OfbShortcuts.all() self.available_icons = ["auto", "light", "dark"] self.available_locales = ["auto", *list_available_locales()] diff --git a/openfreebuds_qt/qt_i18n.py b/openfreebuds_qt/qt_i18n.py index 934537a..2acaa9b 100644 --- a/openfreebuds_qt/qt_i18n.py +++ b/openfreebuds_qt/qt_i18n.py @@ -8,3 +8,16 @@ def get_eq_preset_names(): "equalizer_preset_treble": QApplication.translate("EqPresetName", "Treble-boost"), "equalizer_preset_voices": QApplication.translate("EqPresetName", "Voices"), } + + +def get_shortcut_names(): + return { + "connect": QApplication.translate("ShortcutName", "Connect device"), + "disconnect": QApplication.translate("ShortcutName", "Disconnect device"), + "toggle_connect": QApplication.translate("ShortcutName", "Connect/disconnect device"), + "next_mode": QApplication.translate("ShortcutName", "Next noise control mode"), + "mode_normal": QApplication.translate("ShortcutName", "Disable noise control"), + "mode_cancellation": QApplication.translate("ShortcutName", "Enable noise cancellation"), + "mode_awareness": QApplication.translate("ShortcutName", "Enable awareness mode"), + "enable_low_latency": QApplication.translate("ShortcutName", "Enable low-latency mode"), + } diff --git a/openfreebuds_qt/tray/menu.py b/openfreebuds_qt/tray/menu.py index 9260690..7599e6a 100644 --- a/openfreebuds_qt/tray/menu.py +++ b/openfreebuds_qt/tray/menu.py @@ -70,23 +70,22 @@ def __init__(self, tray: IOfbTrayIcon, context: IOfbQtApplication, ofb: IOpenFre self.anc_level_submenu = OfbDeviceAncLevelTrayMenu(self, ofb) self.anc_level_action = self.add_menu(self.anc_level_submenu) self.anc_level_action.setVisible(False) - self.anc_separator = self.add_separator() + self.add_separator() # Extras - self.extras_section = self.new_section() - self.settings_action = self.add_item(self.tr("Settings..."), - callback=self.do_settings) + self.new_section() + self.add_item(self.tr("Settings..."), callback=self.do_settings) self.equalizer_submenu = OfbDeviceEqualizerTrayMenu(self, self.ctx) self.equalizer_action = self.add_menu(self.equalizer_submenu) self.dual_connect_submenu = OfbDeviceDualConnectTrayMenu(self, self.ctx) self.dual_connect_action = self.add_menu(self.dual_connect_submenu) - self.extras_separator = self.add_separator() + self.add_separator() # Footer - self.footer_section = self.new_section() - self.settings_action = self.add_item(self.tr("Bugreport..."), + self.new_section() + self.add_item(self.tr("Bugreport..."), callback=self.do_bugreport) - self.leave_action = self.add_item(self.tr("Leave application"), + self.add_item(self.tr("Leave application"), callback=self.do_exit) async def on_core_event(self, event: OfbCoreEvent): diff --git a/scripts/build_debian/.gitignore b/scripts/build_debian/.gitignore index e85185a..25343b7 100644 --- a/scripts/build_debian/.gitignore +++ b/scripts/build_debian/.gitignore @@ -1,4 +1,2 @@ /dist -*.whl -*.tar.gz - +openfreebuds* diff --git a/scripts/build_debian/build.sh b/scripts/build_debian/build.sh index 1331bf0..ed7fbeb 100755 --- a/scripts/build_debian/build.sh +++ b/scripts/build_debian/build.sh @@ -5,7 +5,4 @@ cd "$(dirname "$0")" dpkg-buildpackage -S dpkg-buildpackage -b -mv ../*.deb . -mv ../*.buildinfo . -mv ../*.changes . - +mv ../openfreebuds_* . diff --git a/scripts/openfreebuds.desktop b/scripts/openfreebuds.desktop index 1e3871a..fc6d887 100644 --- a/scripts/openfreebuds.desktop +++ b/scripts/openfreebuds.desktop @@ -1,9 +1,14 @@ [Desktop Entry] Version=1.1 Type=Application -Name=Openfreebuds -Comment=HUAWEI Freebuds manager +Name=OpenFreebuds +GenericName=Headphones manager +GenericName[ru]=Управление наушниками +Comment=Open-source client app for HUAWEI FreeBuds +Comment[ru]=Open-source клиент для устройств HUAWEI FreeBuds Icon=/usr/lib/python3/dist-packages/openfreebuds_qt/assets/icon.png Exec=/usr/bin/openfreebuds_qt Actions= +Terminal=false Categories=Utility; +Keywords=huawei;headphones;headset;earphones