Rails Gem - aguspe/turbo_desktop GitHub Wiki
The turbo_desktop-rails gem gives your Rails app awareness of the Turbo Desktop shell.
# Gemfile
gem "turbo_desktop-rails"bundle install
rails generate turbo_desktop:installThe generator:
- Creates
config/initializers/turbo_desktop.rbwith default path rules - Mounts
TurboDesktop::Engineat/turbo-desktopin your routes
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 |
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.
Render content only inside the desktop app:
<%%= turbo_desktop_only do %>
<button data-controller="notification">Send Native Notification</button>
<%% end %>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 %>Generate bridge data attributes for any HTML element:
<%%= tag.button "Notify",
**turbo_desktop_bridge("notification",
title: "Hello",
body: "World"
) %>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.
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<%% 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 %>