“DeviceService”
Device and Operating System Detection can be a pain, so i decided to make this abstraction layer so all my pain goes away. Huge thanks to @ChatGGPT for the OS detection function
Link to the resources
Setup
local engine = {DeviceService = require(game.ReplicatedStorage.DeviceService), _Enum = require(game.ReplicatedStorage._Enum)}
This is how you call it
Features
Events
.CheckDeviceType
Fires when you Emit, returns a device Enum from the weird custom Enum i made
.CheckPlatformType
Fires when you Emit as well, returns a Platform Enum eg(Windows,Android)
Function
:IsInGroup(device,groupEnum)
Enumate
or _Enum
It uses bitflag based constants for device types, groups or platforms. also includes a name table for easy lookup
This is the table for DeviceType
Enumate.DeviceType = {
Phone = 0x01,
Tablet = 0x02,
SmallPhone = 0x04,
Console = 0x08,
Computer = 0x10,
Unknown = 0xFFFF,
Potato = 0x40,
Name = {
[0x01] = “Phone”,
[0x02] = “Tablet”,
[0x04] = “SmallPhone”,
[0x08] = “Console”,
[0x10] = “Computer”,
[0x40] = “Potato”,
[0xFFFF] = “Unknown”,
}
}
Yes there is a “Name” table to make look ups easier, use Name[0x00] to find the string of the Enum
Sample
local engine = {DeviceService = require(game.ReplicatedStorage.DeviceService), _Enum = require(game.ReplicatedStorage._Enum)}
engine.DeviceService.CheckDeviceType:Connect(function(device)
if engine.DeviceService:IsInGroup(device, engine._Enum.DeviceGroup.Mobile) then
print(“Phone?”)
if plrgui.TouchGui then
else
print(“bad”)
end
end
print(engine._Enum.DeviceType.Name[device])
end)engine.DeviceService.CheckDevicePlatform:Connect(function(platform)
if platform == engine._Enum.Platform.Windows then
print(“Windows”)
end
end)
engine.DeviceService:Emit()
Why did I make this?
because device detection is very essential, and its a hassle to do so, so this is why I made this abstraction layer to make it easier to do so! Tweak, Fork, Rewrite if you want.
