Skip to content

Commit

Permalink
[Fix] Flatpak ConfigLock detection
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Nov 5, 2024
1 parent 2f0faa4 commit d88f706
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
8 changes: 7 additions & 1 deletion openfreebuds_qt/config/config_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from openfreebuds.constants import STORAGE_PATH
from openfreebuds.utils.logger import create_logger
from openfreebuds_qt.config.dbus_config_lock import DBusConfigLock

log = create_logger("ConfigLock")

Expand All @@ -15,7 +16,12 @@ class ConfigLock:
owned: bool = False

@staticmethod
def acquire():
async def acquire():
if sys.platform == "linux" and os.path.isfile("/app/is_container"):
ConfigLock.owned = await DBusConfigLock.acquire()
log.info(f"DBus ConfigLock result {ConfigLock.owned}")
return

if ConfigLock._path.is_file():
try:
with open(ConfigLock._path, "r") as f:
Expand Down
32 changes: 32 additions & 0 deletions openfreebuds_qt/config/dbus_config_lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import asyncio

from dbus_next.aio import MessageBus
from dbus_next.service import ServiceInterface


class DBusConfigLock:
task: asyncio.Task
bus: MessageBus

@staticmethod
async def acquire():
bus = await MessageBus().connect()
DBusConfigLock.bus = bus

dbus_introspect = await bus.introspect("org.freedesktop.DBus", "/org/freedesktop/DBus")
dbus_obj = bus.get_proxy_object("org.freedesktop.DBus", "/org/freedesktop/DBus",
dbus_introspect)
dbus = dbus_obj.get_interface("org.freedesktop.DBus")

# noinspection PyUnresolvedReferences
for name in await dbus.call_list_names():
if name == "pw.mmk.OpenFreebuds":
bus.disconnect()
return False

# Provide void DBus service
interface = ServiceInterface('pw.mmk.OpenFreebuds')
bus.export('/com/example/sample0', interface)
await bus.request_name('pw.mmk.OpenFreebuds')

return True
2 changes: 1 addition & 1 deletion openfreebuds_qt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(self, args):
logging.getLogger(tag).disabled = True

# App configuration
ConfigLock.acquire()
self.config.update_fallback_values(self)

# Qt base configs
Expand Down Expand Up @@ -86,6 +85,7 @@ def start(args):

async def boot(self):
try:
await ConfigLock.acquire()
await self._stage_setup_ofb()

if self.args.shortcut != "":
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_flatpak/pw.mmk.OpenFreebuds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ finish-args:
- --system-talk-name=org.bluez
# Display tray icon
- --talk-name=org.kde.StatusNotifierWatcher
# Check running state, enable/disable autostart
# Enable/disable autostart from in-app settings
- --talk-name=org.freedesktop.impl.portal.desktop.gnome

cleanup-commands:
Expand Down

0 comments on commit d88f706

Please sign in to comment.