Problem
Initialize-AppData in ConfigManager.psm1 has a fallback to use %TEMP%\DailyMotivationBrainHelper if %APPDATA% creation fails (lines 58-69). However:
- The fallback updates module-scoped variables, but other scripts hardcode
%APPDATA%
- LaunchMotivation.bat always uses
%APPDATA% with no fallback
- DailyMotivation.ps1 hardcodes
%APPDATA% (line 88)
- If fallback is triggered, most of the app still looks in the wrong location
Current Fallback Code (ConfigManager.psm1)
catch {
# %APPDATA% unavailable (permission denied, disk quota, roaming redirect failure).
# Fall back to %TEMP% so the app can still run.
$fallback = Join-Path $env:TEMP "DailyMotivationBrainHelper"
Write-Warning "Initialize-AppData: Could not create '$script:AppDataDir' ($_). Falling back to '$fallback'."
New-Item -ItemType Directory -Path $fallback -Force | Out-Null
$script:AppDataDir = $fallback
$script:ConfigPath = Join-Path $script:AppDataDir "popup_config.json"
$script:TasksPath = Join-Path $script:AppDataDir "tasks.json"
$script:MessagesPath = Join-Path $script:AppDataDir "messages.json"
$script:SettingsPath = Join-Path $script:AppDataDir "app_settings.json"
$script:LogPath = Join-Path $script:AppDataDir "popup_log.txt"
}
This updates module-scoped $script: variables, so ConfigManager.psm1 functions will use the fallback. But:
Hardcoded %APPDATA% Locations
DailyMotivation.ps1 (line 88)
$appDataDir = Join-Path $env:APPDATA "DailyMotivationBrainHelper"
$configPath = Join-Path $appDataDir "popup_config.json"
$logPath = Join-Path $appDataDir "popup_log.txt"
LaunchMotivation.bat (lines 15-18)
set APP_DATA_DIR=%APPDATA%\DailyMotivationBrainHelper
set LAUNCH_LOG=%APP_DATA_DIR%\launch_log.txt
set PS_LOG=%APP_DATA_DIR%\launch_ps.log
MainApp.ps1 (line 295)
$messagesPath = Join-Path $env:APPDATA "DailyMotivationBrainHelper\messages.json"
None of these will use the fallback location if Initialize-AppData fell back to %TEMP%.
Impact
- If
%APPDATA% is unavailable (rare but possible in corporate/locked-down environments)
- Initialize-AppData creates files in
%TEMP%\DailyMotivationBrainHelper
- DailyMotivation.ps1 looks in
%APPDATA%\DailyMotivationBrainHelper
- Files not found, popup fails
- Fallback is useless
Expected Behavior
Either:
Option A: Consistent Fallback
- Export a
Get-AppDataDir function from ConfigManager
- All scripts call this instead of hardcoding
$env:APPDATA
- DailyMotivation.ps1:
$appDataDir = Get-AppDataDir
- MainApp.ps1:
$messagesPath = Join-Path (Get-AppDataDir) "messages.json"
- LaunchMotivation.bat: More complex, may need PS script to resolve path first
Option B: Remove Fallback
- If
%APPDATA% creation fails, show error dialog and exit
- Don't pretend fallback works when it doesn't
- Simpler and more honest
Recommendation: Option B unless there's a strong use case for %TEMP% fallback. Fallback adds complexity and isn't testable across the whole stack.
Acceptance Criteria
If keeping fallback (Option A):
If removing fallback (Option B):
Files Affected
- src/Modules/ConfigManager.psm1 (lines 58-69 + new function)
- src/DailyMotivation.ps1 (line 88)
- src/MainApp.ps1 (line 295)
- src/LaunchMotivation.bat (lines 15-18)
Related Issues
Problem
Initialize-AppDatain ConfigManager.psm1 has a fallback to use%TEMP%\DailyMotivationBrainHelperif%APPDATA%creation fails (lines 58-69). However:%APPDATA%%APPDATA%with no fallback%APPDATA%(line 88)Current Fallback Code (ConfigManager.psm1)
This updates module-scoped
$script:variables, so ConfigManager.psm1 functions will use the fallback. But:Hardcoded %APPDATA% Locations
DailyMotivation.ps1 (line 88)
LaunchMotivation.bat (lines 15-18)
MainApp.ps1 (line 295)
None of these will use the fallback location if
Initialize-AppDatafell back to%TEMP%.Impact
%APPDATA%is unavailable (rare but possible in corporate/locked-down environments)%TEMP%\DailyMotivationBrainHelper%APPDATA%\DailyMotivationBrainHelperExpected Behavior
Either:
Option A: Consistent Fallback
Get-AppDataDirfunction from ConfigManager$env:APPDATA$appDataDir = Get-AppDataDir$messagesPath = Join-Path (Get-AppDataDir) "messages.json"Option B: Remove Fallback
%APPDATA%creation fails, show error dialog and exitRecommendation: Option B unless there's a strong use case for %TEMP% fallback. Fallback adds complexity and isn't testable across the whole stack.
Acceptance Criteria
If keeping fallback (Option A):
Get-AppDataDirfrom ConfigManager.psm1Get-AppDataDirinstead of hardcodingIf removing fallback (Option B):
Files Affected
Related Issues