Skip to content

Commit

Permalink
fix: utilize proper introspective method to get konsole sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Seas0 committed Nov 23, 2024
1 parent f855d77 commit 8eb6079
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions yin_yang/plugins/konsole.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
import re
import subprocess
from xml.etree import ElementTree as ET
from configparser import ConfigParser
from itertools import chain
from pathlib import Path
Expand Down Expand Up @@ -74,7 +74,7 @@ def set_mode(self, dark: bool) -> bool:
logger.debug(f'Changing profile in konsole session {proc_id}')
set_profile(f'org.kde.konsole-{proc_id}', profile)

set_profile('org.kde.konsole', profile) # konsole may don't have session dbus like above
# set_profile('org.kde.konsole', profile) # konsole may don't have session dbus like above
set_profile('org.kde.yakuake', profile)

process_ids = [
Expand Down Expand Up @@ -238,21 +238,19 @@ def set_profile(service: str, profile: str):
# connect to the session bus
connection = QDBusConnection.sessionBus()

# maybe it's possible with pyside6 dbus packages, but this was simpler and worked
try:
sessions = subprocess.check_output(f'qdbus {service} | grep "Sessions/"', shell=True)
except subprocess.CalledProcessError:
try:
sessions = subprocess.check_output(
f'qdbus org.kde.konsole | grep "Sessions/"', shell=True
)
logger.debug(f'Found org.kde.konsole, use that instead')
service = "org.kde.konsole"
except subprocess.CalledProcessError:
# happens when dolphins konsole is not opened
logger.debug(f'No Konsole sessions available in service {service}, skipping')
return
sessions = sessions.decode('utf-8').removesuffix('\n').split('\n')
# better to get DBus service and session with proper DBus introspection
query = QDBusMessage.createMethodCall(
service,
'/Sessions',
'org.freedesktop.DBus.Introspectable',
'Introspect'
)
response = connection.call(query)
if response.type() == QDBusMessage.MessageType.ErrorMessage:
logger.error(f'Error while introspecting {service}: {response.errorMessage()}')
return
root = ET.fromstring(response.arguments()[0])
sessions = [f"/Sessions/{child.attrib['name']}" for child in root.findall('node')]

# loop: process sessions
for session in sessions:
Expand Down

0 comments on commit 8eb6079

Please sign in to comment.