Handle Regretevator Screenshot Uploading URL Params

This commit is contained in:
2025-03-29 17:00:23 +02:00
parent 8ba7e012a2
commit fad2e52ebb
6 changed files with 139 additions and 48 deletions

View File

@@ -45,7 +45,7 @@ label {
}
label {
text = cmd[update:1000] playerctl metadata -sf "{{artist}} - {{title}}<br/><small>{{album}}</small>"
text = cmd[update:1000] playerctl metadata -sf "{{artist}} - {{title}}<br/>{{album}}"
font_family = Geist
color = rgb(255, 0, 0)
position = 10, -10

View File

@@ -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);

View File

@@ -5,6 +5,8 @@ import { readdirSync, readFileSync, statSync } from "fs";
import { join } from "path";
try {
const start = Date.now();
$`notify-send -t 1000 "Screenshot" "Uploading.."`.nothrow().catch(a => { });
configDotenv({
path: `${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env`
});
@@ -16,10 +18,12 @@ try {
endpoint: process.env.S3_ENDPOINT_URL,
});
let urlParams = "";
const screenshotsDir = join(homedir(), "Pictures", "Screenshots");
const files = readdirSync(screenshotsDir);
const latestFile = files
let latestFile = files
.map(file => ({
file,
time: statSync(join(screenshotsDir, file)).mtime.getTime()
@@ -28,13 +32,23 @@ try {
const filePath = join(screenshotsDir, latestFile);
const start = Date.now();
let [ _, regretevator, floorNum ] = latestFile.match(/\-(regretevator)\-?([0-9]+)?\.png$/) || [];
if (regretevator === "regretevator") {
latestFile = latestFile.replace(`-regretevator${floorNum ? `-${floorNum}` : ""}.png`,".png")
if (floorNum) {
urlParams = `?floor=${floorNum}`
} else {
urlParams = `?regretevator`
}
}
const file = bucket.file(latestFile)
await file.write(readFileSync(filePath), {
type: "image/png"
})
$`echo "https://i.darktru.win/${latestFile}" | wl-copy -n`.nothrow().catch(a => { });
$`notify-send "Screenshot" "Uploaded in ${Date.now() - start}ms"`.nothrow().catch(a => { });
$`echo "https://i.darktru.win/${encodeURIComponent(latestFile)}${urlParams}" | wl-copy -n`.nothrow().catch(a => { });
$`notify-send "Screenshot" "Uploaded in ${Date.now() - start}ms<br/><small>${latestFile}</small>"`.nothrow().catch(a => { });
} catch (e_) {
$`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { });
}

View File

@@ -5,7 +5,7 @@ SCREENSHOTS_DIR="$HOME/Pictures/Screenshots"
LAST_SCREENSHOT=$(ls -t "$SCREENSHOTS_DIR" | head -n 1)
if [[ -n "$LAST_SCREENSHOT" ]]; then
swappy -f "$SCREENSHOTS_DIR/$LAST_SCREENSHOT" # -o "$SCREENSHOTS_DIR/$LAST_SCREENSHOT"
swappy -f "$SCREENSHOTS_DIR/$LAST_SCREENSHOT" -o "$SCREENSHOTS_DIR/$LAST_SCREENSHOT"
else
notify-send -u critical -t 3 "Error" "Can't find screenshot :("
fi

View File

@@ -1,6 +1,6 @@
#!/bin/bash
trap "pkill -9 waybar" EXIT
pkill -9 waybar
hyprctl dispatch exec "GTK_THEME=Adwaita waybar -c ~/config/config/waybar/config -s ~/config/config/waybar/style.css" &
hyprctl reload

View File

@@ -0,0 +1,49 @@
import { existsSync, readFileSync } from "fs";
const STATE_FILE_PATH = "/tmp/.regretevator_state";
type DeadUnknownState = { state: "DEAD" | "UNKNOWN" };
type InElevatorState = {
floor: number;
state: "INGAME";
isGoingUp: boolean;
};
export type RegretevatorState = DeadUnknownState | InElevatorState;
/*
➜ config git:(main) ✗ cat /tmp/.regretevator_state
{"text":"ý 82","tooltip":"On Floor 82"}
➜ config git:(main) ✗ cat /tmp/.regretevator_state
{"text":"ý ","tooltip":"Floor 82  83"}
*/
export function getRegretevatorState(): null | RegretevatorState {
if (!existsSync(STATE_FILE_PATH)) return null;
try {
const {text, tooltip}: { text: string, tooltip: string } = JSON.parse(readFileSync(STATE_FILE_PATH).toString('utf-8'))
if (/^On Floor ([0-9]+)$/.test(tooltip)) {
const floorNum = tooltip.match(/^On Floor ([0-9]+)$/)![1]
return {
floor: Number(floorNum),
state: "INGAME",
isGoingUp: false
}
}
if (/^Floor ([0-9]+)/.test(tooltip)) {
const floorNum = tooltip.match(/^Floor ([0-9]+)/)![1]
return {
floor: Number(floorNum),
state: "INGAME",
isGoingUp: true
}
}
return {
state: "UNKNOWN"
}
} catch {}
return null;
}