# AeThex OS Distribution - Complete Setup Guide

## 🎯 Overview

You now have a complete Roblox-style distribution system with:
- ✅ Beautiful download page at `/download`
- ✅ Server API endpoints for downloading installers
- ✅ Auto-update system built into desktop app
- ✅ Web launcher for one-click installs
- ✅ Marketing materials and embed codes

## 📦 Build the Production Installer

Before users can download, you need to build the production installer:

```bash
# Build desktop app (takes ~5-10 minutes first time)
cd shell/aethex-shell
npm run tauri build

# Creates two installers:
# 1. shell/aethex-shell/src-tauri/target/release/bundle/nsis/AeThex-OS_0.1.0_x64-setup.exe (2.5 MB)
# 2. shell/aethex-shell/src-tauri/target/release/bundle/msi/AeThex-OS_0.1.0_x64_en-US.msi (3.7 MB)
```

## 🚀 Server Setup

### 1. Start Your Server

```bash
# From project root
npm run dev

# Server runs on: http://localhost:5000
# React app: http://localhost:5000/download
```

### 2. API Endpoints (Automatic)

These endpoints are already configured:

```
http://localhost:5000/api/download/desktop     → NSIS installer
http://localhost:5000/api/download/desktop/msi → MSI installer
http://localhost:5000/api/download/version     → Version info (for auto-updates)
```

## 🌐 How Users Install

### Method 1: Website Download Page
```
User visits: http://localhost:5000/download
Clicks: "Download for Windows"
Downloads: AeThex-OS-setup.exe
Runs installer → App installed!
```

### Method 2: Direct Download Link
```
User clicks: http://localhost:5000/api/download/desktop
Browser downloads installer immediately
```

### Method 3: Web Launcher (Auto-start)
```
User visits: http://localhost:5000/launcher.html?autoinstall=true
Download starts automatically
```

## 🔄 Auto-Update System

The desktop app automatically checks for updates:

### How It Works
1. On launch, app checks: `https://aethex.dev/api/download/version`
2. Compares current version (0.1.0) with latest version
3. If new version available, shows update dialog
4. User clicks "Update" → downloads and installs new version

### To Release an Update

1. **Increment version** in `shell/aethex-shell/package.json`:
   ```json
   {
     "version": "0.2.0"
   }
   ```

2. **Rebuild** the installer:
   ```bash
   cd shell/aethex-shell
   npm run tauri build
   ```

3. **Deploy** new installers to your server

4. **Users get notified** automatically on next launch

## 🎨 Marketing Materials

All created in `MARKETING_MATERIALS.md`:

### Social Media Posts
- ✅ Twitter/X post
- ✅ LinkedIn announcement
- ✅ Discord message
- ✅ Reddit post

### Embed Codes
- ✅ HTML buttons
- ✅ JavaScript widgets
- ✅ React components
- ✅ Email signatures

All embed codes in `EMBED_CODES.html`

## 📊 Testing Locally

### 1. Test Download Page
```bash
# Start server
npm run dev

# Visit in browser
http://localhost:5000/download

# Click "Download for Windows"
# Should see 404 if installer not built yet
```

### 2. Build Installer (Recommended)
```bash
cd shell/aethex-shell
npm run tauri build

# Wait 5-10 minutes
# Installer will be created at:
# src-tauri/target/release/bundle/nsis/AeThex-OS_0.1.0_x64-setup.exe
```

### 3. Test Download Again
```bash
# Restart server if needed
npm run dev

# Visit download page
http://localhost:5000/download

# Click "Download for Windows"
# Should download AeThex-OS-setup.exe
```

## 🌍 Production Deployment

### Option 1: Deploy to aethex.dev (Recommended)

1. **Build installer locally**:
   ```bash
   cd shell/aethex-shell
   npm run tauri build
   ```

2. **Deploy to your server** (Railway, Vercel, etc.)
   ```bash
   git add .
   git commit -m "feat: add download system and installers"
   git push
   ```

3. **Upload installers** to your server or CDN
   - Option A: Commit installers to repo (not recommended, large files)
   - Option B: Upload to S3/R2/DigitalOcean Spaces
   - Option C: Host on GitHub Releases

### Option 2: Use GitHub Releases

1. **Create release on GitHub**:
   ```bash
   git tag v0.1.0
   git push origin v0.1.0
   ```

2. **Upload installers** to GitHub release page

3. **Update download routes** in `server/download-routes.ts`:
   ```typescript
   const installerPath = 'https://github.com/[username]/[repo]/releases/download/v0.1.0/AeThex-OS-setup.exe';
   ```

### Option 3: CDN Hosting

1. **Upload to CDN** (Cloudflare R2, AWS S3, DigitalOcean Spaces)

2. **Update download routes** to point to CDN URLs:
   ```typescript
   const installerPath = 'https://cdn.aethex.dev/downloads/AeThex-OS-setup.exe';
   ```

## 🔐 Production Checklist

Before going live:

- [ ] Build production installer (`npm run tauri build`)
- [ ] Test download locally
- [ ] Choose hosting method (GitHub Releases / CDN / Server)
- [ ] Update production URLs in code if needed
- [ ] Test auto-update system
- [ ] Verify installers work on clean Windows machine
- [ ] Set up analytics tracking
- [ ] Prepare social media posts
- [ ] Create launch announcement

## 📈 Analytics & Monitoring

### Track Downloads

Add to your download page (`client/src/pages/download.tsx`):

```typescript
const handleDownload = async () => {
  // Track with your analytics
  gtag('event', 'download_start', {
    event_category: 'installer',
    event_label: 'windows_desktop'
  });

  // ... download logic
};
```

### Monitor Active Users

The `/api/download/version` endpoint logs all update checks:
- Track how many users check for updates
- Monitor active installations
- Track update adoption rate

## 🎬 Launch Strategy

### Week Before Launch
1. Build and test installer thoroughly
2. Set up hosting infrastructure
3. Prepare social media posts
4. Notify mailing list subscribers

### Launch Day
1. Deploy download system
2. Post on all social media channels
3. Share on Reddit, Hacker News, IndieHackers
4. Email announcement to users
5. Monitor download metrics

### Week After Launch
1. Gather user feedback
2. Fix critical bugs
3. Share success metrics
4. Plan first update (v0.2.0)

## 🆘 Troubleshooting

### "Port 1420 already in use"
```bash
# Kill the process
taskkill //F //PID [process-id-from-netstat]
```

### "Installer not found" error
```bash
# Build the installer first
cd shell/aethex-shell
npm run tauri build
```

### Download fails in browser
- Check if installer exists at expected path
- Verify server has read permissions
- Check browser console for errors
- Test direct API endpoint: `http://localhost:5000/api/download/desktop`

### Auto-update not working
- Verify `tauri.conf.json` updater endpoint is correct
- Check version endpoint returns valid JSON
- Ensure app has internet connection
- Look at console logs in desktop app

## 📞 Support & Help

- **Documentation**: See `MARKETING_MATERIALS.md` for full guide
- **Embed Codes**: See `EMBED_CODES.html` for ready-to-use code
- **Issues**: File bugs on GitHub
- **Community**: Discord server

---

**Next Steps:**
1. Build the production installer: `cd shell/aethex-shell && npm run tauri build`
2. Test download locally: `npm run dev` → visit `http://localhost:5000/download`
3. Deploy to production when ready

**Built:** 2026-02-12
**Version:** MVP Distribution System
**Status:** Ready for Testing ✅
