Tested with kubuntu-22.04-desktop-amd64.iso. Running "pkexec ubuntu-bug -f" failed to determine that there is a desktop, because neither DESKTOP nor WAYLAND_DISPLAY are set:
sudo on the other hand preserves XAUTHORITY and DISPLAY.
If you think that apport should not show a GUI when run under sudo, please open a separate bug against apport. This bug report is about sudo. sudo preserves some environment variables to run GUI applications, but not enough to get the theme right.
Tested with kubuntu- 22.04-desktop- amd64.iso. Running "pkexec ubuntu-bug -f" failed to determine that there is a desktop, because neither DESKTOP nor WAYLAND_DISPLAY are set:
$ pkexec env | grep -Ev '^(LC|LS| PATH|TERM| COLOR|LANG) '
SHELL=/bin/bash
LOGNAME=root
USER=root
HOME=/root
PKEXEC_UID=1000
sudo on the other hand preserves XAUTHORITY and DISPLAY.
If you think that apport should not show a GUI when run under sudo, please open a separate bug against apport. This bug report is about sudo. sudo preserves some environment variables to run GUI applications, but not enough to get the theme right.