Module: TurboDesktop::Detection
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/turbo_desktop/detection.rb
Overview
Detects whether the current request is coming from a Turbo Desktop app by inspecting the User-Agent string.
The Turbo Desktop shell sets a User-Agent like:
"Turbo Desktop/0.1.0 (macOS; aarch64)"
This mirrors how turbo-rails detects Turbo Native mobile apps.
Instance Method Summary collapse
-
#turbo_desktop_app? ⇒ Boolean
Returns true if the request is from a Turbo Desktop app.
-
#turbo_desktop_arch ⇒ Object
Returns the architecture: "aarch64", "x86_64", or nil.
-
#turbo_desktop_platform ⇒ Object
Returns the desktop platform: "macos", "windows", "linux", or nil.
Instance Method Details
#turbo_desktop_app? ⇒ Boolean
Returns true if the request is from a Turbo Desktop app.
17 18 19 |
# File 'lib/turbo_desktop/detection.rb', line 17 def turbo_desktop_app? request.user_agent.to_s.match?(TurboDesktop.configuration.user_agent_pattern) end |
#turbo_desktop_arch ⇒ Object
Returns the architecture: "aarch64", "x86_64", or nil.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/turbo_desktop/detection.rb', line 35 def turbo_desktop_arch return nil unless turbo_desktop_app? ua = request.user_agent.to_s case ua when /aarch64/i then "aarch64" when /x86_64/i then "x86_64" else nil end end |
#turbo_desktop_platform ⇒ Object
Returns the desktop platform: "macos", "windows", "linux", or nil.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/turbo_desktop/detection.rb', line 22 def turbo_desktop_platform return nil unless turbo_desktop_app? ua = request.user_agent.to_s case ua when /macOS/i then "macos" when /Windows/i then "windows" when /Linux/i then "linux" else nil end end |