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

fix: utilize proper introspective method to get konsole sessions #319

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 17 additions & 18 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 @@ -237,22 +237,21 @@ def create_profiles(self):
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')
path = '/Sessions'

# better to get DBus service and session with proper DBus introspection
query = QDBusMessage.createMethodCall(
service,
path,
'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"{path}/{child.attrib['name']}" for child in root.findall('node')]

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