Refactor DMS configuration and enhance Obsidian integration

- Replaced legacy Obsidian snippet directory options with a unified `obsidianVaults` option for better management.
- Updated DMS configuration to streamline widget handling and removed deprecated options.
- Introduced new templates for Hyprland colors and Obsidian themes to improve user customization.
- Added scripts for SwiftShare upload functionality, enhancing screenshot capabilities within the DMS environment.
This commit is contained in:
2026-06-21 15:56:27 -03:00
parent 8b66fa8665
commit 3fdb859ff8
9 changed files with 599 additions and 732 deletions
+15 -161
View File
@@ -7,6 +7,8 @@
hyprlandHm = lib.attrByPath [ "wayland" "windowManager" "hyprland" ] { } config;
hyprlandHmEnabled = hyprlandHm.enable or false;
keyOk = cfg.swiftshareApiKeyFile != null && cfg.swiftshareApiKeyFile != "";
uploadScript = builtins.readFile ./scripts/swiftshare-upload.sh;
screenshotScript = builtins.readFile ./scripts/swiftshare-screenshot.sh;
in
{
options.chiasson.home.desktop.screenshot.enable = lib.mkEnableOption ''
@@ -33,171 +35,23 @@
(lib.mkIf (root.enable && cfg.enable && keyOk) (
let
apiKeyFile = cfg.swiftshareApiKeyFile;
swiftshareUpload = pkgs.writeShellScriptBin "swiftshare-upload" (
builtins.replaceStrings [ "@API_KEY_FILE@" ] [ apiKeyFile ] uploadScript
);
swiftshareScreenshot = pkgs.writeShellScriptBin "swiftshare-screenshot" screenshotScript;
in
lib.mkMerge [
{
home.packages = with pkgs; [
grim
slurp
swappy
wl-clipboard
libnotify
(writeShellScriptBin "swiftshare-upload" ''
#!${pkgs.bash}/bin/bash
set -euo pipefail
COPY_URL=0
if [ "$#" -ge 1 ] && [ "$1" = "--copy-url" ]; then
COPY_URL=1
shift
fi
APP_NAME=""
if [ "$#" -ge 2 ] && [ "$1" = "--app-name" ]; then
APP_NAME="$2"
shift 2
fi
API_KEY_FILE=${lib.escapeShellArg apiKeyFile}
if [ -r "$API_KEY_FILE" ]; then
SWIFTSHARE_API_KEY="$(tr -d '\n' < "$API_KEY_FILE")"
fi
if [ -z "''${SWIFTSHARE_API_KEY:-}" ]; then
${pkgs.libnotify}/bin/notify-send "SwiftShare upload" "SwiftShare API key missing (expected readable: $API_KEY_FILE)"
echo "Error: SwiftShare API key missing (expected readable: $API_KEY_FILE)" >&2
exit 1
fi
IMAGE_FILE=""
RESPONSE_FILE=""
cleanup() {
if [ -n "$RESPONSE_FILE" ] && [ -f "$RESPONSE_FILE" ]; then
rm -f "$RESPONSE_FILE"
fi
}
trap cleanup EXIT
if [ "$#" -ge 1 ] && [ "$1" != "-" ]; then
IMAGE_FILE="$1"
if [ "''${IMAGE_FILE#'/'}" = "''${IMAGE_FILE}" ]; then
IMAGE_FILE="$(${pkgs.coreutils}/bin/readlink -f "''${IMAGE_FILE}")"
fi
if [ ! -f "$IMAGE_FILE" ]; then
echo "Error: file not found: $IMAGE_FILE" >&2
exit 1
fi
else
APP_NAME="''${APP_NAME:-screenshot}"
APP_NAME="''${APP_NAME%% *}"
APP_NAME="''${APP_NAME//[^A-Za-z0-9]/}"
APP_NAME="''${APP_NAME,,}"
if [ -z "$APP_NAME" ]; then
APP_NAME="screenshot"
fi
IMAGE_FILE="$(${pkgs.coreutils}/bin/mktemp --suffix=.png "''${TMPDIR:-/tmp}/''${APP_NAME}_XXXXXX")"
cat > "$IMAGE_FILE"
fi
if [ ! -s "$IMAGE_FILE" ]; then
${pkgs.libnotify}/bin/notify-send "SwiftShare" "Empty capture (maybe canceled) not uploading"
echo "Empty image file, not uploading." >&2
exit 0
fi
RESPONSE_FILE="$(mktemp)"
set +e
HTTP_STATUS="$(${pkgs.curl}/bin/curl -sS -o "''${RESPONSE_FILE}" -w '%{http_code}' \
-X POST "https://swiftshare.cloud/api/upload/sharex" \
-F "upload=@''${IMAGE_FILE}" \
-F "apiKey=''${SWIFTSHARE_API_KEY}")"
CURL_EXIT=$?
set -e
RESPONSE="$(cat "''${RESPONSE_FILE}")"
if [ "''${CURL_EXIT}" -ne 0 ]; then
${pkgs.libnotify}/bin/notify-send "SwiftShare upload failed" "Network or HTTP error (curl exit ''${CURL_EXIT})"
echo "SwiftShare upload failed (curl exit ''${CURL_EXIT})." >&2
echo "Response body:" >&2
echo "''${RESPONSE}" >&2
exit 1
fi
if ! echo "''${HTTP_STATUS}" | grep -qE '^2[0-9][0-9]$'; then
ERROR_MSG="$(${pkgs.jq}/bin/jq -r '.error // empty' <<< "''${RESPONSE}")"
if [ -z "''${ERROR_MSG}" ] || [ "''${ERROR_MSG}" = "null" ]; then
ERROR_MSG="Failed to upload file"
fi
${pkgs.libnotify}/bin/notify-send "SwiftShare upload failed (''${HTTP_STATUS})" "''${ERROR_MSG}"
echo "SwiftShare upload failed (HTTP ''${HTTP_STATUS}): ''${ERROR_MSG}" >&2
exit 1
fi
URL="$(${pkgs.jq}/bin/jq -r '.url // empty' <<< "''${RESPONSE}")"
THUMBNAIL="$(${pkgs.jq}/bin/jq -r '.thumbnail // empty' <<< "''${RESPONSE}")"
if [ -z "$URL" ] || [ "$URL" = "null" ]; then
${pkgs.libnotify}/bin/notify-send "SwiftShare upload failed" "Could not parse URL from response"
echo "Upload failed. Raw response:" >&2
echo "''${RESPONSE}" >&2
exit 1
fi
echo "$URL"
if [ -n "$THUMBNAIL" ] && [ "$THUMBNAIL" != "null" ]; then
echo "$THUMBNAIL"
fi
if [ "$COPY_URL" = "1" ]; then
${pkgs.wl-clipboard}/bin/wl-copy <<< "$URL"
fi
if [ -n "$IMAGE_FILE" ] && [ -f "$IMAGE_FILE" ]; then
${pkgs.libnotify}/bin/notify-send \
-a "SwiftShare" \
-i "$IMAGE_FILE" \
-h string:image-path:"$IMAGE_FILE" \
"SwiftShare upload" "Uploaded image: $URL"
else
${pkgs.libnotify}/bin/notify-send "SwiftShare upload" "Uploaded image: $URL"
fi
'')
(writeShellScriptBin "swiftshare-screenshot" ''
#!${pkgs.bash}/bin/bash
set -euo pipefail
LOG_DIR="$HOME/.local/state/swiftshare"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/screenshot.log"
APP_CLASS="$(${pkgs.hyprland}/bin/hyprctl activewindow -j 2>/dev/null | ${pkgs.jq}/bin/jq -r '.class // .initialClass // empty' 2>/dev/null || true)"
APP_CLASS="''${APP_CLASS%% *}"
APP_CLASS="''${APP_CLASS//[^A-Za-z0-9]/}"
APP_CLASS="''${APP_CLASS,,}"
if [ -z "$APP_CLASS" ]; then
APP_CLASS="screenshot"
fi
GEOM="$(${pkgs.slurp}/bin/slurp)"
SLURP_EXIT=$?
if [ "$SLURP_EXIT" -ne 0 ] || [ -z "$GEOM" ]; then
${pkgs.libnotify}/bin/notify-send "SwiftShare" "Capture canceled"
{
echo "==== $(date) ==== capture canceled (slurp exit $SLURP_EXIT, geom='$GEOM')"
} >>"$LOG_FILE" 2>&1
exit 0
fi
{
echo "==== $(date) ===="
echo "Geometry: $GEOM"
${pkgs.grim}/bin/grim -g "$GEOM" - | ${pkgs.swappy}/bin/swappy -f - -o - | swiftshare-upload --copy-url --app-name "$APP_CLASS"
} >>"$LOG_FILE" 2>&1
'')
grim
slurp
swappy
wl-clipboard
libnotify
curl
jq
swiftshareUpload
swiftshareScreenshot
];
}
(lib.mkIf hyprlandHmEnabled {
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail
LOG_DIR="$HOME/.local/state/swiftshare"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/screenshot.log"
APP_CLASS="$(hyprctl activewindow -j 2>/dev/null | jq -r '.class // .initialClass // empty' 2>/dev/null || true)"
APP_CLASS="${APP_CLASS%% *}"
APP_CLASS="${APP_CLASS//[^A-Za-z0-9]/}"
APP_CLASS="${APP_CLASS,,}"
if [ -z "$APP_CLASS" ]; then
APP_CLASS="screenshot"
fi
GEOM="$(slurp)"
SLURP_EXIT=$?
if [ "$SLURP_EXIT" -ne 0 ] || [ -z "$GEOM" ]; then
notify-send "SwiftShare" "Capture canceled"
{
echo "==== $(date) ==== capture canceled (slurp exit $SLURP_EXIT, geom='$GEOM')"
} >>"$LOG_FILE" 2>&1
exit 0
fi
{
echo "==== $(date) ===="
echo "Geometry: $GEOM"
grim -g "$GEOM" - | swappy -f - -o - | swiftshare-upload --copy-url --app-name "$APP_CLASS"
} >>"$LOG_FILE" 2>&1
@@ -0,0 +1,121 @@
#!/usr/bin/env bash
# API key path substituted at build time (@API_KEY_FILE@).
set -euo pipefail
COPY_URL=0
if [ "$#" -ge 1 ] && [ "$1" = "--copy-url" ]; then
COPY_URL=1
shift
fi
APP_NAME=""
if [ "$#" -ge 2 ] && [ "$1" = "--app-name" ]; then
APP_NAME="$2"
shift 2
fi
API_KEY_FILE=@API_KEY_FILE@
if [ -r "$API_KEY_FILE" ]; then
SWIFTSHARE_API_KEY="$(tr -d '\n' < "$API_KEY_FILE")"
fi
if [ -z "${SWIFTSHARE_API_KEY:-}" ]; then
notify-send "SwiftShare upload" "SwiftShare API key missing (expected readable: $API_KEY_FILE)"
echo "Error: SwiftShare API key missing (expected readable: $API_KEY_FILE)" >&2
exit 1
fi
IMAGE_FILE=""
RESPONSE_FILE=""
cleanup() {
if [ -n "$RESPONSE_FILE" ] && [ -f "$RESPONSE_FILE" ]; then
rm -f "$RESPONSE_FILE"
fi
}
trap cleanup EXIT
if [ "$#" -ge 1 ] && [ "$1" != "-" ]; then
IMAGE_FILE="$1"
if [ "${IMAGE_FILE#/}" = "${IMAGE_FILE}" ]; then
IMAGE_FILE="$(readlink -f "${IMAGE_FILE}")"
fi
if [ ! -f "$IMAGE_FILE" ]; then
echo "Error: file not found: $IMAGE_FILE" >&2
exit 1
fi
else
APP_NAME="${APP_NAME:-screenshot}"
APP_NAME="${APP_NAME%% *}"
APP_NAME="${APP_NAME//[^A-Za-z0-9]/}"
APP_NAME="${APP_NAME,,}"
if [ -z "$APP_NAME" ]; then
APP_NAME="screenshot"
fi
IMAGE_FILE="$(mktemp --suffix=.png "${TMPDIR:-/tmp}/${APP_NAME}_XXXXXX")"
cat > "$IMAGE_FILE"
fi
if [ ! -s "$IMAGE_FILE" ]; then
notify-send "SwiftShare" "Empty capture (maybe canceled) not uploading"
echo "Empty image file, not uploading." >&2
exit 0
fi
RESPONSE_FILE="$(mktemp)"
set +e
HTTP_STATUS="$(curl -sS -o "${RESPONSE_FILE}" -w '%{http_code}' \
-X POST "https://swiftshare.cloud/api/upload/sharex" \
-F "upload=${IMAGE_FILE}" \
-F "apiKey=${SWIFTSHARE_API_KEY}")"
CURL_EXIT=$?
set -e
RESPONSE="$(cat "${RESPONSE_FILE}")"
if [ "${CURL_EXIT}" -ne 0 ]; then
notify-send "SwiftShare upload failed" "Network or HTTP error (curl exit ${CURL_EXIT})"
echo "SwiftShare upload failed (curl exit ${CURL_EXIT})." >&2
echo "Response body:" >&2
echo "${RESPONSE}" >&2
exit 1
fi
if ! echo "${HTTP_STATUS}" | grep -qE '^2[0-9][0-9]$'; then
ERROR_MSG="$(jq -r '.error // empty' <<< "${RESPONSE}")"
if [ -z "${ERROR_MSG}" ] || [ "${ERROR_MSG}" = "null" ]; then
ERROR_MSG="Failed to upload file"
fi
notify-send "SwiftShare upload failed (${HTTP_STATUS})" "${ERROR_MSG}"
echo "SwiftShare upload failed (HTTP ${HTTP_STATUS}): ${ERROR_MSG}" >&2
exit 1
fi
URL="$(jq -r '.url // empty' <<< "${RESPONSE}")"
THUMBNAIL="$(jq -r '.thumbnail // empty' <<< "${RESPONSE}")"
if [ -z "$URL" ] || [ "$URL" = "null" ]; then
notify-send "SwiftShare upload failed" "Could not parse URL from response"
echo "Upload failed. Raw response:" >&2
echo "${RESPONSE}" >&2
exit 1
fi
echo "$URL"
if [ -n "$THUMBNAIL" ] && [ "$THUMBNAIL" != "null" ]; then
echo "$THUMBNAIL"
fi
if [ "$COPY_URL" = "1" ]; then
wl-copy <<< "$URL"
fi
if [ -n "$IMAGE_FILE" ] && [ -f "$IMAGE_FILE" ]; then
notify-send \
-a "SwiftShare" \
-i "$IMAGE_FILE" \
-h string:image-path:"$IMAGE_FILE" \
"SwiftShare upload" "Uploaded image: $URL"
else
notify-send "SwiftShare upload" "Uploaded image: $URL"
fi