Repository: skyline-emu/skyline
File: app/src/main/cpp/skyline/applet/controller_applet.cpp (C++)

Code before:
namespace skyline::applet {
    ControllerApplet::ControllerApplet(const DeviceState &state,
                                       service::ServiceManager &manager,
                                       std::shared_ptr<kernel::type::KEvent> onAppletStateChanged,
                                       std::shared_ptr<kernel::type::KEvent> onNormalDataPushFromApplet,
                                       std::shared_ptr<kernel::type::KEvent> onInteractiveDataPushFromApplet,
                                       service::applet::LibraryAppletMode appletMode)
        : IApplet(state, manager, std::move(onAppletStateChanged), std::move(onNormalDataPushFromApplet), std::move(onInteractiveDataPushFromApplet), appletMode) {}

    void ControllerApplet::HandleShowControllerSupport(input::NpadStyleSet styleSet, ControllerAppletVersion version, span<u8> arg) {
        // Generic macro due to both versions of arguments sharing the same fields but having different layouts
        auto handle{[&](auto controllerSupportModeArg) {
            Logger::InfoNoPrefix("Controller Support: "
                                 "Player Count: {} - {}, "
                                 "Take Over Connection: {}, Left Justify: {}, Dual Joy-Con Allowed: {}, Single Mode Enabled: {}, "
                                 "Identification Color Enabled: {}, Explain Text Enabled: {}",
                                 controllerSupportModeArg.playerCountMin, controllerSupportModeArg.playerCountMax,
                                 controllerSupportModeArg.enableTakeOverConnection, controllerSupportModeArg.enableLeftJustify, controllerSupportModeArg.enablePermitJoyDual, controllerSupportModeArg.enableSingleMode,
                                 controllerSupportModeArg.enableIdentificationColor, controllerSupportModeArg.enableExplainText);

            // Here is where we would trigger the applet UI

            auto &npad{state.input->npad};
            std::scoped_lock lock{npad.mutex};

            PushNormalDataAndSignal(std::make_shared<service::am::ObjIStorage<ControllerSupportResultInfo>>(state, manager, ControllerSupportResultInfo{
                .playerCount = static_cast<i8>(controllerSupportModeArg.enableSingleMode ? 1 : npad.GetConnectedControllerCount()),
                .selectedId = [&npad]() {
                    if (npad.controllers[0].device) {
                        return npad.controllers[0].device->id;
                    } else {
                        Logger::Warn("Controller requested but none connected!");
                        return input::NpadId::Player1; // Fallback to player 1
                    }
                }(),
                .result = {}
            }));
        }};

        switch (version) {
            case ControllerAppletVersion::Version3:
            case ControllerAppletVersion::Version4:
            case ControllerAppletVersion::Version5:
                handle(arg.as<ControllerSupportArgOld>());
                break;
            case ControllerAppletVersion::Version7:
            case ControllerAppletVersion::Version8:
                handle(arg.as<ControllerSupportArgNew>());
                break;
            default:
                Logger::Warn("Unsupported controller applet version {}", static_cast<u32>(version));

Review comment (suggestion):
```suggestion
            PushNormalDataAndSignal(std::make_shared<service::am::ObjIStorage<ControllerSupportResultInfo>>
```

Code after:
namespace skyline::applet {
    ControllerApplet::ControllerApplet(const DeviceState &state,
                                       service::ServiceManager &manager,
                                       std::shared_ptr<kernel::type::KEvent> onAppletStateChanged,
                                       std::shared_ptr<kernel::type::KEvent> onNormalDataPushFromApplet,
                                       std::shared_ptr<kernel::type::KEvent> onInteractiveDataPushFromApplet,
                                       service::applet::LibraryAppletMode appletMode)
        : IApplet{state, manager, std::move(onAppletStateChanged), std::move(onNormalDataPushFromApplet), std::move(onInteractiveDataPushFromApplet), appletMode} {}

    void ControllerApplet::HandleShowControllerSupport(input::NpadStyleSet styleSet, ControllerAppletVersion version, span<u8> arg) {
        // Generic macro due to both versions of arguments sharing the same fields but having different layouts
        auto handle{[&](auto controllerSupportModeArg) {
            Logger::InfoNoPrefix("Controller Support: "
                                 "Player Count: {} - {}, "
                                 "Take Over Connection: {}, Left Justify: {}, Dual Joy-Con Allowed: {}, Single Mode Enabled: {}, "
                                 "Identification Color Enabled: {}, Explain Text Enabled: {}",
                                 controllerSupportModeArg.playerCountMin, controllerSupportModeArg.playerCountMax,
                                 controllerSupportModeArg.enableTakeOverConnection, controllerSupportModeArg.enableLeftJustify, controllerSupportModeArg.enablePermitJoyDual, controllerSupportModeArg.enableSingleMode,
                                 controllerSupportModeArg.enableIdentificationColor, controllerSupportModeArg.enableExplainText);

            // Here is where we would trigger the applet UI

            auto &npad{state.input->npad};
            std::scoped_lock lock{npad.mutex};

            PushNormalDataAndSignal(std::make_shared<service::am::ObjIStorage<ControllerSupportResultInfo>>(state, manager, ControllerSupportResultInfo{
                .playerCount = static_cast<i8>(controllerSupportModeArg.enableSingleMode ? 1 : npad.GetConnectedControllerCount()),
                .selectedId = [&npad]() {
                    if (npad.controllers[0].device) {
                        return npad.controllers[0].device->id;
                    } else {
                        Logger::Warn("Controller requested but none connected!");
                        return input::NpadId::Player1; // Fallback to player 1
                    }
                }(),
                .result = {}
            }));
        }};

        switch (version) {
            case ControllerAppletVersion::Version3:
            case ControllerAppletVersion::Version4:
            case ControllerAppletVersion::Version5:
                handle(arg.as<ControllerSupportArgOld>());
                break;
            case ControllerAppletVersion::Version7:
            case ControllerAppletVersion::Version8:
                handle(arg.as<ControllerSupportArgNew>());
                break;
            default:
                Logger::Warn("Unsupported controller applet version {}", static_cast<u32>(version));