Removed unneeded markdown documentation
This commit is contained in:
@@ -1,182 +0,0 @@
|
||||
# Kill Process on Disconnect Feature - Implementation Summary
|
||||
|
||||
## Overview
|
||||
This document describes the implementation of the "Kill Process on Disconnect" feature for the Pianobar Helper application.
|
||||
|
||||
## Feature Requirements
|
||||
1. **Kill Process Checkbox (`chkkillpro`)**: A checkbox in the Settings form that allows users to enable/disable the kill-on-disconnect behavior
|
||||
2. **Gating Mechanism**: The checkbox must be disabled (non-interactive) unless the "Enable Profile Credentials and Custom Config Generation" checkbox (`chkOverrideCredentials`) is checked
|
||||
3. **Disconnect Behavior**: When the user clicks the Disconnect button in the main application:
|
||||
- If `chkkillpro` is checked: Pianobar process is immediately killed via its PID
|
||||
- If `chkkillpro` is unchecked: Pianobar process is detached (continues running in background)
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### 1. Data Model (`ProfileSettings`)
|
||||
**File**: `ProfileManager.cs`
|
||||
|
||||
Added `KillProcessOnDisconnect` boolean property to `ProfileSettings`:
|
||||
```csharp
|
||||
public class ProfileSettings
|
||||
{
|
||||
// ... other properties ...
|
||||
public bool KillProcessOnDisconnect { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
This property is saved/loaded with each profile in `profiles.json`.
|
||||
|
||||
### 2. Process Management (`PianobarManager`)
|
||||
**File**: `PianobarManager.cs`
|
||||
|
||||
Implemented two disconnect methods:
|
||||
|
||||
#### `Disconnect()` - Detach mode
|
||||
- Cleans up streams and event handlers
|
||||
- Sets `IsConnected = false`
|
||||
- Leaves the Pianobar process running in the background
|
||||
|
||||
#### `DisconnectAndKill()` - Kill mode
|
||||
- Checks if the process exists and is not exited
|
||||
- Calls `Process.Kill()` to terminate immediately
|
||||
- Reports the PID that was killed
|
||||
- Cleans up and sets `IsConnected = false`
|
||||
|
||||
### 3. Settings UI (`SettingsForm`)
|
||||
**File**: `Settings.cs` and `Settings.Designer.cs`
|
||||
|
||||
#### Control Initialization
|
||||
- `chkkillpro` checkbox starts **disabled** (set in Designer)
|
||||
- All credential-related fields start disabled:
|
||||
- `txtConfigFilePath`
|
||||
- `btnBrowseConfigFile`
|
||||
- `txtPianobarUser`
|
||||
- `txtPianobarPass`
|
||||
- `chkkillpro`
|
||||
|
||||
#### Event Handling
|
||||
**`chkOverrideCredentials_CheckedChanged`**:
|
||||
- Wired in Designer (line 352)
|
||||
- Calls `ToggleCredentialFields(checked)` method
|
||||
|
||||
**`ToggleCredentialFields(bool enabled)`**:
|
||||
```csharp
|
||||
private void ToggleCredentialFields(bool enabled)
|
||||
{
|
||||
if (txtConfigFilePath != null)
|
||||
txtConfigFilePath.Enabled = enabled;
|
||||
|
||||
if (btnBrowseConfigFile != null)
|
||||
btnBrowseConfigFile.Enabled = enabled;
|
||||
|
||||
if (txtPianobarUser != null)
|
||||
txtPianobarUser.Enabled = enabled;
|
||||
|
||||
if (txtPianobarPass != null)
|
||||
txtPianobarPass.Enabled = enabled;
|
||||
|
||||
if (chkkillpro != null)
|
||||
chkkillpro.Enabled = enabled; // <-- Critical: Kill checkbox is gated here
|
||||
}
|
||||
```
|
||||
|
||||
#### Profile Save/Load
|
||||
- `LoadSettingsToControls()` loads `KillProcessOnDisconnect` into `chkkillpro`
|
||||
- `SaveSettingsFromControls()` saves `chkkillpro.Checked` to profile settings
|
||||
- When saving, the profile is set as active via `SetActiveProfile()`
|
||||
|
||||
### 4. Main Application Logic (`Main.cs`)
|
||||
**File**: `Main.cs`
|
||||
|
||||
**`btnDisconnect_Click` handler**:
|
||||
```csharp
|
||||
public void btnDisconnect_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (!_pianobarManager.IsConnected)
|
||||
{
|
||||
MessageBox.Show("Not connected to Pianobar.", "Not Connected",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
if (statusLabelRight != null)
|
||||
statusLabelRight.Text = "Disconnecting...";
|
||||
|
||||
// Check if we should kill the process or just detach
|
||||
var activeProfile = _profileManager.GetActiveProfile();
|
||||
bool killProcess = activeProfile?.Settings.KillProcessOnDisconnect ?? false;
|
||||
|
||||
if (killProcess)
|
||||
{
|
||||
_pianobarManager.DisconnectAndKill(); // <-- Terminates process
|
||||
}
|
||||
else
|
||||
{
|
||||
_pianobarManager.Disconnect(); // <-- Detaches, leaves running
|
||||
}
|
||||
|
||||
_outputManager?.Stop();
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Output Folder Browse Button
|
||||
**File**: `Settings.cs` and `Settings.Designer.cs`
|
||||
|
||||
**`output_folder_browse_button`** (ID as requested):
|
||||
- Wired in Designer to `output_folder_browse_button_Click` (line 237)
|
||||
- Opens `SaveFileDialog` to allow user to select output file location
|
||||
- Default filename: `now_playing.txt`
|
||||
- Selected path is saved to `output_folder_text_box` (maps to `TextFilePath` in settings)
|
||||
|
||||
## User Workflow
|
||||
|
||||
### Enabling Kill-on-Disconnect
|
||||
1. Open **File ? Settings**
|
||||
2. Navigate to **"Pianobar Config & Auth"** tab
|
||||
3. Check **"Enable Profile Credentials and Custom Config Generation"** (`chkOverrideCredentials`)
|
||||
- This enables all credential fields **and** the kill process checkbox
|
||||
4. Check **"Kill process"** (`chkkillpro`)
|
||||
5. Click **Save**
|
||||
- Profile is updated and set as active
|
||||
- Setting persists for future sessions
|
||||
|
||||
### Using the Feature
|
||||
- **Connect**: Click Connect button (Pianobar starts in background, PID shown in status)
|
||||
- **Disconnect with Kill**: If `chkkillpro` was checked:
|
||||
- Pianobar process is immediately terminated by PID
|
||||
- Status shows "Pianobar process killed (PID: XXXX)"
|
||||
- **Disconnect without Kill**: If `chkkillpro` was unchecked:
|
||||
- Pianobar process continues running
|
||||
- Application detaches and closes streams
|
||||
- Status shows "Disconnected from Pianobar (process detached)"
|
||||
|
||||
### Disabling Override
|
||||
- If user unchecks `chkOverrideCredentials`:
|
||||
- Kill process checkbox becomes disabled and cannot be checked
|
||||
- All credential fields are disabled
|
||||
- User cannot enable kill-on-disconnect without also enabling custom config generation
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
? **Build Status**: Project builds successfully without errors
|
||||
? **Designer Wiring**: All event handlers properly wired in Designer files:
|
||||
- `chkOverrideCredentials.CheckedChanged` ? `chkOverrideCredentials_CheckedChanged`
|
||||
- `output_folder_browse_button.Click` ? `output_folder_browse_button_Click`
|
||||
- `chkkillpro` exists and is added to `pianobar_override_tab_page`
|
||||
? **Initial State**: All credential fields and `chkkillpro` start disabled
|
||||
? **Gating Logic**: `ToggleCredentialFields()` enables/disables `chkkillpro` based on override checkbox
|
||||
? **Profile Persistence**: `KillProcessOnDisconnect` saved/loaded with profile
|
||||
? **Disconnect Logic**: Main form branches to kill or detach based on profile setting
|
||||
? **Process Management**: `DisconnectAndKill()` terminates by PID; `Disconnect()` detaches only
|
||||
|
||||
## Files Modified
|
||||
|
||||
1. **ProfileManager.cs** - Added `KillProcessOnDisconnect` to data model
|
||||
2. **PianobarManager.cs** - Added `DisconnectAndKill()` method
|
||||
3. **Settings.cs** - Load/save logic and gating via `ToggleCredentialFields()`
|
||||
4. **Settings.Designer.cs** - Set initial `Enabled = false` for credential fields and `chkkillpro`
|
||||
5. **Main.cs** - Disconnect logic branches based on profile flag
|
||||
|
||||
## Summary
|
||||
|
||||
The kill-on-disconnect feature is fully implemented and integrated with the existing profile system. The checkbox is properly gated by the override credentials checkbox, ensuring users cannot accidentally enable the feature without understanding its context within custom config generation. The feature provides clean process termination when desired while preserving the option to keep Pianobar running in the background.
|
||||
@@ -1,153 +0,0 @@
|
||||
# Testing Guide - Kill Process on Disconnect
|
||||
|
||||
## Quick Test Steps
|
||||
|
||||
### Test 1: Verify Initial State
|
||||
1. **Run the application**
|
||||
2. **Open Settings** (File ? Settings)
|
||||
3. **Navigate to "Pianobar Config & Auth" tab**
|
||||
4. **Verify**:
|
||||
- [ ] "Enable Profile Credentials and Custom Config Generation" checkbox is **unchecked**
|
||||
- [ ] "Kill process" checkbox is **disabled** (grayed out, cannot be clicked)
|
||||
- [ ] Config file path field is **disabled**
|
||||
- [ ] Browse button is **disabled**
|
||||
- [ ] Username field is **disabled**
|
||||
- [ ] Password field is **disabled**
|
||||
|
||||
### Test 2: Enable Override and Kill Process
|
||||
1. **Check** "Enable Profile Credentials and Custom Config Generation"
|
||||
2. **Verify**:
|
||||
- [ ] "Kill process" checkbox becomes **enabled**
|
||||
- [ ] All credential fields become **enabled**
|
||||
3. **Check** "Kill process" checkbox
|
||||
4. **Click Save**
|
||||
5. **Re-open Settings**
|
||||
6. **Verify**:
|
||||
- [ ] "Enable Profile Credentials..." remains **checked**
|
||||
- [ ] "Kill process" checkbox remains **checked**
|
||||
- [ ] Setting persists correctly
|
||||
|
||||
### Test 3: Connect and Kill on Disconnect
|
||||
1. **Ensure a profile with Kill Process enabled is active**
|
||||
2. **Set Pianobar executable path** if not already set
|
||||
3. **Click Connect**
|
||||
4. **Verify**:
|
||||
- [ ] Pianobar starts (status shows "Connected to Pianobar")
|
||||
- [ ] PID is displayed in status bar (e.g., "PID: 12345")
|
||||
5. **Click Disconnect**
|
||||
6. **Verify**:
|
||||
- [ ] Status shows "Pianobar process killed (PID: XXXX)"
|
||||
- [ ] Pianobar process is **terminated** (check Task Manager)
|
||||
|
||||
### Test 4: Connect and Detach on Disconnect
|
||||
1. **Open Settings**
|
||||
2. **Navigate to "Pianobar Config & Auth" tab**
|
||||
3. **Verify** "Enable Profile Credentials..." is **checked**
|
||||
4. **Uncheck** "Kill process" checkbox
|
||||
5. **Click Save**
|
||||
6. **Click Connect**
|
||||
7. **Verify**:
|
||||
- [ ] Pianobar starts successfully
|
||||
8. **Click Disconnect**
|
||||
9. **Verify**:
|
||||
- [ ] Status shows "Disconnected from Pianobar (process detached)"
|
||||
- [ ] Pianobar process is **still running** in Task Manager
|
||||
- [ ] Music continues playing
|
||||
|
||||
### Test 5: Disable Override (Gating)
|
||||
1. **Open Settings**
|
||||
2. **Navigate to "Pianobar Config & Auth" tab**
|
||||
3. **Uncheck** "Enable Profile Credentials and Custom Config Generation"
|
||||
4. **Verify**:
|
||||
- [ ] "Kill process" checkbox becomes **disabled** (grayed out)
|
||||
- [ ] All credential fields become **disabled**
|
||||
- [ ] Cannot check "Kill process"
|
||||
5. **Try to check "Kill process"** (should not be possible)
|
||||
6. **Click Save**
|
||||
7. **Close Settings**
|
||||
|
||||
### Test 6: Output Folder Browse Button
|
||||
1. **Open Settings**
|
||||
2. **Navigate to "Outputs" tab**
|
||||
3. **Click** the **Browse** button next to the output folder text box (ID: `output_folder_browse_button`)
|
||||
4. **Verify**:
|
||||
- [ ] SaveFileDialog opens with title "Select Text File Output Path"
|
||||
- [ ] Default filename is "now_playing.txt"
|
||||
- [ ] Can select a location
|
||||
5. **Select a location** and click OK
|
||||
6. **Verify**:
|
||||
- [ ] Selected path appears in the output folder text box
|
||||
7. **Click Save**
|
||||
8. **Verify**:
|
||||
- [ ] Output path is saved to the profile
|
||||
|
||||
## Edge Case Tests
|
||||
|
||||
### Edge 1: Switch Profiles with Different Settings
|
||||
1. **Create two profiles**:
|
||||
- Profile A: Kill process **enabled**
|
||||
- Profile B: Kill process **disabled**
|
||||
2. **Switch to Profile A** and connect
|
||||
3. **Disconnect** ? Should **kill** the process
|
||||
4. **Switch to Profile B** and connect
|
||||
5. **Disconnect** ? Should **detach** (not kill)
|
||||
|
||||
### Edge 2: Override Disabled Mid-Session
|
||||
1. **Have Kill process enabled**
|
||||
2. **Open Settings** while connected
|
||||
3. **Uncheck** "Enable Profile Credentials..."
|
||||
4. **Verify** "Kill process" becomes **disabled**
|
||||
5. **Click Save**
|
||||
6. **Disconnect**
|
||||
7. **Verify** process is **detached** (not killed), since override was disabled
|
||||
|
||||
### Edge 3: No Active Profile
|
||||
1. **Delete all profiles** or ensure no profile is active
|
||||
2. **Try to connect**
|
||||
3. **Verify**:
|
||||
- [ ] Error message: "No active profile selected..."
|
||||
- [ ] Cannot connect without a profile
|
||||
|
||||
## Expected Behavior Summary
|
||||
|
||||
| Override Enabled? | Kill Process Checked? | Disconnect Behavior |
|
||||
|-------------------|----------------------|---------------------|
|
||||
| ? No | N/A (disabled) | Detach |
|
||||
| ? Yes | ? No | Detach |
|
||||
| ? Yes | ? Yes | **Kill by PID** |
|
||||
|
||||
## Status Bar Messages
|
||||
|
||||
- **Connect starting**: "Starting Pianobar..."
|
||||
- **Connect success**: "Connected to Pianobar (PID: XXXX)"
|
||||
- **Connect failed**: "Failed to start Pianobar"
|
||||
- **Disconnect (kill)**: "Pianobar process killed (PID: XXXX)"
|
||||
- **Disconnect (detach)**: "Disconnected from Pianobar (process detached)"
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Issue: Kill checkbox is always disabled
|
||||
**Solution**: Make sure "Enable Profile Credentials and Custom Config Generation" is **checked**
|
||||
|
||||
### Issue: Setting doesn't persist
|
||||
**Solution**: Make sure you clicked **Save** before closing the Settings dialog
|
||||
|
||||
### Issue: Process not killed on disconnect
|
||||
**Checks**:
|
||||
- Is "Enable Profile Credentials..." checked?
|
||||
- Is "Kill process" checkbox checked?
|
||||
- Did you save the profile?
|
||||
- Is the correct profile active?
|
||||
|
||||
### Issue: Cannot connect
|
||||
**Checks**:
|
||||
- Is a profile selected and active?
|
||||
- Is the Pianobar executable path set correctly?
|
||||
- Does the Pianobar.exe file exist at that path?
|
||||
|
||||
## Files to Monitor
|
||||
|
||||
- `profiles.json` in `%APPDATA%\PianoBarHelper\`
|
||||
- Check that `"KillProcessOnDisconnect": true` is saved for profiles where it's enabled
|
||||
- Task Manager ? Details
|
||||
- Watch for `pianobar.exe` process appearing/disappearing during connect/disconnect
|
||||
Reference in New Issue
Block a user