41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
|
/**
|
||
|
* @file rotate.ts
|
||
|
*
|
||
|
* @summary Raycast command to rotate selected images by a specified number of degrees.
|
||
|
*
|
||
|
* Created at : 2023-07-06 14:56:15
|
||
|
* Last modified : 2023-07-18 18:48:47
|
||
|
*/
|
||
|
|
||
|
import { getPreferenceValues, showToast, Toast } from "@raycast/api";
|
||
|
|
||
|
import rotate from "./operations/rotateOperation";
|
||
|
import { getSelectedImages } from "./utilities/utils";
|
||
|
import { RotatePreferences } from "./utilities/preferences";
|
||
|
import { parser } from "mathjs";
|
||
|
import runOperation from "./operations/runOperation";
|
||
|
|
||
|
export default async function Command(props: { arguments: { angle: string } }) {
|
||
|
const { angle } = props.arguments;
|
||
|
const preferences = getPreferenceValues<RotatePreferences>();
|
||
|
|
||
|
let angleNumber = parseFloat(parser().evaluate(angle).toString());
|
||
|
if (isNaN(angleNumber)) {
|
||
|
await showToast({ title: "Angle must be a number", style: Toast.Style.Failure });
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (preferences.rotationUnit === "radians") {
|
||
|
angleNumber = angleNumber * (180 / Math.PI);
|
||
|
}
|
||
|
|
||
|
const selectedImages = await getSelectedImages();
|
||
|
await runOperation({
|
||
|
operation: () => rotate(selectedImages, angleNumber),
|
||
|
selectedImages,
|
||
|
inProgressMessage: "Rotation in progress...",
|
||
|
successMessage: "Rotated",
|
||
|
failureMessage: "Failed to rotate",
|
||
|
});
|
||
|
}
|