Rails Gem - aguspe/turbo_desktop GitHub Wiki

Rails Gem — turbo_desktop-rails

The turbo_desktop-rails gem gives your Rails app awareness of the Turbo Desktop shell.

Installation

# Gemfile
gem "turbo_desktop-rails"
bundle install
rails generate turbo_desktop:install

The generator:

  1. Creates config/initializers/turbo_desktop.rb with default path rules
  2. Mounts TurboDesktop::Engine at /turbo-desktop in your routes

Detection Helpers

Available in all controllers and views:

Helper Returns Example
turbo_desktop_app? true / false Check if request is from desktop
turbo_desktop_platform "macos", "windows", "linux", or nil Platform-specific logic
turbo_desktop_arch "aarch64", "x86_64", or nil Architecture detection

How Detection Works

The desktop shell sets a custom User-Agent header:

Turbo Desktop/0.1.0 (macOS; aarch64)

The gem parses this to determine platform and architecture.

View Helpers

turbo_desktop_only

Render content only inside the desktop app:

<%%= turbo_desktop_only do %>
  <button data-controller="notification">Send Native Notification</button>
<%% end %>

turbo_web_only

Render content only in regular web browsers:

<%%= turbo_web_only do %>
  <p>Download our <a href="/desktop">desktop app</a> for native features!</p>
<%% end %>

turbo_desktop_bridge

Generate bridge data attributes for any HTML element:

<%%= tag.button "Notify",
    **turbo_desktop_bridge("notification",
      title: "Hello",
      body: "World"
    ) %>

Path Configuration Endpoint

The engine serves the path configuration at:

GET /turbo-desktop/path-configuration.json

The desktop shell fetches this on startup to know how to present different URLs.

Controller Usage

class TasksController < ApplicationController
  def create
    @task = Task.create!(task_params)

    if turbo_desktop_app?
      # Maybe trigger a different response for desktop
      redirect_to tasks_path
    else
      redirect_to tasks_path
    end
  end
end

Platform-specific Logic

<%% if turbo_desktop_platform == "macos" %>
  <p>Press ⌘N for a new task</p>
<%% elsif turbo_desktop_platform == "windows" %>
  <p>Press Ctrl+N for a new task</p>
<%% end %>
⚠️ **GitHub.com Fallback** ⚠️