5555 :type '(choice (const nil ) (other t ))
5656 :group 'hover )
5757
58+ (defcustom hover-screenshot-path nil
59+ " If non-nil, save hover screenshot on specified folder.
60+ Default to project root."
61+ :type 'string
62+ :group 'hover )
63+
64+ (defcustom hover-screenshot-prefix " hover-"
65+ " Prefix for file name on `hover-take-screenshot`."
66+ :type 'string
67+ :group 'hover )
68+
69+ (defcustom hover-observatory-uri " http://127.0.0.1:50300"
70+ " Hover custom observatory-uri.
71+ Default is hover's default uri"
72+ :type 'string
73+ :group 'hover )
74+
5875(defvar hover-mode-map (copy-keymap comint-mode-map)
5976 " Basic mode map for `hover-run' ." )
6077
@@ -103,7 +120,7 @@ The function's name will be NAME prefixed with 'hover-'."
103120
104121(defun hover--project-get-root ()
105122 " Find the root of the current project."
106- (or (locate-dominating-file default-directory " go" )
123+ (or (expand-file-name ( locate-dominating-file default-directory " go" ) )
107124 (error " This does not appear to be a Hover project (go folder not found), did you already run `hover init`? " )))
108125
109126(defun hover--running-p ()
@@ -122,6 +139,18 @@ The function's name will be NAME prefixed with 'hover-'."
122139 (when (hover--running-p)
123140 (hover--run-command-on-hover-buffer " r" )))
124141
142+ (defun hover--build-screenshot-file-name ()
143+ " Build screenshot file name with a timestamp."
144+ (let ((formatted-timestamp (format-time-string " %Y-%m-%dT%T" )))
145+ (concat hover-screenshot-prefix formatted-timestamp " .png" )))
146+
147+ (defun hover--take-screenshot (file-path uri )
148+ " Run `fluter screenshot` to take a screenshot of hover application.
149+ Save on FILE-PATH and use the observatory URI given."
150+ (compilation-start
151+ (format " %s screenshot --type=rasterizer --out=%s --observatory-uri=%s " (hover-build-flutter-command) file-path uri)
152+ t ))
153+
125154
126155; ;; Key bindings
127156
@@ -140,7 +169,6 @@ The function's name will be NAME prefixed with 'hover-'."
140169 (" z" . elevation-checker)
141170 (" P" . performance-overlay)
142171 (" a" . timeline-events)
143- (" s" . screenshot)
144172 (" d" . detatch)
145173 (" q" . quit)))
146174
@@ -169,6 +197,12 @@ the `hover` process."
169197 " hover"
170198 (error (format " Hover command not found in go path '%s '. Try to configure `hover-command-path` " hover-command-path)))))
171199
200+ (defun hover-build-flutter-command ()
201+ " Check if command exists and return the flutter command."
202+ (if hover-flutter-sdk-path
203+ (concat (file-name-as-directory hover-flutter-sdk-path) " bin/flutter" )
204+ " flutter" ))
205+
172206;;;### autoload
173207(defun hover-run (&optional args )
174208 " Execute `hover run` inside Emacs.
@@ -199,6 +233,19 @@ args."
199233 (hover--run-command-on-hover-buffer " R" )
200234 (hover-run)))
201235
236+ ; flutter screenshot --observatory-uri=http://127.0.0.1:50300 --type=rasterizer
237+ ;;;### autoload
238+ (defun hover-take-screenshot ()
239+ " Take screenshot of current `hover` application using `flutter screenshot`.
240+ Saves screenshot on `hover-screenshot-path`."
241+ (interactive )
242+ (let* ((screenshot-path (or (if hover-screenshot-path
243+ (file-name-as-directory hover-screenshot-path))
244+ (hover--project-get-root)))
245+ (file-name (hover--build-screenshot-file-name))
246+ (file-path (concat screenshot-path file-name)))
247+ (hover--take-screenshot file-path hover-observatory-uri)))
248+
202249;;;### autoload
203250(define-derived-mode hover-mode comint-mode " Hover"
204251 " Major mode for `hover-run' ."
0 commit comments