Skip to content

hasCapability ​

hasCapability checks whether a SystemCapability is available on this system.

SignaturehasCapability(cap: SystemCapability): boolean
tyrus
import { SystemCapability, hasCapability } from "tyrus:os";

if (hasCapability(SystemCapability.Notification)) {
    // safe to call notify(), the notification service is reachable
}

Answers "can I find out?"/"would this work?" without triggering the real effect, checking Notification does not pop up a notification, checking SleepPrevention does not spawn an inhibitor process.

SystemCapability Members ​

MemberMeaning
NotificationWhether a desktop notification could plausibly be shown.
ClipboardWhether the system clipboard can be reached.
BatteryWhether this machine reports at least one battery.
DarkModeWhether the desktop's dark-mode setting is queryable at all.
ScreenLockWhether the screensaver/lock-screen state is queryable at all (Linux only).
SessionLockWhether the session-lock state is queryable at all (Linux only).
SleepPreventionWhether preventSleep()/allowSleep() would actually work.
FontsWhether systemFonts() would return anything.

Not the same question as the function it mirrors

hasCapability(SystemCapability.ScreenLock) asks whether the screensaver state is queryable at all, not whether the screen is currently locked, that is isScreenLocked()'s own return value. The same distinction applies to every other capability that mirrors a real function (Battery vs. battery(), DarkMode vs. isDarkMode(), and so on).