# Electron Integration (Events - Launcher)

This document describes the Electron integration for the Aether Svelte application, which provides native capabilities for the Events module, specifically for the **Event Launcher** functionality.

## Overview

The Event Launcher is not a standalone module but rather a set of native functions and UI elements integrated into the Events module. It is designed to be used in a hybrid event scenario where a local application (the Electron app) is used to control presentations and other event-related content on a local machine.

## Architecture

The Electron integration is composed of three main parts:

1.  **Electron Main Process (`electron.js`):** The main process of the Electron application. It is responsible for creating the browser window and handling communication with the renderer process.
2.  **Native Functions (`src/lib/electron/electron_native.js`):** A set of functions that are executed in the Electron main process and have access to the operating system's native APIs. These functions provide the core functionality for the Event Launcher, such as opening files, running commands, and managing processes.
3.  **Relay/Bridge (`src/lib/electron/electron_relay.js`):** A bridge that exposes the native functions to the Svelte application running in the renderer process. This allows the Svelte components to call the native functions.

## Key Functionality

The native functions in `electron_native.js` provide the following key functionalities for the Event Launcher:

- **File Caching:**
    - `check_hash_file_cache()`: Checks if a file with a specific hash exists in the local cache.
    - `download_hash_file_to_cache()`: Downloads a file from the API and stores it in the local cache.
- **File Operations:**
    - `open_hash_file_to_temp()`: Copies a file from the cache to a temporary directory and opens it.
    - `open_local_file()`: Opens a local file.
- **Process Management:**
    - `kill_processes()`: Kills processes by name or ID. This is used to close presentation applications after a presentation is finished.
- **Command Execution:**
    - `run_osascript()`: Runs an AppleScript command (macOS only).
    - `run_cmd()`: Runs a shell command.
- **Device Information:**
    - `get_device_info()`: Gets information about the device, which can be used for logging and debugging.

## UI Integration

The Event Launcher functionality is integrated into the Events module's UI as follows:

- **Launcher Links:** In the list of event sessions, there are "launcher" links that, when clicked, trigger the native launcher functionality.
- **Configuration:** The visibility and behavior of the launcher links are controlled by the `mod_pres_mgmt_json` configuration in the `Event` object. This allows for fine-grained control over the launcher functionality on a per-event basis.

## How it Works

1.  The Svelte application, running in the Electron renderer process, displays a list of event sessions.
2.  For each session, a "launcher" link is displayed if the configuration allows it.
3.  When the user clicks on a launcher link, a function in `electron_relay.js` is called.
4.  The relay function then calls the corresponding native function in `electron_native.js` via the Electron context bridge.
5.  The native function performs the requested action, such as downloading a file, opening a presentation, or running a command.
