Skip to content

Commit

Permalink
[Refactor] Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Sep 23, 2024
1 parent d7a4ffb commit 18007a6
Show file tree
Hide file tree
Showing 27 changed files with 30 additions and 49 deletions.
1 change: 0 additions & 1 deletion openfreebuds/driver/generic/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Optional

from openfreebuds.constants import OfbEventKind
Expand Down
1 change: 0 additions & 1 deletion openfreebuds/driver/huawei/driver/generic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
from contextlib import suppress

from openfreebuds.driver.generic import OfbDriverHandlerGeneric, OfbDriverSppGeneric
from openfreebuds.driver.huawei.package import HuaweiSppPackage
Expand Down
2 changes: 1 addition & 1 deletion openfreebuds/driver/huawei/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def to_table_string(self):
out += "\n"
return out

def find_param(self, *args, **kwargs) -> bytes:
def find_param(self, *args) -> bytes:
"""
Get parameter value by one of provided types
"""
Expand Down
3 changes: 0 additions & 3 deletions openfreebuds/driver/huawei/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from array import array


def build_table_row(ln, val, description_table=None):
if description_table is not None and val in description_table:
val = f"{val} ({description_table[val]})"
Expand Down
1 change: 0 additions & 1 deletion openfreebuds/manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from aiohttp.web_routedef import RouteTableDef

import openfreebuds_backend
from openfreebuds import webserver
from openfreebuds.constants import OfbEventKind
from openfreebuds.driver import DEVICE_TO_DRIVER_MAP
Expand Down
1 change: 1 addition & 0 deletions openfreebuds/utils/event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def include_subscription(self, callback_id: str, subscription):
self._child_subs[callback_id].cancel()

async def _handler():
# noinspection PyProtectedMember
queue = subscription._new_queue(callback_id, None)
while True:
await self.send_message(*(await queue.get()))
Expand Down
2 changes: 0 additions & 2 deletions openfreebuds_backend/errors.py

This file was deleted.

3 changes: 1 addition & 2 deletions openfreebuds_backend/windows/bt_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# noinspection PyUnresolvedReferences,PyPackageRequirements
from winsdk.windows.networking import HostName

from openfreebuds_backend.errors import BluetoothNotAvailableError
from openfreebuds_backend.exception import OfbBackendDependencyMissingError

extra_tools_dir = 'C:\\Program Files (x86)\\Bluetooth Command Line Tools\\bin'
Expand Down Expand Up @@ -76,7 +75,7 @@ async def bt_list_devices():
selector = BluetoothDevice.get_device_selector_from_pairing_state(True)
devices = await DeviceInformation.find_all_async(selector, [], DeviceInformationKind.DEVICE)
except OSError:
raise BluetoothNotAvailableError("Got OSError, looks like bluetooth isn't installed")
return []

for a in devices:
try:
Expand Down
1 change: 0 additions & 1 deletion openfreebuds_backend/windows/misc_win32.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pathlib
import subprocess
import sys
Expand Down
1 change: 0 additions & 1 deletion openfreebuds_backend/windows/ui_win32.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import winreg


Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_cmd/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .launcher import main

main()
main()
2 changes: 1 addition & 1 deletion openfreebuds_qt/app/module/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from openfreebuds import DEVICE_TO_DRIVER_MAP
from openfreebuds_qt.app.module.common import OfbQtCommonModule
from openfreebuds_qt.constants import LINK_WEBSITE, LINK_GITHUB, ASSETS_PATH
from openfreebuds_qt.constants import LINK_WEBSITE, LINK_GITHUB
from openfreebuds_qt.designer.about_module import Ui_OfbQtAboutModule
from openfreebuds_qt.version_info import VERSION, LIBRARIES

Expand Down
16 changes: 6 additions & 10 deletions openfreebuds_qt/app/module/dual_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@ async def on_connect_toggle(self):
async with qt_error_handler("OfbQtDualConnectModule_ToggleConnect", self.ctx):
addr, data = self._all_data[self._current_index]

try:
self.button_toggle_connect.setEnabled(False)
await self.ofb.set_property(
"dual_connect",
f"{addr}:connected",
json.dumps(not data["connected"])
)
except Exception:
log.exception(f"Trying to switch connection state of {addr}")
self.button_toggle_connect.setEnabled(True)
self.button_toggle_connect.setEnabled(False)
await self.ofb.set_property(
"dual_connect",
f"{addr}:connected",
json.dumps(not data["connected"])
)

