diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml new file mode 100644 index 0000000..32346b8 --- /dev/null +++ b/.github/workflows/on_push.yml @@ -0,0 +1,70 @@ +name: On `push` actions +on: [push] +jobs: + PyTest: + runs-on: ubuntu-24.04 + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install Poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: "1.8.3" + - uses: actions/checkout@v4 + - name: Set up poetry environment + run: poetry install --without extras + - name: Run pytest + run: poetry run pytest + + BuildExe: + runs-on: windows-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install Poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: "1.8.3" + - uses: actions/checkout@v4 + - name: Set up poetry environment + run: poetry install + - name: Change in-app version + run: bash.exe -c "./scripts/bump_version.sh \"0.99.git.$(git rev-parse HEAD)\"" + - name: Run build script + run: .\scripts/build_win32\make.cmd + - name: Upload bundle + uses: actions/upload-artifact@v4 + with: + name: Win32 installer + path: .\scripts\build_win32\dist\openfreebuds_install.exe + if-no-files-found: error + + BuildDeb: + runs-on: ubuntu-24.04 + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install Poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: "1.8.3" + - uses: actions/checkout@v4 + - name: Install dev-dependencies + run: | + sudo apt install -y build-essential + sudo ./scripts/install_dpkg_dependencies.sh + - name: Set up poetry environment + run: poetry install + - name: Change in-app version + run: bash ./scripts/bump_version.sh "0.99.git.$(git rev-parse HEAD)" + - name: Run build script + run: bash ./scripts/build_debian/build.sh + - name: Upload bundle + uses: actions/upload-artifact@v4 + with: + name: Debian package + path: ./scripts/build_debian/openfreebuds_*.deb + if-no-files-found: error diff --git a/openfreebuds_backend/linux/ui_gtk.py b/openfreebuds_backend/linux/ui_gtk.py index f9078cb..293d7f9 100644 --- a/openfreebuds_backend/linux/ui_gtk.py +++ b/openfreebuds_backend/linux/ui_gtk.py @@ -1,45 +1,19 @@ import logging -import gi - -gi.require_version("Gtk", "3.0") log = logging.getLogger("OfbLinuxBackend") -# noinspection PyPackageRequirements -def ask_string(message, callback): - from gi.repository import GLib, Gtk - - # noinspection PyArgumentList,PyUnresolvedReferences - def show_async(): - # noinspection PyTypeChecker - dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK_CANCEL, "OpenFreebuds") - dialog.format_secondary_text(message) - - area = dialog.get_content_area() - entry = Gtk.Entry() - entry.set_margin_start(16) - entry.set_margin_end(16) - area.pack_end(entry, False, False, 0) - dialog.show_all() - - response = dialog.run() - text = entry.get_text() - dialog.destroy() - - if response != Gtk.ResponseType.OK: - text = None - - callback(text) - - GLib.idle_add(show_async) - - def is_dark_taskbar(): - from gi.repository import Gtk - settings = Gtk.Settings() - defaults = settings.get_default() - theme_name = defaults.get_property("gtk-theme-name") - log.info(f"System theme name is {theme_name}") - return "Dark" in theme_name + try: + import gi + gi.require_version("Gtk", "3.0") + + from gi.repository import Gtk + settings = Gtk.Settings() + defaults = settings.get_default() + theme_name = defaults.get_property("gtk-theme-name") + log.info(f"System theme name is {theme_name}") + return "Dark" in theme_name + except ImportError: + return False diff --git a/poetry.lock b/poetry.lock index 4ee84ba..bc250f1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1184,4 +1184,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "f4ac33aa856ab0b87da379c4aa9cf27cc2cdd42312a9356713e9e1f1ec54ef6f" +content-hash = "ecce3259a2c3f5f62c26b80f4fc1890f24753a7f3f815ef28fa9f26e257ff3d2" diff --git a/pyproject.toml b/pyproject.toml index 12b9691..cd331e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,19 +22,21 @@ openfreebuds_cmd = 'openfreebuds_cmd:main' [tool.poetry.dependencies] python = ">=3.10,<3.13" pillow = "^10.4.0" -aiocmd = ">=0.1.5,<0.2.0" psutil = "^6.0.0" aiohttp = "^3.10.5" -pyinstaller = "6.10.0" -pygobject = { version = "^3.48.1", platform = "linux" } winsdk = { version = "1.0.0b10", platform = "win32" } pyqt6 = "^6.7.1" qasync = "^0.27.1" sdbus = { version = "^0.12.0", platform = "linux" } pynput = "^1.7.7" -[tool.poetry.group.goodies.dependencies] +[tool.poetry.group.release.dependencies] +pyinstaller = "6.10.0" + +[tool.poetry.group.extras.dependencies] +aiocmd = ">=0.1.5,<0.2.0" pynput = ">=1.7.6,<1.8.0" +pygobject = { version = "^3.48.1", platform = "linux" } [tool.poetry.group.test.dependencies] pytest = "^8.3.2" diff --git a/scripts/build_debian/Makefile b/scripts/build_debian/Makefile index a259e7a..b770d27 100644 --- a/scripts/build_debian/Makefile +++ b/scripts/build_debian/Makefile @@ -4,15 +4,15 @@ DIST_PACKAGES_PATH := /usr/lib/python3/dist-packages WHEEL_FILE := $(shell find ${PWD} -maxdepth 1 -name '*.whl') all: - cd ../.. && pyuic6 openfreebuds_qt/designer - cd ../.. && /usr/lib/qt6/bin/lrelease openfreebuds_qt/assets//i18n + bash ../make_qt_parts.sh cd ../.. && poetry build cp ../../dist/openfreebuds* . install: - pip install --no-dependencies --target="${DESTDIR}${DIST_PACKAGES_PATH}" ${WHEEL_FILE} + pip install --upgrade --no-dependencies --target="${DESTDIR}${DIST_PACKAGES_PATH}" ${WHEEL_FILE} mkdir -p ${DESTDIR}/usr/bin mv ${DESTDIR}${DIST_PACKAGES_PATH}/bin/* ${DESTDIR}/usr/bin/ + sed -i '1 s/^.*$$/\#\!\/usr\/bin\/env python3/' ${DESTDIR}/usr/bin/* rm -rf ${DESTDIR}${DIST_PACKAGES_PATH}/bin mkdir -p ${DESTDIR}/usr/share/applications cp ../openfreebuds.desktop ${DESTDIR}/usr/share/applications diff --git a/scripts/build_debian/build.sh b/scripts/build_debian/build.sh index 29f3dc0..1331bf0 100755 --- a/scripts/build_debian/build.sh +++ b/scripts/build_debian/build.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash + +cd "$(dirname "$0")" + dpkg-buildpackage -S dpkg-buildpackage -b diff --git a/scripts/build_debian/debian/control b/scripts/build_debian/debian/control index d57750a..aba3b0c 100644 --- a/scripts/build_debian/debian/control +++ b/scripts/build_debian/debian/control @@ -4,7 +4,8 @@ Priority: optional Maintainer: MelianMiko Build-Depends: debhelper-compat (= 12), python3 (>= 3.11), python3-pip, pyqt6-dev-tools, - make + libcairo2-dev, gobject-introspection, libgirepository1.0-dev, + qt6-l10n-tools, make Standards-Version: 4.4.1 Homepage: https://github.com/melianmiko/OpenFreebuds @@ -12,8 +13,7 @@ Package: openfreebuds Architecture: all Depends: ${misc:Depends}, python3 (>= 3.11), - python3-gi, python3-sdbus, python3-pyqt6, python3-pil, python3-qasync, python3-aiohttp, - libgtk-3-0 + python3-sdbus, python3-pyqt6, python3-pil, python3-qasync, python3-aiohttp Description: Open-source client application for HUAWEI FreeBuds bluetooth headset series. . diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh index 9ed42ca..21c316a 100755 --- a/scripts/bump_version.sh +++ b/scripts/bump_version.sh @@ -10,12 +10,13 @@ cd "$(dirname "$0")"/.. source scripts/constants.sh # Bump python wheel version -sed -i "s/version =.*/version = \"$1\"/g" pyproject.toml +VERSION_SHORT=`echo $1 | cut -d . -f -2` +sed -i "s/^version =.*/version = \"$VERSION_SHORT\"/g" pyproject.toml # Create ./openfreebuds_qt/version_info.py echo "VERSION = '$1'" > ./openfreebuds_qt/version_info.py echo "LIBRARIES = [" >> ./openfreebuds_qt/version_info.py -poetry export --without-hashes -n | while read line +poetry export --without-hashes -n --with extras | while read line do echo " '$line'," >> ./openfreebuds_qt/version_info.py done diff --git a/scripts/install_dpkg_dependencies.sh b/scripts/install_dpkg_dependencies.sh new file mode 100755 index 0000000..2faf86d --- /dev/null +++ b/scripts/install_dpkg_dependencies.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +apt install -y $(awk ' + /^(Build-)?Depends:/ || /^ / && deps { + sub(/^[^ ]+: /, "") + deps = 1 + dep_str = dep_str ", " $0 + next + } + { deps=0 } + END { + split(dep_str, dep_array, /[,|] */) + for (d in dep_array) { + dep = dep_array[d] + gsub(/[^a-z0-9_.+-].*$/, "", dep) + if (dep && !seen[dep]++) print dep + } + }' scripts/build_debian/debian/control)