Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #211

Merged
merged 3 commits into from
Jan 28, 2024
Merged

Dev #211

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ websockets = "*"
requests = "*"
pinecil = "*"
typing_extensions = "*"
rich = "*"

[dev-packages]
black = "*"
Expand Down
65 changes: 65 additions & 0 deletions backend/bluetooth_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import subprocess


def run_command(command: str) -> tuple[bool, str]:
try:
result = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
return True, result.stdout.strip()
except subprocess.CalledProcessError as e:
return False, e.stderr.strip()


class ServiceCheck:
def __init__(self, name: str, command: str, recommend: str = ""):
self.command = command
self.name = name
self.recommend = recommend
self.success = False

def run(self) -> bool:
self.success, _ = run_command(self.command)
return self.success


def run_checks() -> tuple[bool, list[str]]:
checks = [
ServiceCheck("BlueZ", "bluetoothd -v", recommend="Install BlueZ"),
ServiceCheck(
"bluetooth.service active",
"systemctl status bluetooth.service",
recommend="Install/Start bluetooth.service",
),
ServiceCheck(
"D-Bus configuration file for Bluetooth",
"test -f /etc/dbus-1/system.d/bluetooth.conf || test -f /usr/share/dbus-1/system.d/bluetooth.conf || test -f /var/lib/dbus-1/system.d/bluetooth.conf",
recommend="Install D-Bus configuration file for Bluetooth",
),
]
all_passed = all([c.run() for c in checks])
return all_passed, [
f"{c.name} check failed. {c.recommend}" for c in checks if not c.success
]


def main():
all_passed, errors = run_checks()
if not all_passed:
print("Bluetooth check failed:")
print("\n".join(errors))
return
success, output = run_command("journalctl -u bluetooth.service -n 10")
if success:
print("Last 10 lines of bluetooth.service logs:\n" + output)
else:
print("Failed to retrieve bluetooth.service logs.")


if __name__ == "__main__":
main()
12 changes: 11 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import asyncio
import os
import sys
from pinecil_monitor import PinecilMonitor, PinecilFinder
from ws_server import CommandProcessor, WebSocketHandler
from version_checker import VersionChecker
import logging
from io_utils import parse_cmd_args, get_resource_path
from bluetooth_check import run_checks as run_bluetooth_checks
from rich.logging import RichHandler

LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper()
timestamp_format = "%H:%M:%S"
logging.basicConfig(
level=LOG_LEVEL,
format="%(asctime)s.%(msecs)03d::%(levelname)s::%(message)s",
datefmt=timestamp_format,
handlers=[RichHandler(rich_tracebacks=True)],
)

DEFAULT_HOST = "0.0.0.0"
Expand All @@ -22,7 +26,13 @@ async def main(stop_event=asyncio.Event()):
host, port = parse_cmd_args(DEFAULT_HOST, DEFAULT_PORT)
if not host or not port:
return

if sys.platform == "linux":
bt_ok, bt_errors = run_bluetooth_checks()
if not bt_ok:
logging.warning(
"Bluetooth check failed. Application may not work as expected."
)
logging.warning("\n" + "\n".join(bt_errors))
pinesam_url = "https://api.github.com/repos/builder555/PineSAM/releases/latest"
ironos_url = "https://api.github.com/repos/Ralim/IronOS/releases/latest"
app_version_manager = VersionChecker(
Expand Down
Binary file modified docs/img/full_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.2.2
Loading