action_options.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env sh
  2. # Tests for final action options with various flameshot commands
  3. # Arguments:
  4. # 1. path to tested flameshot executable
  5. # Dependencies:
  6. # - display command (imagemagick)
  7. # HOW TO USE:
  8. # - Start the script with path to tested flameshot executable as the first
  9. # argument
  10. #
  11. # - Read messages from stdout and see if flameshot sends the right notifications
  12. #
  13. # Some commands will pin screenshots to the screen. Check if that is happening
  14. # correctly. NOTE: the screen command will pin one screenshot over your entire
  15. # screen, so don't be confused by that.
  16. #
  17. # - When the flameshot gui is tested, follow the instructions from the system
  18. # notifications
  19. #
  20. # - Some tests may ask you for confirmation in the CLI before continuing.
  21. # - Whenever the --raw option is tested, the `display` command is used to open
  22. # the image from stdout in a window. Just close that window.
  23. #
  24. FLAMESHOT="$1"
  25. [ -z "$FLAMESHOT" ] && FLAMESHOT="flameshot"
  26. # --raw >/dev/null is a hack that makes the subcommand wait for the daemon to
  27. # finish the pending action
  28. flameshot() {
  29. command "$FLAMESHOT" "$@" --raw >/tmp/img.png
  30. }
  31. # Print the given command and run it
  32. cmd() {
  33. echo "$*" >&2
  34. "$@"
  35. sleep 1
  36. }
  37. notify() {
  38. if [ "$FLAMESHOT_PLATFORM" = "MAC" ]
  39. then
  40. osascript - "$1" <<EOF
  41. on run argv
  42. display notification (item 1 of argv) with title "Flameshot"
  43. end run
  44. EOF
  45. else
  46. notify-send "GUI Test 1: --path" "Make a selection, then accept"
  47. fi
  48. }
  49. display_img() {
  50. if [ "$FLAMESHOT_PLATFORM" = "MAC" ]
  51. then
  52. open -a Preview.app -f
  53. else
  54. display
  55. fi
  56. }
  57. wait_for_key() {
  58. echo "Press Enter to continue..." >&2 && read ____
  59. }
  60. # NOTE: Upload option is intentionally not tested
  61. # flameshot full & screen
  62. # ┗━━━━━━━━━━━━━━━━━━━━━━━━┛
  63. for subcommand in full screen
  64. do
  65. cmd flameshot "$subcommand" --path /tmp/
  66. cmd flameshot "$subcommand" --clipboard
  67. cmd command "$FLAMESHOT" "$subcommand" --raw | display_img
  68. [ "$subcommand" = "full" ] && sleep 1
  69. echo
  70. done
  71. echo "The next command will pin a screenshot over your entire screen."
  72. echo "Make sure to close it afterwards"
  73. echo "Press Enter to continue..."
  74. read ____
  75. flameshot screen --pin
  76. sleep 1
  77. # flameshot gui
  78. # ┗━━━━━━━━━━━━━━━┛
  79. wait_for_key
  80. notify "GUI Test 1: --path" #"Make a selection, then accept"
  81. cmd flameshot gui --path /tmp/
  82. wait_for_key
  83. notify "GUI Test 2: Clipboard" "Make a selection, then accept"
  84. cmd flameshot gui --clipboard
  85. wait_for_key
  86. notify "GUI Test 3: Print geometry" "Make a selection, then accept"
  87. cmd command "$FLAMESHOT" gui --print-geometry
  88. wait_for_key
  89. notify "GUI Test 4: Pin" "Make a selection, then accept"
  90. cmd flameshot gui --pin
  91. wait_for_key
  92. notify "GUI Test 5: Print raw" "Make a selection, then accept"
  93. cmd command "$FLAMESHOT" gui --raw | display_img
  94. wait_for_key
  95. notify "GUI Test 6: Copy on select" "Make a selection, flameshot will close automatically"
  96. cmd flameshot gui --clipboard --accept-on-select
  97. wait_for_key
  98. notify "GUI Test 7: File dialog on select" "After selecting, a file dialog will open"
  99. cmd flameshot gui --accept-on-select
  100. # All options except for --print-geometry (incompatible with --raw)
  101. wait_for_key
  102. notify "GUI Test 8: All actions except print-geometry" "Just make a selection"
  103. cmd command "$FLAMESHOT" gui -p /tmp/ -c -r --pin | display_img
  104. echo '>> All tests done.'