Skip to content

Commit

Permalink
Add support for v1.x of the litra CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
timrogers committed Apr 25, 2024
1 parent 7784212 commit 3079083
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Logitech Litra Changelog

## [Allow `v1.x` of the `litra` CLI] - 2024-04-25

- `v1.x` of the [`litra` CLI](https://github.com/timrogers/litra-rs) is now supported, alongside `v0.x`

## [Improve the UI for displaying your Litra devices] - 2024-01-23

- The extension UI now shows the state of each Litra device - whether it's on or off, and the current brightness and temperature 💡
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This [Raycast](https://www.raycast.com/) extension allows you to manage your USB

## Installation

To use this extension, as well as downloading the extension from the Raycast Store, you must also set up the [`litra` command line](https://github.com/timrogers/litra-rs) on your machine by following the instructions in the readme. You must be running at least `v0.2.0` of `litra`.
To use this extension, as well as downloading the extension from the Raycast Store, you must also set up the [`litra` command line](https://github.com/timrogers/litra-rs) on your machine by following the instructions in the readme.

You must be running at least `v0.2.0` of `litra`, and only `v0.x` and `v1.x` versions are supported.

When you run the extension for the first time, you'll be prompted to configure the path of your `litra` binary. You can get this after installation by running `which litra` in a shell.
1 change: 0 additions & 1 deletion raycast-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ declare namespace Arguments {
/** Arguments passed to the `manage-brightness-presets` command */
export type ManageBrightnessPresets = {}
}

26 changes: 23 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,37 @@ import parse from "semver/functions/parse";
import { Device } from "./types";
const exec = promisify(defaultExec);

const joinWordsWithCommasThenOr = (words: string[]): string => {
if (words.length === 0) {
return "";
} else if (words.length === 1) {
return words[0];
} else {
const lastWord = words.pop();
return `${words.join(", ")} or ${lastWord}`;
}
};

const MINIMUM_SUPPORTED_LITRA_VERSION = "0.2.0";
const SUPPORTED_MAJOR_LITRA_VERSIONS = [0, 1];
const ALLOWED_MAJOR_VERSIONS_STRING = joinWordsWithCommasThenOr(
SUPPORTED_MAJOR_LITRA_VERSIONS.map((majorVersion) => `v${majorVersion}.x`),
);

export const checkLitraVersion = async (binaryPath: string): Promise<void> => {
const version = await getLitraVersion(binaryPath);
const parsedVersion = parse(version);

if (!parsedVersion) {
throw `The version of the \`litra\` CLI could not be detected. Please check the extension's preferences, and make sure that you're pointing to the \`litra\` CLI`;
}

if (gte(version, MINIMUM_SUPPORTED_LITRA_VERSION)) {
if (parse(version)?.major != parse(MINIMUM_SUPPORTED_LITRA_VERSION)?.major) {
throw `You are running v${version} of the \`litra\` CLI which is too new for this Raycast extension. Please downgrade to v${MINIMUM_SUPPORTED_LITRA_VERSION} or a later version within the same major version.`;
if (!SUPPORTED_MAJOR_LITRA_VERSIONS.includes(parsedVersion.major)) {
throw `You are running v${version} of the \`litra\` CLI which is too new for this Raycast extension. Please downgrade to an earlier version - you must use at least v${MINIMUM_SUPPORTED_LITRA_VERSION}, and it must be a ${ALLOWED_MAJOR_VERSIONS_STRING} version. To download a supported version, see https://github.com/timrogers/litra-rs`;
}
} else {
throw `You are running an old version of the \`litra\` CLI, v${version}. You must be running v${MINIMUM_SUPPORTED_LITRA_VERSION} or a later version within the same major version. For details on how to install the latest version, see https://github.com/timrogers/litra-rs.`;
throw `You are running an old version of the \`litra\` CLI, v${version}. Please upgrade to a more recent version - you must use at least v${MINIMUM_SUPPORTED_LITRA_VERSION}, and it must be a ${ALLOWED_MAJOR_VERSIONS_STRING} version. For details on how to install the latest version, see https://github.com/timrogers/litra-rs`;
}
};

Expand Down

0 comments on commit 3079083

Please sign in to comment.