Overview

The File Type Associations system provides comprehensive file type registration, MIME type mapping, default application associations, and icon mappings for the FreeWorld OS file system.

Status: ✅ Complete - 100+ file types registered with MIME types, icons, and default applications

Components

FileTypeRegistry

Location: system/file-type-associations.js

The main registry class that manages all file type associations.

Key Features:

  • 100+ File Types: Comprehensive coverage of common file extensions
  • MIME Type Mapping: Standard MIME type associations for each extension
  • Default Applications: Maps file types to their default opening applications
  • Icon Associations: Links file types to their display icons
  • File Descriptions: Human-readable descriptions for each file type

Methods:

// Register a new file type
register(extension, mimeType, iconName, defaultApp, description)

// Get association for file extension
getAssociation(extension) → FileTypeAssociation

// Get icon URL for file extension
getIconURL(extension) → string

// Get default application for file extension
getDefaultApp(extension) → string|null

// Get MIME type for file extension
getMimeType(extension) → string

// Get description for file extension
getDescription(extension) → string

// Check if extension is supported
isSupported(extension) → boolean

// Get all registered extensions
getAllExtensions() → string[]

// Get all associations
getAllAssociations() → FileTypeAssociation[]

FileTypeAssociation

Represents a single file type association with the following properties:

  • extension: File extension (e.g., '.txt', '.zip')
  • mimeType: MIME type (e.g., 'text/plain', 'application/zip')
  • iconName: Name of icon file (e.g., 'PostItNote', 'ArchiveIcon')
  • defaultApp: Default application name (e.g., 'Notepad', 'ImageViewer')
  • description: Human-readable description (e.g., 'Text Document', 'ZIP Archive')

Supported File Types

Archive Files

  • .zip - ZIP Archive (application/zip) → ArchiveIcon
  • .rar - RAR Archive (application/x-rar-compressed) → ArchiveIcon
  • .7z - 7-Zip Archive (application/x-7z-compressed) → ArchiveIcon
  • .tar - TAR Archive (application/x-tar) → ArchiveIcon
  • .gz - GZIP Archive (application/gzip) → ArchiveIcon

Text Files

  • .txt - Text Document (text/plain) → PostItNote → Notepad
  • .md - Markdown Document (text/markdown) → PostItNote → Notepad
  • .log - Log File (text/plain) → PostItNote → Notepad
  • .readme - Readme File (text/plain) → PostItNote → Notepad

Code Files

  • .js - JavaScript File (application/javascript) → Editor
  • .ts - TypeScript File (application/typescript) → Editor
  • .c - C Source File (text/x-c) → Editor
  • .cpp - C++ Source File (text/x-c++) → Editor
  • .h - C Header File (text/x-c) → Editor
  • .hpp - C++ Header File (text/x-c++) → Editor
  • .asm - Assembly File (text/x-asm) → Editor
  • .py - Python Script (text/x-python) → Editor
  • .java - Java Source File (text/x-java) → Editor
  • .cs - C# Source File (text/x-csharp) → Editor
  • .php - PHP Script (application/x-php) → Editor
  • .rb - Ruby Script (text/x-ruby) → Editor
  • .go - Go Source File (text/x-go) → Editor
  • .rs - Rust Source File (text/x-rust) → Editor

Web Files

  • .html / .htm - HTML Document (text/html) → Browser
  • .css - CSS Stylesheet (text/css) → Editor
  • .scss - SCSS Stylesheet (text/x-scss) → Editor
  • .json - JSON File (application/json) → Editor
  • .xml - XML Document (application/xml) → Editor
  • .yaml / .yml - YAML File (application/x-yaml) → Editor

Image Files

  • .png - PNG Image (image/png) → ImageViewer
  • .jpg / .jpeg - JPEG Image (image/jpeg) → ImageViewer
  • .gif - GIF Image (image/gif) → ImageViewer
  • .bmp - Bitmap Image (image/bmp) → ImageViewer
  • .svg - SVG Image (image/svg+xml) → ImageViewer
  • .ico - Icon File (image/x-icon) → ImageViewer
  • .webp - WebP Image (image/webp) → ImageViewer
  • .tiff / .tif - TIFF Image (image/tiff) → ImageViewer

Audio Files

  • .mp3 - MP3 Audio (audio/mpeg) → MediaPlayer
  • .wav - WAV Audio (audio/wav) → MediaPlayer
  • .ogg - OGG Audio (audio/ogg) → MediaPlayer
  • .flac - FLAC Audio (audio/flac) → MediaPlayer
  • .aac - AAC Audio (audio/aac) → MediaPlayer
  • .m4a - M4A Audio (audio/mp4) → MediaPlayer
  • .wma - WMA Audio (audio/x-ms-wma) → MediaPlayer

