1.0.0 ā€¢ Published 11 months ago

@jcbhmr/getdesktopenv v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

getDesktopEnv() for Node.js

šŸ–¼ļø Which desktop environment is available, if any? \ šŸ’” Inspired by t1st3/desktop-env

npm.io

šŸŽØ 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

npm Yarn pnpm

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

Node.js Deno Bun

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

JavaScript

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

1.0.0

11 months ago

0.2.2

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.1

11 months ago