package dev.photosync.platform.mixin;

import com.mojang.blaze3d.platform.Window;
import dev.photosync.platform.WindowTitle;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
 * Hooks the window title, for the upload description's client name.
 *
 * <p>There is no way to read the title back from GLFW before lwjgl 3.4 (the
 * buckets below 26.x ship 3.3.x, which has no {@code glfwGetWindowTitle}), so
 * the title is captured as every caller passes it through {@code setTitle} --
 * the one public way to change it, and the one every title mod uses.
 *
 * <p>Like {@code QuitMixin}, the hook only records into a static holder and
 * holds no state of its own. {@code setTitle(String)} has not moved in the
 * supported range; the day a bucket disagrees, this class moves down into all
 * nine copies like any other common class.
 */
@Mixin(Window.class)
public class TitleMixin {

    @Inject(method = "setTitle", at = @At("HEAD"))
    private void photosync$capture(String title, CallbackInfo callback) {
        WindowTitle.record(title);
    }
}
