Skip to content

BUG: %TEMP% fallback in ConfigManager not used consistently across scripts #7

Description

@SevWren

Problem

Initialize-AppData in ConfigManager.psm1 has a fallback to use %TEMP%\DailyMotivationBrainHelper if %APPDATA% creation fails (lines 58-69). However:

  1. The fallback updates module-scoped variables, but other scripts hardcode %APPDATA%
  2. LaunchMotivation.bat always uses %APPDATA% with no fallback
  3. DailyMotivation.ps1 hardcodes %APPDATA% (line 88)
  4. 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

  1. If %APPDATA% is unavailable (rare but possible in corporate/locked-down environments)
  2. Initialize-AppData creates files in %TEMP%\DailyMotivationBrainHelper
  3. DailyMotivation.ps1 looks in %APPDATA%\DailyMotivationBrainHelper
  4. Files not found, popup fails
  5. 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):

  • Export Get-AppDataDir from ConfigManager.psm1
  • All scripts use Get-AppDataDir instead of hardcoding
  • LaunchMotivation.bat resolves dir from PS before launching
  • Test: Block %APPDATA% creation, verify app works from %TEMP%

If removing fallback (Option B):

  • Remove fallback catch block from Initialize-AppData
  • Show clear error dialog if %APPDATA% unavailable
  • Document that app requires %APPDATA% access

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions