Skip to content

Commit 4693796

Browse files
authored
Merge pull request #45 from K9i-0/feature/debug-port-configuration
feat: デバッグ時のポート競合を解決する環境変数サポートを追加
2 parents c54db3b + 9696004 commit 4693796

21 files changed

+219
-44
lines changed

CLAUDE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,39 @@ open Package.swift
5050
# Clean up processes if needed
5151
killall ClaudeCodeMonitor 2>/dev/null || true
5252
ps aux | grep -E "node.*server" | grep -v grep | awk '{print $2}' | xargs kill 2>/dev/null || true
53+
54+
# Debug with different port (to avoid conflict with release version)
55+
cd server && PORT=3457 npm start # Start server on port 3457
56+
CLAUDE_MONITOR_PORT=3457 swift run # Run app using port 3457
57+
```
58+
59+
## Debugging with Port Configuration
60+
61+
To avoid port conflicts between the DMG-distributed app and debug builds:
62+
63+
### Using Environment Variables
64+
65+
Both the server and application support custom port configuration via environment variables:
66+
67+
- Server: `PORT` environment variable (defaults to 3456)
68+
- Application: `CLAUDE_MONITOR_PORT` environment variable (defaults to 3456)
69+
70+
### Debug Setup in Xcode
71+
72+
1. Open the project in Xcode: `open Package.swift`
73+
2. Edit the scheme (Product → Scheme → Edit Scheme...)
74+
3. In the "Run" section, go to "Arguments" tab
75+
4. Add environment variable: `CLAUDE_MONITOR_PORT` = `3457`
76+
77+
### Command Line Debug
78+
79+
```bash
80+
# Terminal 1: Start server on custom port
81+
cd server
82+
PORT=3457 npm start
83+
84+
# Terminal 2: Run app with custom port
85+
CLAUDE_MONITOR_PORT=3457 swift run
5386
```
5487

5588
## Architecture

Config/Debug.xcconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Debug configuration
2+
PRODUCT_BUNDLE_IDENTIFIER = com.k9i.ClaudeCodeMonitor.debug
3+
PRODUCT_NAME = ClaudeCodeMonitor-Debug

Config/Release.xcconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Release configuration
2+
PRODUCT_BUNDLE_IDENTIFIER = com.k9i.ClaudeCodeMonitor
3+
PRODUCT_NAME = ClaudeCodeMonitor

DEBUG_GUIDE.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ npm start
5151
```
5252
**解決策**: エラーメッセージに基づいて対処
5353

54-
### 5. 追加のデバッグ情報
54+
### 5. デバッグビルドでポートを変更
55+
56+
リリース版と同時に実行するには:
57+
58+
1. Xcodeでスキームを編集: Product → Scheme → Edit Scheme...
59+
2. Run → Arguments → Environment Variables
60+
3. 追加: `CLAUDE_MONITOR_PORT` = `3457`
61+
4. サーバーも別ポートで起動: `cd server && PORT=3457 npm start`
62+
63+
### 6. 追加のデバッグ情報
5564

5665
環境変数を確認するには、AppDelegate.swiftに以下を追加:
5766

Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleIdentifier</key>
6-
<string>com.k9i.claude-code-monitor</string>
6+
<string>com.k9i.ClaudeCodeMonitor</string>
77
<key>CFBundleName</key>
8-
<string>Claude Code Monitor</string>
8+
<string>ClaudeCodeMonitor</string>
99
<key>CFBundleDisplayName</key>
10-
<string>Claude Code Monitor</string>
10+
<string>ClaudeCodeMonitor</string>
1111
<key>CFBundleExecutable</key>
1212
<string>ClaudeCodeMonitor</string>
1313
<key>CFBundleVersion</key>

README.ja.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ Xcodeで:
8989
- **ビルド**: Product > Build(⌘B)
9090
- **実行**: Product > Run(⌘R)
9191

92+
##### 異なるポートでデバッグ実行
93+
94+
リリース版と同時に実行するには:
95+
96+
1. スキームを編集: Product → Scheme → Edit Scheme...
97+
2. Run → Arguments → Environment Variables へ移動
98+
3. 追加: `CLAUDE_MONITOR_PORT` = `3457`
99+
4. サーバーも別ポートで起動: `cd server && PORT=3457 npm start`
100+
92101
#### 方法2: コマンドラインでビルド
93102