def _update_current_device_view(self, addr: str, data: dict):
self.current_device_name.setText(data['name'])
Expand Down
1 change: 0 additions & 1 deletion openfreebuds_qt/app/module/linux_related.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import webbrowser
from contextlib import suppress

from PyQt6.QtCore import pyqtSlot
from PyQt6.QtWidgets import QMessageBox
Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/app/module/sound_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json

from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QSlider, QMenu, QInputDialog, QMessageBox, QFileDialog, QApplication
from PyQt6.QtWidgets import QSlider, QMenu, QInputDialog, QMessageBox, QFileDialog
from qasync import asyncSlot

from openfreebuds.exceptions import OfbTooManyItemsError
Expand Down
Binary file removed openfreebuds_qt/assets/icon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions openfreebuds_qt/config/config_lock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import sys
from pathlib import Path

from psutil import Process, AccessDenied, NoSuchProcess

from openfreebuds.constants import STORAGE_PATH
from openfreebuds.utils.logger import create_logger
from openfreebuds_qt.constants import STORAGE_PATH


log = create_logger("ConfigLock")

Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from qasync import QApplication

from openfreebuds.constants import STORAGE_PATH
from openfreebuds_backend import is_dark_taskbar
from openfreebuds_qt.constants import STORAGE_PATH

CONFIG_PATH = STORAGE_PATH / "openfreebuds_qt.json"

Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from openfreebuds import APP_ROOT, STORAGE_PATH
from openfreebuds import APP_ROOT

ASSETS_PATH = APP_ROOT / "openfreebuds_qt" / "assets"
I18N_PATH = APP_ROOT / "openfreebuds_qt" / "assets" / "i18n"
Expand Down
5 changes: 2 additions & 3 deletions openfreebuds_qt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from qasync import QEventLoop

from openfreebuds import IOpenFreebuds, create as create_ofb, OfbEventKind
from openfreebuds.constants import STORAGE_PATH
from openfreebuds.utils.logger import setup_logging, screen_handler, create_logger
from openfreebuds_qt.app.main import OfbQtMainWindow
from openfreebuds_qt.config import OfbQtConfigParser, ConfigLock
from openfreebuds_qt.constants import IGNORED_LOG_TAGS, I18N_PATH, STORAGE_PATH
from openfreebuds_qt.constants import IGNORED_LOG_TAGS, I18N_PATH
from openfreebuds_qt.generic import IOfbQtApplication
from openfreebuds_qt.tray.main import OfbTrayIcon
from openfreebuds_qt.utils import OfbQtDeviceAutoSelect, OfbQtHotkeyService, list_available_locales
Expand Down Expand Up @@ -123,8 +124,6 @@ async def boot(self):
self.qt_app.exit(e.args[0])
ConfigLock.release()
return
except Exception:
log.exception("App boot failed")

async def exit(self, ret_code: int = 0):
await self.tray.close()
Expand Down
13 changes: 5 additions & 8 deletions openfreebuds_qt/tray/menu.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from datetime import datetime
from typing import Optional

from PyQt6.QtGui import QAction
from qasync import asyncSlot

from openfreebuds import IOpenFreebuds, OfbEventKind
from openfreebuds_backend.exception import OfbBackendDependencyMissingError
from openfreebuds_qt.config import OfbQtConfigParser
from openfreebuds_qt.generic import IOfbTrayIcon, IOfbQtApplication
from openfreebuds_qt.tray.dialogs import OfbQtDependencyMissingDialog
from openfreebuds_qt.tray.menu_anc_level import OfbDeviceAncLevelTrayMenu
from openfreebuds_qt.tray.menu_dual_connect import OfbDeviceDualConnectTrayMenu
from openfreebuds_qt.tray.menu_equalizer import OfbDeviceEqualizerTrayMenu
from openfreebuds_qt.utils.core_event import OfbCoreEvent
from openfreebuds_qt.generic import IOfbTrayIcon, IOfbQtApplication
from openfreebuds_qt.tray.menu_generic import OfbQtTrayMenuCommon
from openfreebuds_qt.tray.menu_anc_level import OfbDeviceAncLevelTrayMenu
from openfreebuds_qt.utils.core_event import OfbCoreEvent
from openfreebuds_qt.utils.report_tool import OfbQtReportTool


