Skip to content

Commit cf1cd54

Browse files
authored
Merge pull request #2 from ericdallo/screenshot-option
Screenshot option
2 parents 5d94d07 + 2d1eb27 commit cf1cd54

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Tests CI
22

33
on:
44
push:
5-
paths-ignore:
6-
- '**/*.md'
7-
- '**/*.org'
85

96
jobs:
107
build:

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ For example you can bind `hover-run-or-hot-reload` to `C-M-z` in dart-mode. Whil
2929
| Variable | Description | Default value |
3030
| ------------------- | ------------------- | ----------------|
3131
| `hover-command-path` | Path to the hover executable command | tries to use `hover` if exists in $PATH |
32-
| `hover-flutter-sdk-path` | Path to flutter sdk path to find flutter executable command | tries to find `flutter` executable in $PATH |
32+
| `hover-flutter-sdk-path` | Path to flutter sdk path to find flutter executable command | tries to find `flutter` executable in $PATH |
3333
| `hover-hot-reload-on-save` | On buffer save, triggers hover hot-reload (if hover is running) | nil |
34+
| `hover-screenshot-path` | If non-nil, save hover screenshot on specified folder. | project root |
35+
| `hover-screenshot-prefix` | Prefix for file name on `hover-take-screenshot`. | hover- |
36+
| `hover-observatory-uri` | Hover custom observatory-uri. | http://127.0.0.1:50300 |
3437

3538
# Example
3639

37-
The following example uses all available configurations above, you can customize as you wish.
40+
The following example uses **all available** configurations above, you can customize as you wish.
3841

3942
```elisp
4043
;; Assuming usage with dart-mode
@@ -47,11 +50,15 @@ The following example uses all available configurations above, you can customize
4750
:after dart-mode
4851
:bind (:map dart-mode-map
4952
("C-M-z" . #'hover-run-or-hot-reload)
50-
("C-M-x" . #'hover-run-or-hot-restart))
53+
("C-M-x" . #'hover-run-or-hot-restart)
54+
("C-M-p" . #'hover-take-screenshot'))
5155
:init
5256
(setq flutter-sdk-path (concat (getenv "HOME") "/flutter") ; remove if `flutter` is already in $PATH
5357
hover-command-path (concat (getenv "GOPATH") "/bin/hover") ; remove if `hover` is already in $PATH
54-
hover-hot-reload-on-save t))
58+
hover-hot-reload-on-save t
59+
hover-screenshot-path (concat (getenv "HOME") "/Pictures"
60+
hover-screenshot-prefix "my-prefix-"
61+
hover-observatory-uri "http://my-custom-host:50300")))
5562
```
5663

5764
_Thanks to [flutter.el](https://github.com/amake/flutter.el) which inspired this project._

hover.el

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@
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

Comments
 (0)