Desktop Detection - aguspe/turbo_desktop GitHub Wiki
Turbo Desktop lets you serve different content depending on whether the user is in the native desktop app or a regular web browser.
The desktop shell adds a custom User-Agent string:
Turbo Desktop/0.1.0 (macOS; aarch64)
The turbo_desktop-rails gem parses this automatically and provides helper methods.
<%%= turbo_desktop_only do %>
<div class="native-toolbar">
<button data-controller="notification">Native Notification</button>
<button data-controller="file-picker">Open File</button>
</div>
<%% end %><%%= turbo_web_only do %>
<div class="download-banner">
<p>Get the desktop app for native features!</p>
<a href="/download">Download</a>
</div>
<%% end %>class DashboardController < ApplicationController
def index
if turbo_desktop_app?
# Desktop-specific logic
@show_native_features = true
end
end
endturbo_desktop_platform # => "macos", "windows", "linux", or nil
turbo_desktop_arch # => "aarch64", "x86_64", or nilUse these for platform-specific keyboard shortcuts, UI differences, or feature flags.
The example app uses detection in its layout to show a platform badge:
<nav class="navbar">
<!-- ... -->
<%%= turbo_desktop_only do %>
<span class="badge badge-desktop">
Desktop (<%%= turbo_desktop_platform %>)
</span>
<%% end %>
<%%= turbo_web_only do %>
<span class="badge badge-web">Web Browser</span>
<%% end %>
</nav>This gives desktop users visual confirmation they're in the native app, while web users see a regular browser badge.