@jcbhmr/getdesktopenv v1.0.0
getDesktopEnv()
for Node.js
š¼ļø Which desktop environment is available, if any? \ š” Inspired by t1st3/desktop-env
šØ Lets you know if the user can open a GUI or not \
š§ Supports Linux, macOS, and Windows \
š¦ Works in Node.js, Deno, and Bun \
š« Has a sham for the browser (returns null
) \
š©āš» Includes a basic CLI
š I need your help! What does your development environment return? What desktop environment are you using? Open an Issue and let me know! š I want to make this package more robust and accurate! š
Installation
You can install this package using npm, Yarn, or pnpm.
npm install @jcbhmr/getdesktopenv
If you're using this in the browser, don't worry! There's a stub implementation
just for you that always returns null
. š
Usage
This package exports a single function, getDesktopEnv()
, which returns a
Promise<string | null>
. The string that it resolves to is the name of the
desktop environment that was detected. If no desktop environment was detected,
it will resolve to null
.
import getDesktopEnv from "@jcbhmr/getdesktopenv";
console.log(getDesktopEnv());
//=> 'Windows shell'
You can also use the CLI directly if you just want to check your desktop env in CI or something. I don't judge. š
npx @jcbhmr/getdesktopenv
#=> 'Windows shell'
When using a headless Linux OS (like you might in, say GitHub Actions or GitHub
Codespaces), this function will return null
. If no desktop environment was
matched (an unknown desktop environment) this function will return null
. If
you're in the browser, this function will also return null
.
š If you are using a desktop environment that's not in the list, open an Issue! We want to support as many desktop environments as possible. š
Development
This project uses plain JavaScript. It's so simple that we can get away with this! š We also don't have any tests, because this is a very simple package. You are expected to manually make sure that this package works before doing anything major. š Testing is also a bit unfeasible, because there's not a lot of CI providers that support desktop environments. š
Here's how you might manually test this package in Node.js:
$ node
Welcome to Node.js v19.9.0.
Type ".help" for more information.
> let m; m = await import("@jcbhmr/getdesktopenv")
[Module: null prototype] { default: [AsyncFunction: getDesktopEnv] }
> await m.default()
'Windows shell'
ā¹ There's currently a quirk with JSDoc and TypeScript. TypeScript still wants to
look for a @types/*
package even though we provide JSDoc types. š¤·āāļø #1