namespace qdr.app.tools.claudecodebalancewidget { public partial class SettingsForm : Form { private TextBox sessionTokenTextBox; private Button okButton; private Button cancelButton; private Button showHideButton; private Label instructionsLabel; private bool isTokenVisible = false; public string SessionToken { get; private set; } public SettingsForm(string currentToken) { SessionToken = currentToken; InitializeComponent(); sessionTokenTextBox.Text = currentToken; } //private void InitializeComponent() //{ // this.SuspendLayout(); // // Form // this.ClientSize = new Size(500, 250); // this.Text = "Settings - Claude Balance Monitor"; // this.StartPosition = FormStartPosition.CenterParent; // this.FormBorderStyle = FormBorderStyle.FixedDialog; // this.MaximizeBox = false; // this.MinimizeBox = false; // // Instructions Label // instructionsLabel = new Label(); // instructionsLabel.Text = "To get your session token:\n" + // "1. Go to https://console.anthropic.com/settings/billing\n" + // "2. Open Developer Tools (F12)\n" + // "3. Go to Application → Cookies\n" + // "4. Find and copy the 'sessionKey' cookie value"; // instructionsLabel.Location = new Point(10, 10); // instructionsLabel.Size = new Size(470, 80); // instructionsLabel.Font = new Font("Segoe UI", 9); // this.Controls.Add(instructionsLabel); // // Session Token Label // var tokenLabel = new Label(); // tokenLabel.Text = "Session Token:"; // tokenLabel.Location = new Point(10, 100); // tokenLabel.Size = new Size(100, 20); // tokenLabel.Font = new Font("Segoe UI", 9, FontStyle.Bold); // this.Controls.Add(tokenLabel); // // Session Token TextBox // sessionTokenTextBox = new TextBox(); // sessionTokenTextBox.Location = new Point(10, 125); // sessionTokenTextBox.Size = new Size(370, 23); // sessionTokenTextBox.UseSystemPasswordChar = true; // sessionTokenTextBox.Font = new Font("Consolas", 9); // this.Controls.Add(sessionTokenTextBox); // // Show/Hide Button // showHideButton = new Button(); // showHideButton.Text = "Show"; // showHideButton.Location = new Point(390, 125); // showHideButton.Size = new Size(60, 23); // showHideButton.Click += ShowHideButton_Click; // this.Controls.Add(showHideButton); // // Test Connection Button // var testButton = new Button(); // testButton.Text = "Test Connection"; // testButton.Location = new Point(10, 160); // testButton.Size = new Size(120, 30); // testButton.Click += TestButton_Click; // this.Controls.Add(testButton); // // Status Label // var statusLabel = new Label(); // statusLabel.Name = "statusLabel"; // statusLabel.Text = "Enter your session token and click 'Test Connection'"; // statusLabel.Location = new Point(140, 165); // statusLabel.Size = new Size(350, 20); // statusLabel.ForeColor = Color.Gray; // this.Controls.Add(statusLabel); // // OK Button // okButton = new Button(); // okButton.Text = "OK"; // okButton.Location = new Point(295, 200); // okButton.Size = new Size(90, 30); // okButton.Click += OkButton_Click; // this.Controls.Add(okButton); // // Cancel Button // cancelButton = new Button(); // cancelButton.Text = "Cancel"; // cancelButton.Location = new Point(395, 200); // cancelButton.Size = new Size(90, 30); // cancelButton.Click += CancelButton_Click; // this.Controls.Add(cancelButton); // this.ResumeLayout(false); //} private void ShowHideButton_Click(object sender, EventArgs e) { isTokenVisible = !isTokenVisible; sessionTokenTextBox.UseSystemPasswordChar = !isTokenVisible; showHideButton.Text = isTokenVisible ? "Hide" : "Show"; } private async void TestButton_Click(object sender, EventArgs e) { var statusLabel = this.Controls.Find("statusLabel", false)[0] as Label; var testToken = sessionTokenTextBox.Text.Trim(); if (string.IsNullOrEmpty(testToken)) { statusLabel.Text = "Please enter a session token"; statusLabel.ForeColor = Color.Red; return; } statusLabel.Text = "Testing connection..."; statusLabel.ForeColor = Color.Blue; try { using (var testClient = new HttpClient()) { testClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"); testClient.DefaultRequestHeaders.Add("Cookie", $"sessionKey={testToken}"); var response = await testClient.GetAsync("https://console.anthropic.com/settings/billing"); if (response.IsSuccessStatusCode) { statusLabel.Text = "✓ Connection successful!"; statusLabel.ForeColor = Color.Green; } else { statusLabel.Text = $"✗ Connection failed (Status: {response.StatusCode})"; statusLabel.ForeColor = Color.Red; } } } catch (Exception ex) { statusLabel.Text = $"✗ Connection error: {ex.Message}"; statusLabel.ForeColor = Color.Red; } } private void OkButton_Click(object sender, EventArgs e) { SessionToken = sessionTokenTextBox.Text.Trim(); DialogResult = DialogResult.OK; Close(); } private void CancelButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }