Skip to content

BUG: DailyMotivation.ps1 doesn't call Initialize-AppData, assumes MainApp already ran #5

Description

@SevWren

Problem

DailyMotivation.ps1 (the popup script) assumes %APPDATA%\DailyMotivationBrainHelper\ already exists and never calls Initialize-AppData. If the popup is triggered by Task Scheduler before MainApp.ps1 has ever run, all config files are missing and the script exits silently.

Symptoms

  • Popup never appears when triggered by Task Scheduler
  • Debug log shows: "Config file not found - using defaults" (line 116)
  • Script exits silently at line 127: "No folder configured in popup_config.json -- exiting silently"
  • User gets no feedback about what went wrong

Root Cause

DailyMotivation.ps1 loads ConfigManager module (line 85) but never calls Initialize-AppData. The script assumes:

  1. User ran MainApp.ps1 first
  2. MainApp created all necessary files
  3. Task Scheduler will only fire after manual setup

This assumption breaks if:

  • User manually creates a scheduled task without running MainApp
  • Files get deleted after initial setup
  • Multiple user profiles on same machine
  • Portable installation moved to new machine

Current Behavior (DailyMotivation.ps1)

# Line 85: Capture module path
$script:ModulesPath = Join-Path $PSScriptRoot "Modules"

# ... later ...

# Lines 88-90: Hardcode paths
$appDataDir = Join-Path $env:APPDATA "DailyMotivationBrainHelper"
$configPath = Join-Path $appDataDir "popup_config.json"

# Lines 104-117: Try to load config
if (Test-Path $configPath) {
    # load it
} else {
    Write-DLog "Config file not found - using defaults" "WARN"
}

# Lines 125-129: Exit if no folder configured
if (-not $config.explorer_path -or $config.explorer_path -eq "") {
    Write-DLog "No folder configured in popup_config.json -- exiting silently" "WARN"
    exit 0
}

Expected Behavior

DailyMotivation.ps1 should be self-sufficient:

  1. Import ConfigManager module
  2. Call Initialize-AppData to ensure directory structure exists
  3. If popup_config.json still doesn't exist or is empty, show user-facing error dialog
  4. Log the issue clearly in debug log

Proposed Fix

# After loading module
Import-Module (Join-Path $script:ModulesPath "ConfigManager.psm1") -Force

# Ensure directory structure exists
Initialize-AppData

# Now load config
$config = Get-PopupConfig
if (-not $config -or -not $config.explorer_path) {
    Show-ErrorDialog "No scheduled task configuration found. Please run the main application first to schedule a folder."
    exit 1
}

Acceptance Criteria

  • DailyMotivation.ps1 calls Initialize-AppData on every launch
  • If config files missing, show clear error dialog (not silent exit)
  • Debug log explains why popup didn't show
  • Works even if MainApp.ps1 has never been run
  • Test: Delete %APPDATA%\DailyMotivationBrainHelper, trigger Task Scheduler, verify graceful error

Files Affected

  • src/DailyMotivation.ps1 (add Initialize-AppData call after line 85)
  • src/DailyMotivation.ps1 (replace silent exit at line 125 with error dialog)

Related Issues

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions