Automatic scaling for QtQuick

I’m making a system update app for Bazzite using Kirigami, and have gotten very close to completion. The biggest remaining issue is that the UI does not scale in gamescope session. (A secondary separate issue is the theme not applying, but proper scaling is very important for high-dpi displays.)

Ideally, the app would follow how a desktop wants to scale the app while automatically scaling itself if run inside of gamescope session. What would be the recommended way to handle this?

What it looks like in KDE:

What it looks like in gamescope session (on high-dpi screens):

The Item type has a scale property, but I could only use that to scale Item-based components (all actions would need to be replaced, and hopefully not too many custom Kirigami components).

I came up with this, it’ll need a bit more tuning but seems to perfectly handle auto-scaling for gamescope. Now I just ideally need it to use breeze-dark

int main(int argc, char *argv[])
{
    /*
        Gamescope-session does not apply any app scaling. 
        This ensures it is scaled well even on high-DPI, while respecting regular desktop settings.

        This may behave strangely in multi-monitor environments, but gamescope should keep those hidden from the app.
        Example: kde window rules to move the app to a certain display seem to break this scaling check
    */
    if (
        qEnvironmentVariable("XDG_CURRENT_DESKTOP").trimmed().toLower().contains(u"gamescope"_s);
         && qEnvironmentVariableIsEmpty("QT_SCALE_FACTOR")
        ) 
    {
        QGuiApplication screenGetter(argc, argv);
        QScreen *screen = screenGetter.primaryScreen();
        const float height = screen->geometry().height();
        const float scale_factor = height / BASE_HEIGHT;
        qputenv("QT_SCALE_FACTOR", QByteArray::number(scale_factor));
    }
//... load the actual application