Application lifecycle and main window
Transmission Remote GUI is a Lazarus desktop client that starts one application process, creates one primary window, and uses that window to present and control torrent data from a Transmission daemon. The lifecycle joins process setup, user-interface state, daemon connection state, background refresh, and orderly shutdown.
Lifecycle model
The application moves from process checks to UI creation, then into an event loop that keeps the main window and daemon state aligned. A close request either hides the window for later reuse or ends the process after the application saves its session state.
flowchart TD
A[Process start] --> B[Validate parameters and runtime state]
B -->|Continue| C[Initialize Lazarus application]
B -->|Another instance handles request| Z[Exit new process]
C --> D[Create main window]
D --> E[Load UI state and prepare services]
E --> F[Run event loop]
F --> G[Refresh UI and process user actions]
G --> F
F --> H[Close or end-session request]
H --> I{Tray close enabled?}
I -->|Yes| J[Hide or minimize window]
J --> F
I -->|No| K[Save state and release resources]
K --> L[Process exit]
Process entry
The program entry point performs the small set of steps that turns a process into a Lazarus application. It checks command-line input and process ownership first. It then initializes the widget system, creates TMainForm, applies the Windows taskbar setting when needed, and starts the event loop. See Startup and component wiring for the unit and component relationships behind this sequence.
References: transgui.lpr• L29-65 main.pas• L1280-1403
Runtime preparation
Runtime preparation selects the application home area and prepares the settings and handoff state used by the rest of the session. It also accepts torrent files, web links, and magnet links from command-line input. If another process is active, the new process passes those inputs to the active process and exits instead of creating a second application session.
The same stage loads the selected language and interface scale before the main window is created. This makes the window use the session-wide display settings from its first display.
References: main.pas• L1171-1255 main.pas• L1257-1270 main.pas• L1280-1403
Main window
TMainForm is the primary user-facing coordinator. It owns the main torrent view, connection status, detail views, menus, toolbars, tray behavior, and the actions that connect those surfaces to daemon requests.
Window creation
Window creation builds the working session around the form that Lazarus creates. The form creates its RPC client and data views, sets an initial disconnected state, restores saved window and pane settings, loads column choices, and applies connection and interface preferences. It also prepares optional behaviors such as a hidden start, a watched local folder, clipboard link handling, translations, and platform-specific controls.
The form does not start with active torrent data. It first establishes a known disconnected view. Later connection and refresh events replace that state with daemon data.
References: main.pas• L1575-1686 main.pas• L1717-1813 baseform.pas• L217-244
Event-loop coordination
The Lazarus event loop delivers input, timer events, window changes, and application events to the main form. The form uses these events to keep the visible UI consistent with connection and torrent state rather than making each control update itself in isolation.
The idle event updates common UI state. Timers request torrent-list refreshes, check pending torrent inputs, and manage delayed filter work. A page change asks the RPC layer for the level of detail required by the selected information page. This coordination keeps the list, filters, details, status display, and available actions tied to the current daemon state. See Main-window workflows for the user actions that run through this coordinator.
References: main.pas• L4475-4482 main.pas• L5170-5175 main.pas• L5220-5226 main.pas• L5205-5213 main.pas• L8325-8384
Application actions
The main window exposes user intent through shared actions. Menus, toolbar buttons, context menus, shortcuts, and tray commands can therefore reach the same high-level operation. The action layer covers connection control, torrent changes, view changes, file operations, tracker work, updates, and application exit.
Actions use the current selection and connection state to decide what the user can do. Operations that change daemon data pass through the RPC client. Operations that change the local presentation update saved interface state or the visible panes. This split lets the window coordinate remote work without making the presentation depend on one particular control.
References: main.pas• L210-281 main.pas• L548-601 main.pas• L2023-2029 main.pas• L3491-3495
Connection state
The connection state links a named host configuration to the main window’s data views. A connection attempt reads the selected host settings, prepares authentication and transport choices, starts the RPC session, and records the active host. A disconnect stops pending refresh work and returns the lists, filters, search controls, and statistics to a disabled empty state.
This state boundary is important for the UI: the window can remain open while no daemon is available, and a later connection can repopulate the same views without recreating the form.
References: main.pas• L5310-5424 main.pas• L5426-5457
Window visibility
The application treats window visibility as separate from process lifetime. The tray icon and platform rules can hide the main window while the process continues to serve refreshes and accept new inputs. A show operation restores a minimized or hidden window, brings it to the front, and updates the tray state. A hide operation removes the taskbar presence where the platform allows it.
The hidden startup option uses the same model. The process creates the main window but leaves it out of the normal display while the tray remains available.
References: main.pas• L1794-1803 main.pas• L3019-3043 main.pas• L4484-4501 main.pas• L5239-5247
Shutdown
Shutdown has two paths: a close request can keep the process alive in the tray, while an exit or end-session request ends the application. Both paths save the user’s window layout and view choices before the form releases its session resources.
Close behavior
When the main window receives a close request, the configured tray-close behavior decides whether the request becomes a hide or minimize action. If the setting does not keep the process alive, the form saves its state and allows application termination. Platform rules can change whether the result is a hidden window or a minimized window.
References: main.pas• L5177-5203 main.pas• L3019-3043
State persistence
Before a real close, the form records window geometry, window state, splitter positions, visible panes, column layouts, and peer display choices. The next form creation reads these values and restores the prior working layout. This makes the UI session persistent without making the daemon hold presentation state.
References: main.pas• L3124-3154 main.pas• L1717-1793
Resource release
Form destruction removes the run marker, writes pending settings, unregisters platform hooks, and frees the objects that support the session. The end-session handler performs the run-marker cleanup and state save early so an operating-system session end follows the same ownership rules as a normal exit.
References: main.pas• L1926-1974 main.pas• L4425-4429
Failure handling
The application keeps failures inside the desktop session when possible. Application exceptions are routed to a user-facing error handler, which restores a usable window state and shows a translated message. Connection failures leave the window available for another connection attempt rather than ending the process.
Exception response
The application properties object captures uncaught UI exceptions and sends them to the main form’s exception handler. The handler makes the application visible in a normal state and reports the error. When call-stack support is enabled, it also offers fuller diagnostic text without changing the normal user path.
References: main.pas• L1615-1618 main.pas• L1811-1813 main.pas• L4431-4473
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to process handoff or supported input types must preserve the contract between command-line arguments, the active instance, and
CheckAddTorrents. - Changes to
FormCreatesettings must stay paired with the matching keys written byBeforeCloseApp. - Changes to close behavior must cover normal close, tray close, platform session end, and the run-marker cleanup path.
- Changes to shared actions must preserve the same action behavior across menus, toolbars, shortcuts, context menus, and tray commands.
- Changes to connection reset behavior must keep refresh timers and all daemon-backed views aligned with the disconnected state.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A second process starts while the first process is responsive | The second process must not create a competing main window or lose the requested torrent input | The run marker and IPC file pass inputs to the active process before the new process exits |
| The IPC file remains from an old session | A new start can treat stale data as a current handoff | Startup removes an IPC record that is older than the allowed age |
| Close handling hides the form when the user expects exit | The process continues in the background and the main window is not destroyed | The tray-close setting and platform-specific close path determine whether the request hides or terminates |
| A connection is lost while refresh work is pending | Old daemon data can remain visible or a timer can request data from an invalid session | DoDisconnect disables refresh work and clears daemon-backed views |
| The run marker is not removed during shutdown | A later start can falsely detect an active instance | Normal destruction and end-session handling both remove the marker |
Key files
| File | Why to read it |
|---|---|
transgui.lpr | Shows the process entry sequence from parameter checks to the Lazarus event loop. |
main.pas | Defines the primary window, application events, shared actions, connection boundary, visibility rules, and shutdown behavior. |
baseform.pas | Explains the common form setup that applies interface scaling before the main window becomes active. |
transgui.lpi | Records the Lazarus project entry point and the fact that the main form is created by program code rather than automatic form creation. |
| Startup and component wiring | Child page for the startup units, form creation path, and application-level component wiring. |
| Main-window workflows | Child page for the user flows coordinated by the main window after startup. |