Handle Regretevator Screenshot Uploading URL Params
This commit is contained in:
@@ -2,11 +2,24 @@ import { $ } from "bun";
|
||||
import { Command } from "commander";
|
||||
import sharp from "sharp";
|
||||
import { writeFileSync } from "fs";
|
||||
import { getRegretevatorState } from "../lib/RegretevatorUtil";
|
||||
|
||||
async function getFilename(): Promise<string> {
|
||||
const _d = new Date();
|
||||
const windowClass = await $`hyprctl activewindow -j`.json();
|
||||
return `${windowClass.initialClass || "Hyprland"}-${_d.getTime()}`;
|
||||
const isRoblox =
|
||||
windowClass.initialClass === "org.vinegarhq.Sober" ? true : false;
|
||||
const regretevatorState = isRoblox ? getRegretevatorState() : null;
|
||||
// console.log(isRoblox, regretevatorState)
|
||||
return `${isRoblox ? "Roblox" : (windowClass.initialClass || "Hyprland")}-${_d.getTime()}${
|
||||
!regretevatorState
|
||||
? ""
|
||||
: `-regretevator${
|
||||
regretevatorState.state === "INGAME"
|
||||
? `-${regretevatorState.floor}`
|
||||
: ""
|
||||
}`
|
||||
}`;
|
||||
}
|
||||
|
||||
const program = new Command("handle-screenshot");
|
||||
@@ -27,58 +40,73 @@ async function transformImage(b: Buffer): Promise<Buffer> {
|
||||
</svg>`
|
||||
);
|
||||
|
||||
const maskedImage = image.composite([
|
||||
{
|
||||
input: mask,
|
||||
gravity: "center",
|
||||
blend: "dest-in"
|
||||
},
|
||||
]).extend({
|
||||
top: 16,
|
||||
bottom: 16,
|
||||
left: 16,
|
||||
right: 16
|
||||
}).ensureAlpha();
|
||||
const maskedImage = image
|
||||
.composite([
|
||||
{
|
||||
input: mask,
|
||||
gravity: "center",
|
||||
blend: "dest-in",
|
||||
},
|
||||
])
|
||||
.extend({
|
||||
top: 16,
|
||||
bottom: 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
})
|
||||
.ensureAlpha();
|
||||
|
||||
return await maskedImage.png().toBuffer() as Buffer;
|
||||
return (await maskedImage.png().toBuffer()) as Buffer;
|
||||
}
|
||||
|
||||
(() => {
|
||||
program
|
||||
.command("selection")
|
||||
.description("Takes a screenshot from selection")
|
||||
.action(async () => {
|
||||
const selection = await $`slurp -w 0 -d -b "#cdd6f444"`
|
||||
.nothrow()
|
||||
.quiet();
|
||||
if (
|
||||
selection.exitCode !== 0 ||
|
||||
selection.stdout.toString().includes("cancel")
|
||||
) {
|
||||
console.log("/tmp/woah");
|
||||
process.exit(0);
|
||||
}
|
||||
const _BUF = await $`grim -t png -l 0 -g ${selection.stdout
|
||||
.toString()
|
||||
.trim()} -`.arrayBuffer();
|
||||
let BUF = Buffer.from(_BUF) as Buffer;
|
||||
|
||||
program.command("selection").description("Takes a screenshot from selection").action(async () => {
|
||||
const selection = await $`slurp -w 0 -d -b "#cdd6f444"`.nothrow().quiet();
|
||||
if (selection.exitCode !== 0 || selection.stdout.toString().includes("cancel")) {
|
||||
console.log("/tmp/woah");
|
||||
process.exit(0);
|
||||
};
|
||||
const _BUF = await $`grim -t png -l 0 -g ${selection.stdout.toString().trim()} -`.arrayBuffer();
|
||||
let BUF = Buffer.from(_BUF) as Buffer;
|
||||
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||
|
||||
// BUF = await transformImage(BUF);
|
||||
writeFileSync(FILENAME,BUF);
|
||||
console.log(FILENAME);
|
||||
});
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||
|
||||
// BUF = await transformImage(BUF);
|
||||
writeFileSync(FILENAME, BUF);
|
||||
console.log(FILENAME);
|
||||
});
|
||||
})();
|
||||
|
||||
(() => {
|
||||
program
|
||||
.command("fullscreen")
|
||||
.description("Takes a fullsceen screenshot")
|
||||
.action(async () => {
|
||||
const selection =
|
||||
await $`hyprctl monitors | awk '/Monitor/{monitor=$2} /focused: yes/{print monitor; exit}'`
|
||||
.nothrow()
|
||||
.text();
|
||||
|
||||
program.command("fullscreen").description("Takes a fullsceen screenshot").action(async () => {
|
||||
const selection = await $`hyprctl monitors | awk '/Monitor/{monitor=$2} /focused: yes/{print monitor; exit}'`.nothrow().text();
|
||||
const _BUF =
|
||||
await $`grim -t png -l 0 -o ${selection.trim()} -`.arrayBuffer();
|
||||
let BUF = Buffer.from(_BUF) as Buffer;
|
||||
|
||||
const _BUF = await $`grim -t png -l 0 -o ${selection.trim()} -`.arrayBuffer();
|
||||
let BUF = Buffer.from(_BUF) as Buffer;
|
||||
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||
|
||||
// BUF = await transformImage(BUF);
|
||||
writeFileSync(FILENAME,BUF);
|
||||
console.log(FILENAME)
|
||||
});
|
||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||
|
||||
// BUF = await transformImage(BUF);
|
||||
writeFileSync(FILENAME, BUF);
|
||||
console.log(FILENAME);
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
Reference in New Issue
Block a user