hasCapability
hasCapability checks whether a SystemCapability is available on this system.
Signature
hasCapability(cap: SystemCapability): booleantyrus
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
| Member | Meaning |
|---|---|
Notification | Whether a desktop notification could plausibly be shown. |
Clipboard | Whether the system clipboard can be reached. |
Battery | Whether this machine reports at least one battery. |
DarkMode | Whether the desktop's dark-mode setting is queryable at all. |
ScreenLock | Whether the screensaver/lock-screen state is queryable at all (Linux only). |
SessionLock | Whether the session-lock state is queryable at all (Linux only). |
SleepPrevention | Whether preventSleep()/allowSleep() would actually work. |
Fonts | Whether 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).
