Browse Source
- Make database initialization non-blocking to prevent app crashes - Add proper window lifecycle management and error handling - Implement retry logic for index.html loading - Add detailed logging for debugging - Fix type safety issues in error handling - Add proper cleanup on window close WIP: Database path resolution still needs fixing - Current issue: Path conflict between ~/.local/share and ~/.config - Database connection failing with invalid response - Multiple connection attempts occurring This commit improves app stability but database connectivity needs to be addressed in a follow-up commit.pull/134/head
2 changed files with 488 additions and 186 deletions
@ -1,71 +1,186 @@ |
|||||
#! /bin/bash |
#!/bin/bash |
||||
|
# experiment.sh |
||||
|
# Author: Matthew Raymer |
||||
|
# Description: Build script for TimeSafari Electron application |
||||
|
# This script handles the complete build process for the TimeSafari Electron app, |
||||
|
# including web asset compilation, TypeScript compilation, and AppImage packaging. |
||||
|
# It ensures all dependencies are available and provides detailed build feedback. |
||||
|
# |
||||
|
# Build Process: |
||||
|
# 1. Environment setup and dependency checks |
||||
|
# 2. Web asset compilation (Vite) |
||||
|
# 3. TypeScript compilation |
||||
|
# 4. Electron main process build |
||||
|
# 5. AppImage packaging |
||||
|
# |
||||
|
# Dependencies: |
||||
|
# - Node.js and npm |
||||
|
# - TypeScript |
||||
|
# - Vite |
||||
|
# - electron-builder |
||||
|
# |
||||
|
# Usage: ./experiment.sh |
||||
|
# |
||||
|
# Exit Codes: |
||||
|
# 1 - Required command not found |
||||
|
# 2 - TypeScript installation failed |
||||
|
# 3 - TypeScript compilation failed |
||||
|
# 4 - Build process failed |
||||
|
# 5 - AppImage build failed |
||||
|
|
||||
# Exit on any error |
# Exit on any error |
||||
set -e |
set -e |
||||
|
|
||||
|
# ANSI color codes for better output formatting |
||||
|
readonly RED='\033[0;31m' |
||||
|
readonly GREEN='\033[0;32m' |
||||
|
readonly YELLOW='\033[1;33m' |
||||
|
readonly BLUE='\033[0;34m' |
||||
|
readonly NC='\033[0m' # No Color |
||||
|
|
||||
|
# Logging functions |
||||
|
log_info() { |
||||
|
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')] [INFO]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
log_success() { |
||||
|
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] [SUCCESS]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
log_warn() { |
||||
|
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] [WARN]${NC} $1" |
||||
|
} |
||||
|
|
||||
|
log_error() { |
||||
|
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] [ERROR]${NC} $1" |
||||
|
} |
||||
|
|
||||
# Function to check if a command exists |
# Function to check if a command exists |
||||
check_command() { |
check_command() { |
||||
if ! command -v $1 &> /dev/null; then |
if ! command -v "$1" &> /dev/null; then |
||||
echo "Error: $1 is required but not installed." |
log_error "$1 is required but not installed." |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
|
log_info "Found $1: $(command -v "$1")" |
||||
|
} |
||||
|
|
||||
|
# Function to measure and log execution time |
||||
|
measure_time() { |
||||
|
local start_time=$(date +%s) |
||||
|
"$@" |
||||
|
local end_time=$(date +%s) |
||||
|
local duration=$((end_time - start_time)) |
||||
|
log_success "Completed in ${duration} seconds" |
||||
|
} |
||||
|
|
||||
|
# Function to find the AppImage |
||||
|
find_appimage() { |
||||
|
local appimage_path |
||||
|
appimage_path=$(find dist-electron-packages -name "*.AppImage" -type f -print -quit) |
||||
|
if [ -n "$appimage_path" ]; then |
||||
|
echo "$appimage_path" |
||||
|
else |
||||
|
log_warn "AppImage not found in expected location" |
||||
|
echo "dist-electron-packages/*.AppImage" |
||||
|
fi |
||||
} |
} |
||||
|
|
||||
|
# Print build header |
||||
|
echo -e "\n${BLUE}=== TimeSafari Electron Build Process ===${NC}\n" |
||||
|
log_info "Starting build process at $(date)" |
||||
|
|
||||
# Check required commands |
# Check required commands |
||||
|
log_info "Checking required dependencies..." |
||||
check_command node |
check_command node |
||||
check_command npm |
check_command npm |
||||
|
|
||||
|
# Create application data directory |
||||
|
log_info "Setting up application directories..." |
||||
mkdir -p ~/.local/share/TimeSafari/timesafari |
mkdir -p ~/.local/share/TimeSafari/timesafari |
||||
|
|
||||
# Clean up previous builds |
# Clean up previous builds |
||||
echo "Cleaning previous builds..." |
log_info "Cleaning previous builds..." |
||||
rm -rf dist* |
rm -rf dist* || log_warn "No previous builds to clean" |
||||
|
|
||||
# Set environment variables for the build |
# Set environment variables for the build |
||||
echo "Setting up environment variables..." |
log_info "Configuring build environment..." |
||||
export VITE_PLATFORM=electron |
export VITE_PLATFORM=electron |
||||
export VITE_PWA_ENABLED=false |
export VITE_PWA_ENABLED=false |
||||
export VITE_DISABLE_PWA=true |
export VITE_DISABLE_PWA=true |
||||
|
|
||||
# Ensure TypeScript is installed |
# Ensure TypeScript is installed |
||||
echo "Checking TypeScript installation..." |
log_info "Verifying TypeScript installation..." |
||||
if [ ! -f "./node_modules/.bin/tsc" ]; then |
if [ ! -f "./node_modules/.bin/tsc" ]; then |
||||
echo "Installing TypeScript..." |
log_info "Installing TypeScript..." |
||||
npm install --save-dev typescript@~5.2.2 |
if ! npm install --save-dev typescript@~5.2.2; then |
||||
|
log_error "TypeScript installation failed!" |
||||
|
exit 2 |
||||
|
fi |
||||
# Verify installation |
# Verify installation |
||||
if [ ! -f "./node_modules/.bin/tsc" ]; then |
if [ ! -f "./node_modules/.bin/tsc" ]; then |
||||
echo "TypeScript installation failed!" |
log_error "TypeScript installation verification failed!" |
||||
exit 1 |
exit 2 |
||||
fi |
fi |
||||
|
log_success "TypeScript installed successfully" |
||||
|
else |
||||
|
log_info "TypeScript already installed" |
||||
fi |
fi |
||||
|
|
||||
# Get git hash for versioning |
# Get git hash for versioning |
||||
GIT_HASH=$(git log -1 --pretty=format:%h) |
GIT_HASH=$(git log -1 --pretty=format:%h) |
||||
|
log_info "Using git hash: ${GIT_HASH}" |
||||
|
|
||||
# Build web assets |
# Build web assets |
||||
echo "Building web assets..." |
log_info "Building web assets with Vite..." |
||||
VITE_GIT_HASH=$GIT_HASH npx vite build --config vite.config.app.electron.mts --mode electron |
if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.app.electron.mts --mode electron; then |
||||
|
log_error "Web asset build failed!" |
||||
|
exit 4 |
||||
|
fi |
||||
|
|
||||
# TypeScript compilation |
# TypeScript compilation |
||||
echo "Running TypeScript compilation..." |
log_info "Compiling TypeScript..." |
||||
if ! ./node_modules/.bin/tsc -p tsconfig.electron.json; then |
if ! measure_time ./node_modules/.bin/tsc -p tsconfig.electron.json; then |
||||
echo "TypeScript compilation failed!" |
log_error "TypeScript compilation failed!" |
||||
exit 1 |
exit 3 |
||||
fi |
fi |
||||
|
|
||||
# Build electron main process |
# Build electron main process |
||||
echo "Building electron main process..." |
log_info "Building electron main process..." |
||||
VITE_GIT_HASH=$GIT_HASH npx vite build --config vite.config.electron.mts --mode electron |
if ! measure_time env VITE_GIT_HASH="$GIT_HASH" npx vite build --config vite.config.electron.mts --mode electron; then |
||||
|
log_error "Electron main process build failed!" |
||||
|
exit 4 |
||||
|
fi |
||||
|
|
||||
# Organize files |
# Organize files |
||||
echo "Organizing build files..." |
log_info "Organizing build artifacts..." |
||||
mkdir -p dist-electron/www |
mkdir -p dist-electron/www |
||||
cp -r dist/* dist-electron/www/ |
cp -r dist/* dist-electron/www/ || log_error "Failed to copy web assets" |
||||
mkdir -p dist-electron/resources |
mkdir -p dist-electron/resources |
||||
cp src/electron/preload.js dist-electron/resources/preload.js |
cp src/electron/preload.js dist-electron/resources/preload.js || log_error "Failed to copy preload script" |
||||
|
|
||||
# Build the AppImage |
# Build the AppImage |
||||
echo "Building AppImage..." |
log_info "Building AppImage package..." |
||||
npx electron-builder --linux AppImage |
if ! measure_time npx electron-builder --linux AppImage; then |
||||
|
log_error "AppImage build failed!" |
||||
|
exit 5 |
||||
|
fi |
||||
|
|
||||
|
# Print build summary |
||||
|
echo -e "\n${GREEN}=== Build Summary ===${NC}" |
||||
|
log_success "Build completed successfully!" |
||||
|
log_info "Build artifacts location: $(pwd)/dist-electron" |
||||
|
log_info "AppImage location: $(find_appimage)" |
||||
|
|
||||
|
# Check for build warnings |
||||
|
if grep -q "default Electron icon is used" dist-electron-packages/builder-effective-config.yaml; then |
||||
|
log_warn "Using default Electron icon - consider adding a custom icon" |
||||
|
fi |
||||
|
|
||||
|
if grep -q "chunks are larger than 1000 kB" dist-electron-packages/builder-effective-config.yaml; then |
||||
|
log_warn "Large chunks detected - consider implementing code splitting" |
||||
|
fi |
||||
|
|
||||
|
echo -e "\n${GREEN}=== End of Build Process ===${NC}\n" |
||||
|
|
||||
echo "Build completed successfully!" |
# Exit with success |
||||
|
exit 0 |
Loading…
Reference in new issue