diff --git a/bun.lockb b/bun.lockb index 096a377..56afe13 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/config/hypr/config/autoexec.conf b/config/hypr/config/autoexec.conf index 2aaf5a9..96dbce4 100644 --- a/config/hypr/config/autoexec.conf +++ b/config/hypr/config/autoexec.conf @@ -17,7 +17,7 @@ exec-once = bash ~/config/config/scripts/xdg.sh exec-once = bash ~/config/config/scripts/gtk.sh # Start Hot Reload -exec-once = bash ~/config/config/scripts/hot-reload.sh +exec-once = sleep 1000 & bash ~/config/config/scripts/hot-reload.sh # Start arRPC exec-once = arrpc diff --git a/config/hypr/config/keybindings/other.conf b/config/hypr/config/keybindings/other.conf index 2bbcb46..22c4518 100644 --- a/config/hypr/config/keybindings/other.conf +++ b/config/hypr/config/keybindings/other.conf @@ -40,7 +40,7 @@ bind = CTRL SUPER ALT, L, exec, hyprlock bind = $mainMod ALT CTRL, mouse_down, exec, hyprctl keyword cursor:zoom_factor "$(hyprctl getoption cursor:zoom_factor | awk 'NR==1 {factor = $2; if (factor < 1) {factor = 1}; print factor * 1.25}')" bind = $mainMod ALT CTRL, mouse_up, exec, hyprctl keyword cursor:zoom_factor "$(hyprctl getoption cursor:zoom_factor | awk 'NR==1 {factor = $2; if (factor < 1) {factor = 1}; print factor / 1.25}')" -bind = $mainMod SHIFT, M, exec, bun run $HOME/config/scripts/bin/r2UploadScreenshot.ts +bind = $mainMod SHIFT, M, exec, bun run $HOME/config/scripts/bin/r2Upload.ts bind = $mainMod, F1, exec, bash $HOME/config/scripts/roblox-fullscreen.sh bind = $mainMod, F2, exec, bash -c "xdg-open roblox://" bind = $mainMod, F5, exec, notify-send -u critical "Hyprland" "Enabled debug overlay" && hyprctl keyword debug:overlay 1 diff --git a/package.json b/package.json index 338b408..07bac45 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,10 @@ }, "dependencies": { "@types/commander": "^2.12.5", + "@types/dotenv": "^8.2.3", "@types/sharp": "^0.32.0", "commander": "^13.1.0", + "dotenv": "^16.4.7", "sharp": "^0.33.5" } } \ No newline at end of file diff --git a/scripts/bin/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env.example b/scripts/bin/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env.example new file mode 100644 index 0000000..07b6bbb --- /dev/null +++ b/scripts/bin/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env.example @@ -0,0 +1,5 @@ +# Plant this in your home dir +S3_ACCESS_KEY=xxxxxxxxxxxxxxxx +S3_SECRET_KEY=xxxxxxxxxxxxxxxx +S3_BUCKET_NAME=dotfiles-screenshot +S3_ENDPOINT_URL="https://xxxxxxxxxxxxxxxx.r2.cloudflarestorage.com" diff --git a/scripts/bin/handleScreenshot.ts b/scripts/bin/handleScreenshot.ts index 0f68b5b..6018578 100755 --- a/scripts/bin/handleScreenshot.ts +++ b/scripts/bin/handleScreenshot.ts @@ -3,6 +3,12 @@ import { Command } from "commander"; import sharp from "sharp"; import { writeFileSync } from "fs"; +async function getFilename(): Promise { + const _d = new Date(); + const windowClass = await $`hyprctl activewindow -j`.json(); + return `${windowClass.initialClass || "Hyprland"}-${_d.getTime()}`; +} + const program = new Command("handle-screenshot"); const SCREENSHOT_PATH = `/home/ocbwoy3/Pictures/Screenshots`; @@ -48,8 +54,7 @@ async function transformImage(b: Buffer): Promise { const _BUF = await $`grim -t png -l 0 -g ${selection.stdout.toString().trim()} -`.arrayBuffer(); let BUF = Buffer.from(_BUF) as Buffer; - const _d = new Date(); - const FILENAME = `${SCREENSHOT_PATH}/${_d.toISOString()}-${_d.getTime()}.png` + const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`; // BUF = await transformImage(BUF); writeFileSync(FILENAME,BUF); @@ -66,8 +71,7 @@ async function transformImage(b: Buffer): Promise { const _BUF = await $`grim -t png -l 0 -o ${selection.trim()} -`.arrayBuffer(); let BUF = Buffer.from(_BUF) as Buffer; - const _d = new Date(); - const FILENAME = `${SCREENSHOT_PATH}/${_d.toISOString()}-${_d.getTime()}.png` + const FILENAME = `${SCREENSHOT_PATH}/${await getFilename()}.png`; // BUF = await transformImage(BUF); writeFileSync(FILENAME,BUF); diff --git a/scripts/bin/r2Upload.ts b/scripts/bin/r2Upload.ts new file mode 100644 index 0000000..faad17a --- /dev/null +++ b/scripts/bin/r2Upload.ts @@ -0,0 +1,41 @@ +import { $, S3Client } from "bun"; +import { configDotenv } from "dotenv"; +import { homedir } from "os"; +import { readdirSync, readFileSync, statSync } from "fs"; +import { join } from "path"; + +try { + configDotenv({ + path: `${homedir()}/.ocbwoy3-dotfiles-SECRET-DO-NOT-TOUCH.env` + }); + + const bucket = new S3Client({ + accessKeyId: process.env.S3_ACCESS_KEY, + secretAccessKey: process.env.S3_SECRET_KEY, + bucket: process.env.S3_BUCKET_NAME, + endpoint: process.env.S3_ENDPOINT_URL, + }); + + const screenshotsDir = join(homedir(), "Pictures", "Screenshots"); + const files = readdirSync(screenshotsDir); + + const latestFile = files + .map(file => ({ + file, + time: statSync(join(screenshotsDir, file)).mtime.getTime() + })) + .sort((a, b) => b.time - a.time)[0].file; + + const filePath = join(screenshotsDir, latestFile); + + const start = Date.now(); + 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 => { }); +} catch (e_) { + $`notify-send "Screenshot" "${`${e_}`}"`.nothrow().catch(a => { }); +} + diff --git a/scripts/hot-reload.sh b/scripts/hot-reload.sh index 2361dfa..6f07374 100755 --- a/scripts/hot-reload.sh +++ b/scripts/hot-reload.sh @@ -1,6 +1,6 @@ #!/bin/bash -pkill -9 waybar +trap "pkill -9 waybar" EXIT hyprctl dispatch exec "GTK_THEME=Adwaita waybar -c ~/config/config/waybar/config -s ~/config/config/waybar/style.css" & hyprctl reload