16 Commits
Author SHA1 Message Date
vgearen f1b6b72d8d fix(critical): isolate AppStateTests from user's real data directory
PRIOR BEHAVIOR (data-loss bug):
AppStateTests.setUp() constructed AppState() directly, which used the real
~/Library/Application Support/Stockbar/ for stocks.json. Each test method
that did 'sut.stocks = [s1, s2]' triggered didSet → saveStocks → silently
overwrote the user's actual portfolio file with 2 test entries. backupIfNeeded
then rolled all 10 backup snapshots forward, eventually erasing every
historical copy of real data.

This destroyed a user's 29-stock portfolio when xcodebuild test was run
during Korean stock feature development (2026-05-14 10:08).

FIX:
- AppState gains a static appSupportDirOverride: URL? hook
- AppStateTests.setUp() creates a unique tmpDir, sets the override, tearDown
  resets and removes the directory
- Verified: after running all 7 AppStateTests, the real stocks.json is
  byte-identical to before the run.

This must land before any further test run touches AppState.
2026-05-14 10:35:01 +08:00
vgearen 6e63064207 feat(korea): add koreanMarketSession + wire KR into AppState.refresh
AppState.koreanMarketSession (nonisolated) returns '盘中' during KST 09:00-15:30
on weekdays, nil otherwise. Marked nonisolated so it can be called from sync
non-MainActor contexts (notably tests).

AppState.refresh now has a 5th parallel branch fetching Korean quotes via
DataService.fetchKoreanQuotes. KR is non-throwing (returns [:] on failure) so
it's awaited outside the try block — any KR network failure does not abort
A股/港股fetch results.
2026-05-14 10:05:47 +08:00
vgearenandClaude Opus 4.6 f8bb287194 v1.2.6: Hide daily PnL on non-trading days (holidays/weekends)
- Add Quote.isToday: compare updateTime date with today in Beijing timezone
- effectiveDailyPnl returns nil when quote data is stale (not from today)
- Prevents showing yesterday's change as today's daily PnL on closed markets

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 14:14:49 +08:00
vgearenandClaude Opus 4.6 592ad90f61 v1.2.5: Add watchlist (观察仓) feature with virtual portfolio support
- New Watchlist model: named virtual portfolios with per-stock cost/shares
- Watchlists persisted to watchlists.json, active ID in settings
- AppState: effective cost/shares/PnL methods that respect active watchlist
- Settings: create/delete/switch watchlists, edit writes to active watchlist
- ProfitSummaryView shows active watchlist name
- UI alignment fixes for toggle and text field padding

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 11:31:59 +08:00
vgearenandClaude Opus 4.6 d898185745 v1.2.2: Fix overnight session weekday logic (Sunday evening = Monday overnight)
- ET 20:00-24:00: allow Sunday (wd=1) as Monday overnight start
- ET 00:00-04:00: allow Saturday (wd=7) as Friday overnight continuation
- Fixes no data shown on Sunday evening when overnight API has live data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 08:51:15 +08:00
vgearenandClaude Opus 4.6 94b14693d5 v1.2.0: Add US overnight session real-time prices via Pyth/TradingView API
- Add PythService.swift: fetch overnight prices from us-overnight-stock-api.vercel.app
- Restore "夜盘" session in usMarketSession() (ET 20:00-04:00)
- Parallel fetch Sina + Pyth during overnight, merge once to avoid UI flicker
- Clear stale after-hours extendedPrice before applying overnight data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 12:52:39 +08:00
vgearenandClaude Opus 4.6 72103bd69f v1.1.9: Remove US night session display (no free data source available)
- Remove "夜盘" from usMarketSession(), only keep 盘前/盘中/盘后
- Night session (ET 20:00-04:00) has no free real-time data API

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 09:31:04 +08:00
vgearenandClaude Opus 4.6 66b77aee04 v1.1.4: Security hardening — SHA-256 verify, fix injection, log rotation, error logging
- Add SHA-256 hash verification for downloaded DMG in auto-update
- Fix shell command injection: use positional args instead of path interpolation
- Add log rotation (truncate to 500KB when exceeding 1MB)
- Replace critical try? with do/catch + logToFile for data persistence

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 10:51:23 +08:00
vgearenandClaude Opus 4.6 00f142f091 v1.1.3: Fix status bar PnL display, rounded app icon, LaunchAgent fallback
- Fix "daily + total" PnL mode only showing daily: use single Text concatenation
- Move PnL options into status bar picker (daily / total / both), hide icon in PnL mode
- Add rounded corners to app icon for macOS consistency
- Add LaunchAgent plist fallback for launch-at-login on Intel Macs
- Remove StatusBarPnL enum, use statusBarStockId special values instead

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 09:56:19 +08:00
vgearenandClaude Opus 4.6 88e705fece v1.1.1: Add PnL percentage display and in-app auto-update
- Show floating PnL percentage for each stock and portfolio summary
- Show daily/total PnL percentage in profit summary view
- Replace manual GitHub download with in-app auto-update (download DMG, mount, replace, relaunch)
- Disable app sandbox for Process support (non-App Store distribution)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 09:16:35 +08:00
vgearenandClaude Sonnet 4.6 8c60d39024 Migrate all settings from UserDefaults to settings.json
- AppSettings: fully Codable with statusBarStockId, refreshInterval,
  colorScheme, displayCurrency; uses decodeIfPresent for forward compat
