using System;
using System.Collections.Generic;
using System.IO;
using Codely.Newtonsoft.Json;
using Codely.Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
using UnityTcp.Editor.Helpers;
namespace UnityTcp.Editor.Notifier
{
///
/// Batches new Unity console activity and forwards it to notifier clients as a
/// "console_log_changed" event (one flush per editor tick).
///
/// Source: , which fires for
/// every console entry regardless of the thread it was raised on — Debug.* calls,
/// uncaught exceptions, AND C# compiler errors/warnings (Unity routes those through
/// the log system too; their file/line/column are embedded in the message text,
/// e.g. "Assets/Foo.cs(12,3): error CS1002: ; expected"). Subscribing to this one
/// callback covers all of them without duplicates — also hooking
/// CompilationPipeline.assemblyCompilationFinished would re-deliver every compiler
/// message a second time.
///
/// The payload mirrors what 's
/// action="get" with types=["all"] returns, i.e.
/// wrapping the entry
/// array: { success, message, rev, data: [ { type, message, file, line, stackTrace }, … ] }.
///
// [InitializeOnLoad] // disable this notifier
public static class ConsoleLogChangedNotifier
{
private const string EventType = "console_log_changed";
// Safety valve for pathological single-tick bursts (e.g. Debug.Log in a tight
// loop): never queue more than this many entries per flush.
private const int MaxEntriesPerFlush = 5000;
private static readonly object _gate = new object();
private static readonly List