Handle Regretevator Screenshot Uploading URL Params
This commit is contained in:
@@ -45,7 +45,7 @@ label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
font_family = Geist
|
||||||
color = rgb(255, 0, 0)
|
color = rgb(255, 0, 0)
|
||||||
position = 10, -10
|
position = 10, -10
|
||||||
|
|||||||
@@ -2,11 +2,24 @@ import { $ } from "bun";
|
|||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { writeFileSync } from "fs";
|
import { writeFileSync } from "fs";
|
||||||
|
import { getRegretevatorState } from "../lib/RegretevatorUtil";
|
||||||
|
|
||||||
async function getFilename(): Promise<string> {
|
async function getFilename(): Promise<string> {
|
||||||
const _d = new Date();
|
const _d = new Date();
|
||||||
const windowClass = await $`hyprctl activewindow -j`.json();
|
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");
|
const program = new Command("handle-screenshot");
|
||||||
@@ -27,58 +40,73 @@ async function transformImage(b: Buffer): Promise<Buffer> {
|
|||||||
</svg>`
|
</svg>`
|
||||||
);
|
);
|
||||||
|
|
||||||
const maskedImage = image.composite([
|
const maskedImage = image
|
||||||
|
.composite([
|
||||||
{
|
{
|
||||||
input: mask,
|
input: mask,
|
||||||
gravity: "center",
|
gravity: "center",
|
||||||
blend: "dest-in"
|
blend: "dest-in",
|
||||||
},
|
},
|
||||||
]).extend({
|
])
|
||||||
|
.extend({
|
||||||
top: 16,
|
top: 16,
|
||||||
bottom: 16,
|
bottom: 16,
|
||||||
left: 16,
|
left: 16,
|
||||||
right: 16
|
right: 16,
|
||||||
}).ensureAlpha();
|
})
|
||||||
|
.ensureAlpha();
|
||||||
|
|
||||||
return await maskedImage.png().toBuffer() as Buffer;
|
return (await maskedImage.png().toBuffer()) as Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
|
program
|
||||||
program.command("selection").description("Takes a screenshot from selection").action(async () => {
|
.command("selection")
|
||||||
const selection = await $`slurp -w 0 -d -b "#cdd6f444"`.nothrow().quiet();
|
.description("Takes a screenshot from selection")
|
||||||
if (selection.exitCode !== 0 || selection.stdout.toString().includes("cancel")) {
|
.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");
|
console.log("/tmp/woah");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
}
|
||||||
const _BUF = await $`grim -t png -l 0 -g ${selection.stdout.toString().trim()} -`.arrayBuffer();
|
const _BUF = await $`grim -t png -l 0 -g ${selection.stdout
|
||||||
|
.toString()
|
||||||
|
.trim()} -`.arrayBuffer();
|
||||||
let BUF = Buffer.from(_BUF) as Buffer;
|
let BUF = Buffer.from(_BUF) as Buffer;
|
||||||
|
|
||||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||||
|
|
||||||
// BUF = await transformImage(BUF);
|
// BUF = await transformImage(BUF);
|
||||||
writeFileSync(FILENAME,BUF);
|
writeFileSync(FILENAME, BUF);
|
||||||
console.log(FILENAME);
|
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 _BUF =
|
||||||
const selection = await $`hyprctl monitors | awk '/Monitor/{monitor=$2} /focused: yes/{print monitor; exit}'`.nothrow().text();
|
await $`grim -t png -l 0 -o ${selection.trim()} -`.arrayBuffer();
|
||||||
|
|
||||||
const _BUF = await $`grim -t png -l 0 -o ${selection.trim()} -`.arrayBuffer();
|
|
||||||
let BUF = Buffer.from(_BUF) as Buffer;
|
let BUF = Buffer.from(_BUF) as Buffer;
|
||||||
|
|
||||||
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`;
|
||||||
|
|
||||||
// BUF = await transformImage(BUF);
|
// BUF = await transformImage(BUF);
|
||||||
writeFileSync(FILENAME,BUF);
|
writeFileSync(FILENAME, BUF);
|
||||||
console.log(FILENAME)
|
console.log(FILENAME);
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { readdirSync, readFileSync, statSync } from "fs";
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const start = Date.now();
|
||||||
|
$`notify-send -t 1000 "Screenshot" "Uploading.."`.nothrow().catch(a => { });
|
||||||
configDotenv({
|
configDotenv({
|
||||||
path: `${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env`
|
path: `${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env`
|
||||||
});
|
});
|
||||||
@@ -16,10 +18,12 @@ try {
|
|||||||
endpoint: process.env.S3_ENDPOINT_URL,
|
endpoint: process.env.S3_ENDPOINT_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let urlParams = "";
|
||||||
|
|
||||||
const screenshotsDir = join(homedir(), "Pictures", "Screenshots");
|
const screenshotsDir = join(homedir(), "Pictures", "Screenshots");
|
||||||
const files = readdirSync(screenshotsDir);
|
const files = readdirSync(screenshotsDir);
|
||||||
|
|
||||||
const latestFile = files
|
let latestFile = files
|
||||||
.map(file => ({
|
.map(file => ({
|
||||||
file,
|
file,
|
||||||
time: statSync(join(screenshotsDir, file)).mtime.getTime()
|
time: statSync(join(screenshotsDir, file)).mtime.getTime()
|
||||||
@@ -28,13 +32,23 @@ try {
|
|||||||
|
|
||||||
const filePath = join(screenshotsDir, latestFile);
|
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)
|
const file = bucket.file(latestFile)
|
||||||
await file.write(readFileSync(filePath), {
|
await file.write(readFileSync(filePath), {
|
||||||
type: "image/png"
|
type: "image/png"
|
||||||
})
|
})
|
||||||
$`echo "https://i.darktru.win/${latestFile}" | wl-copy -n`.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"`.nothrow().catch(a => { });
|
$`notify-send "Screenshot" "Uploaded in ${Date.now() - start}ms<br/><small>${latestFile}</small>"`.nothrow().catch(a => { });
|
||||||
} catch (e_) {
|
} catch (e_) {
|
||||||
$`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { });
|
$`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ SCREENSHOTS_DIR="$HOME/Pictures/Screenshots"
|
|||||||
LAST_SCREENSHOT=$(ls -t "$SCREENSHOTS_DIR" | head -n 1)
|
LAST_SCREENSHOT=$(ls -t "$SCREENSHOTS_DIR" | head -n 1)
|
||||||
|
|
||||||
if [[ -n "$LAST_SCREENSHOT" ]]; then
|
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
|
else
|
||||||
notify-send -u critical -t 3 "Error" "Can't find screenshot :("
|
notify-send -u critical -t 3 "Error" "Can't find screenshot :("
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/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 dispatch exec "GTK_THEME=Adwaita waybar -c ~/config/config/waybar/config -s ~/config/config/waybar/style.css" &
|
||||||
hyprctl reload
|
hyprctl reload
|
||||||
|
|||||||
49
scripts/lib/RegretevatorUtil.ts
Normal file
49
scripts/lib/RegretevatorUtil.ts
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user