- AppState: replace @AppStorage with @Published var config: AppSettings,
  persisted to ~/Library/Application Support/Stockbar/settings.json
- Computed accessors (statusBarStockId, refreshInterval, colorScheme,
  displayCurrency) maintain same API so views require no changes
- Fix views: appState.settings.* → appState.config.*

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 10:12:59 +08:00
vgearenandClaude Sonnet 4.6 28cf10480b Rename app from StockMonitor to Stockbar
- Bundle ID: com.vgearen.StockMonitor → com.vgearen.Stockbar
- Display name: Stock Monitor → Stockbar
- App entry struct: StockMonitorApp → StockbarApp
- App Support path: ~/Library/Application Support/Stockbar
- Log path: ~/Library/Logs/Stockbar
- OSLog subsystem: com.vgearen.Stockbar
- Test module import: @testable import Stockbar
- GitHub Actions: scheme, DMG name updated

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 09:34:19 +08:00
vgearenandClaude Sonnet 4.6 a119f89624 Fix config data loss on startup and Codable forward-compatibility
- AppState.init: use _stocks = Published(wrappedValue:) to bypass didSet,
  preventing empty array from overwriting disk on decode failure
- AppState.saveStocks: guard against overwriting non-empty file with []
- Stock: explicit Codable extension using decodeIfPresent for optional fields,
  so missing fields in old JSON use defaults instead of failing the whole decode

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 09:17:14 +08:00
vgearenandClaude Sonnet 4.6 3227b4fcda Add lifecycle logging to diagnose startup crashes
- AppLogger.swift: global OSLog Logger + logToFile() writing to
  ~/Library/Logs/StockMonitor/app.log
- AppDelegate: log applicationDidFinishLaunching / WillTerminate / ShouldTerminate
- AppState.init: log start, stocks-loaded count, and init-complete

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 09:01:41 +08:00
vgearenandClaude Sonnet 4.6 5a482ac818 Add currency conversion for portfolio summary
- CurrencyService: fetch USD/CNY and USD/HKD from Sina Finance forex
- DisplayCurrency enum (CNY/HKD/USD) with symbol and display name
- AppState: fetch rates on every refresh, convert totalPnL/totalDailyPnL
- Settings: add 持仓汇总货币 segmented picker
- ProfitSummaryView: show currency symbol in P&L display

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 08:51:42 +08:00
vgearenandClaude Sonnet 4.6 6b1f565d7d Initial release: macOS menu bar stock monitor
- A-shares, HK, and US stock real-time quotes (Sina / Tencent)
- Intraday minute charts (Tencent / Yahoo Finance)
- US extended-hours session indicator with price and change%
- Portfolio P&L tracking (cost price × shares)
- Sort by change%, color themes, launch at login
- File-based persistence with 10-snapshot rolling backup
- Universal binary (Apple Silicon + Intel)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 17:41:52 +08:00