94103
```bash

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ In Xcode:
9393
- **Build**: Product > Build (⌘B)
9494
- **Run**: Product > Run (⌘R)
9595

96+
##### Debug with Different Port
97+
98+
To run debug builds alongside the release version:
99+
100+
1. Edit scheme: Product → Scheme → Edit Scheme...
101+
2. Go to Run → Arguments → Environment Variables
102+
3. Add: `CLAUDE_MONITOR_PORT` = `3457`
103+
4. Start server on different port: `cd server && PORT=3457 npm start`
104+
96105
#### Method 2: Command Line Build
97106

98107
```bash

Sources/ClaudeUsageMonitor/AppDelegate.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1111
private var dataAccessManager: ClaudeDataAccessManager!
1212

1313
func applicationDidFinishLaunching(_ notification: Notification) {
14+
// Debug builds use different settings to avoid conflicts with release version
15+
#if DEBUG
16+
// This will be reflected in menu bar and other UI elements
17+
print("Running in DEBUG mode")
18+
#endif
19+
1420
// Initialize data access manager
1521
dataAccessManager = ClaudeDataAccessManager()
1622

@@ -143,7 +149,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
143149
}
144150

145151
// パーセンテージのみ表示(HIGに準拠した簡潔な表示)
152+
#if DEBUG
153+
button.title = String(format: "%.0f%% [D]", percentage)
154+
#else
146155
button.title = String(format: "%.0f%%", percentage)
156+
#endif
147157
button.attributedTitle = NSAttributedString(
148158
string: button.title,
149159
attributes: [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
3+
enum BundleConfiguration {
4+
static var bundleIdentifier: String {
5+
#if DEBUG
6+
return "com.k9i.ClaudeCodeMonitor.debug"
7+
#else
8+
return "com.k9i.ClaudeCodeMonitor"
9+
#endif
10+
}
11+
12+
static var appName: String {
13+
#if DEBUG
14+
return "ClaudeCodeMonitor-Debug"
15+
#else
16+
return "ClaudeCodeMonitor"
17+
#endif
18+
}
19+
}

Sources/ClaudeUsageMonitor/ClaudeDataAccessManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ClaudeDataAccessManager: ObservableObject {
1515
/// Check if we have existing access via saved path or auto-detect
1616
func checkExistingAccess() {
1717
// First try to load saved path
18-
if let savedPath = UserDefaults.standard.string(forKey: "claudeDataPath") {
18+
if let savedPath = UserDefaultsManager.shared.string(forKey: "claudeDataPath") {
1919
print("[ClaudeDataAccess] Found saved path: \(savedPath)")
2020
// Verify the path still exists and has projects subdirectory
2121
let url = URL(fileURLWithPath: savedPath)
@@ -29,7 +29,7 @@ class ClaudeDataAccessManager: ObservableObject {
2929
} else {
3030
print("[ClaudeDataAccess] Saved path no longer valid")
3131
// Clear invalid path
32-
UserDefaults.standard.removeObject(forKey: "claudeDataPath")
32+
UserDefaultsManager.shared.removeObject(forKey: "claudeDataPath")
3333
}
3434
}
3535

@@ -42,7 +42,7 @@ class ClaudeDataAccessManager: ObservableObject {
4242
claudePath = defaultClaudePath.path
4343
hasAccess = true
4444
// Save the auto-detected path
45-
UserDefaults.standard.set(defaultClaudePath.path, forKey: "claudeDataPath")
45+
UserDefaultsManager.shared.set(defaultClaudePath.path, forKey: "claudeDataPath")
4646
print("[ClaudeDataAccess] Auto-detected Claude data at: \(defaultClaudePath.path)")
4747
} else {
4848
print("[ClaudeDataAccess] Claude data not found at default location: \(defaultClaudePath.path)")
@@ -128,8 +128,8 @@ class ClaudeDataAccessManager: ObservableObject {
128128
hasAccess = true
129129

130130
// Save the resolved path to UserDefaults
131-
UserDefaults.standard.set(resolvedURL.path, forKey: "claudeDataPath")
132-
UserDefaults.standard.synchronize()
131+
UserDefaultsManager.shared.set(resolvedURL.path, forKey: "claudeDataPath")
132+
UserDefaultsManager.shared.synchronize()
133133

134134
print("[ClaudeDataAccess] Successfully saved path: \(resolvedURL.path)")
135135
print("[ClaudeDataAccess] hasAccess is now: \(hasAccess)")

0 commit comments

Comments
 (0)