Expand Down Expand Up @@ -84,10 +83,8 @@ def __init__(self, tray: IOfbTrayIcon, context: IOfbQtApplication, ofb: IOpenFre

# Footer
self.new_section()
self.add_item(self.tr("Bugreport..."),
callback=self.do_bugreport)
self.add_item(self.tr("Leave application"),
callback=self.do_exit)
self.add_item(self.tr("Bugreport..."), callback=self.do_bugreport)
self.add_item(self.tr("Leave application"), callback=self.do_exit)

async def on_core_event(self, event: OfbCoreEvent, state: int):
if event.kind_in([OfbEventKind.STATE_CHANGED, OfbEventKind.QT_SETTINGS_CHANGED]):
Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/tray/menu_dual_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def update_ui(self):
def _add_item(self, addr: str, display_name: str, active: bool = False):
@asyncSlot()
async def toggle(_):
await self.ofb.set_property("dual_connect", f"{addr}:connected", not active)
await self.ofb.set_property("dual_connect", f"{addr}:connected", json.dumps(not active))
await self.update_ui()

self.add_item(text=display_name,
Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/utils/hotkeys/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def on_release(self, pressed_key):
from pynput import keyboard
if isinstance(pressed_key, keyboard.Key):
val = str(pressed_key).replace("Key.", "")
if val == "esc" and len(self._specials) == 1 :
if val == "esc" and len(self._specials) == 1:
self.cancel()
return
if val in self._specials:
Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/utils/mpris/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from openfreebuds_backend.linux.dbus.mpris import MPRISPProxy
except ImportError:
pass
MPRISPProxy = None

log = create_logger("OfbQtMPRISHelperService")

Expand Down
2 changes: 1 addition & 1 deletion openfreebuds_qt/utils/report_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from PyQt6.QtCore import QT_VERSION_STR, PYQT_VERSION_STR

import openfreebuds_backend
from openfreebuds.constants import STORAGE_PATH
from openfreebuds.utils.logger import get_full_log
from openfreebuds_qt.config import OfbQtConfigParser
from openfreebuds_qt.config.config_lock import ConfigLock
from openfreebuds_qt.constants import STORAGE_PATH
from openfreebuds_qt.generic import IOfbQtApplication
from openfreebuds_qt.version_info import VERSION

Expand Down
3 changes: 1 addition & 2 deletions openfreebuds_qt/utils/updater/service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import sys
from typing import Optional

from PyQt6.QtWidgets import QWidget

from openfreebuds.constants import STORAGE_PATH
from openfreebuds.utils.logger import create_logger
from openfreebuds_qt.config import OfbQtConfigParser
from openfreebuds_qt.constants import STORAGE_PATH
from openfreebuds_qt.version_info import VERSION

try:
Expand Down
3 changes: 2 additions & 1 deletion scripts/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

URL_FLATPAK_PIP_GENERATOR = ("https://github.com/flatpak/flatpak-builder-tools/raw/refs/heads/master"
"/pip/flatpak-pip-generator")
BASE_CHANGELOG_URL = "https://github.com/melianmiko/OpenFreebuds/blob/main/CHANGELOG.md"

PROJECT_ROOT = Path(__file__).parents[1]
FLATPAK_PIP_GENERATOR_PATH = PROJECT_ROOT / "scripts" / "tools" / "flatpak-pip-generator"
Expand Down Expand Up @@ -120,7 +121,7 @@ def bump_metainfo(line: str):
new_data = [
line,
f' <release version="{NEW_VERSION}" date="{date.today()}">',
f' <url type="details">https://github.com/melianmiko/OpenFreebuds/blob/main/CHANGELOG.md#v{NEW_VERSION}</url>',
f' <url type="details">{BASE_CHANGELOG_URL}#v{NEW_VERSION}</url>',
f' <description>',
f' <ul>',
*[f" <li>{escape(line[2:])}</li>" for line in CHANGELOG],
Expand Down

0 comments on commit 18007a6

Please sign in to comment.