Files
once-campfire/app/models/application_platform.rb
Kevin McConnell df76a227dc Hello world
First open source release of Campfire 🎉
2025-08-21 09:31:59 +01:00

62 lines
1.1 KiB
Ruby

class ApplicationPlatform < PlatformAgent
def ios?
match? /iPhone|iPad/
end
def android?
match? /Android/
end
def mac?
match? /Macintosh/
end
def chrome?
user_agent.browser.match? /Chrome/
end
def firefox?
user_agent.browser.match? /Firefox|FxiOS/
end
def safari?
user_agent.browser.match? /Safari/
end
def edge?
user_agent.browser.match? /Edg/
end
def apple_messages?
# Apple Messages pretends to be Facebook and Twitter bots via spoofed user agent.
# We want to avoid showing "Unsupported browser" message when a Campfire link
# is shared via Messages.
match?(/facebookexternalhit/i) && match?(/Twitterbot/i)
end
def mobile?
ios? || android?
end
def desktop?
!mobile?
end
def windows?
operating_system == "Windows"
end
def operating_system
case user_agent.platform
when /Android/ then "Android"
when /iPad/ then "iPad"
when /iPhone/ then "iPhone"
when /Macintosh/ then "macOS"
when /Windows/ then "Windows"
when /CrOS/ then "ChromeOS"
else
os =~ /Linux/ ? "Linux" : os
end
end
end