Video Files

  • .mp4 - MP4 Video (video/mp4) → MediaPlayer
  • .avi - AVI Video (video/x-msvideo) → MediaPlayer
  • .mkv - MKV Video (video/x-matroska) → MediaPlayer
  • .mov - QuickTime Video (video/quicktime) → MediaPlayer
  • .wmv - WMV Video (video/x-ms-wmv) → MediaPlayer
  • .flv - Flash Video (video/x-flv) → MediaPlayer
  • .webm - WebM Video (video/webm) → MediaPlayer

Document Files

  • .pdf - PDF Document (application/pdf) → PDFViewer
  • .doc / .docx - Word Document → WordProcessor
  • .xls / .xlsx - Excel Spreadsheet → Spreadsheet
  • .ppt / .pptx - PowerPoint Presentation → Presentation
  • .odt - OpenDocument Text → WordProcessor
  • .ods - OpenDocument Spreadsheet → Spreadsheet
  • .odp - OpenDocument Presentation → Presentation

Executable Files

  • .exe - Executable File (application/x-msdownload)
  • .dll - Dynamic Link Library (application/x-msdownload)
  • .so - Shared Object (application/x-sharedlib)
  • .dylib - Dynamic Library (application/x-mach-binary)
  • .app - Application Bundle (application/x-executable)

Script Files

  • .sh - Shell Script (application/x-sh) → Terminal
  • .bat - Batch File (application/x-msdos-program) → Terminal
  • .cmd - Command File (application/x-msdos-program) → Terminal
  • .ps1 - PowerShell Script (application/x-powershell) → Terminal

Configuration Files

  • .ini - Configuration File (text/plain) → Editor
  • .conf - Configuration File (text/plain) → Editor
  • .config - Configuration File (text/plain) → Editor
  • .cfg - Configuration File (text/plain) → Editor
  • .properties - Properties File (text/plain) → Editor

Data Files

  • .db - Database File (application/x-sqlite3)
  • .sqlite - SQLite Database (application/x-sqlite3)
  • .sql - SQL Script (application/x-sql) → Editor
  • .csv - CSV File (text/csv) → Spreadsheet

Font Files

  • .ttf - TrueType Font (font/ttf)
  • .otf - OpenType Font (font/otf)
  • .woff - Web Open Font (font/woff)
  • .woff2 - Web Open Font 2 (font/woff2)

System Files

  • .sys - System File (application/x-msdownload) → ThisPC
  • .drv - Driver File (application/x-msdownload) → ThisPC
  • .inf - Setup Information (text/plain) → Editor

Other Files

  • .bin - Binary File (application/octet-stream)
  • .dat - Data File (application/octet-stream)
  • .tmp - Temporary File (application/octet-stream)
  • .bak - Backup File (application/octet-stream)

Icon Mappings

File types are mapped to specific icon files located in usr/share/icons/64x64/:

  • ArchiveIcon.zip, .rar, .7z, .tar, .gz
  • PostItNote.txt, .md, .log, .readme
  • Mail.eml, .msg, .mbox
  • ThisPC.sys, .dll, .drv (system files)
  • Trashcan → Trash (empty)
  • TrashcanFull → Trash (full)
  • driveicondark → Drives

Integration

File Manager Integration

The FileManager class uses the FileTypeRegistry to:

  • Get icons for file listings
  • Determine default applications for file opening
  • Display file type descriptions

File Browser Integration

The FileBrowser component uses file type associations to:

  • Display appropriate icons for each file type
  • Enable double-click to open files with default applications
  • Show file type information in properties dialogs

Application Launcher Integration

The ApplicationLauncherService uses file type associations to:

  • Launch default applications when opening files
  • Handle "Open With" functionality
  • Register file associations with applications

API Endpoints

The GUI server provides the following API endpoints for file type associations:

Open File With Application

POST /api/file/open-with
{
    "path": "/path/to/file.txt",
    "extension": ".txt"
}

Response:
{
    "success": true,
    "opened": true,
    "processId": 123,
    "hwnd": 456
}

Usage Examples

Get Icon for File Extension

const FileTypeRegistry = require('./file-type-associations');

const registry = new FileTypeRegistry();
const iconURL = registry.getIconURL('.txt');
// Returns: '/usr/share/icons/64x64/PostItNote.png' or emoji fallback

Get Default Application

const defaultApp = registry.getDefaultApp('.txt');
// Returns: 'Notepad'

Get MIME Type

const mimeType = registry.getMimeType('.txt');
// Returns: 'text/plain'

Check if Extension is Supported

if (registry.isSupported('.zip')) {
    console.log('ZIP files are supported');
}

Adding New File Types

To add a new file type association:

const registry = new FileTypeRegistry();

registry.register(
    '.myext',                    // Extension
    'application/x-mytype',      // MIME type
    'MyIcon',                    // Icon name
    'MyApp',                     // Default application
    'My Custom File Type'        // Description
);

Related Documentation