-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
indium-chrome.el
100 lines (78 loc) · 3.3 KB
/
indium-chrome.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; indium-chrome.el --- Chrom{e|ium} support for indium -*- lexical-binding: t; -*-
;; Copyright (C) 2016-2018 Nicolas Petton
;; Author: Nicolas Petton <[email protected]>
;; Keywords: tools, javascript
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Handle indium connections to Chrom{e|ium} using the v8 backend.
;;; Code:
(require 'url)
(require 'json)
(require 'map)
(require 'seq)
(declare-function indium-client-connect "indium-client.el")
(defgroup indium-chrome nil
"Chrome interaction."
:prefix "indium-chrome-"
:group 'indium)
(defun indium-chrome--default-executable ()
"Return a default executable based on the OS."
(cond ((string-equal system-type "darwin")
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
((string-equal system-type "windows-nt")
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")
(t "chromium")))
(defcustom indium-chrome-executable
(indium-chrome--default-executable)
"Chrome executable."
:type '(file))
(defcustom indium-chrome-default-port
9222
"Default Chrome remote debugger port."
:type '(integer))
(defcustom indium-chrome-use-temporary-profile
t
"When non-nil, each invocation of the browser uses a temporary profile.
The temporary profile can be set with `indium-chrome-data-dir'."
:type '(boolean))
(defvar indium-chrome--default-data-dir (expand-file-name "indium-chrome-profile"
user-emacs-directory)
"Default directory used as Chrome data directory.")
(defvar indium-chrome-data-dir
(make-directory indium-chrome--default-data-dir t)
"Chrome profile directory used by Indium.")
(defun indium-launch-chrome (conf)
"Start chrome/chromium with remote debugging enabled based on CONF settings."
(let-alist conf
(unless .url
(error "No url specified in configuration"))
(make-process :name "indium-chrome-process"
:command (indium-chrome--command
(or .port indium-chrome-default-port)
.url))
(indium-client-connect (file-name-directory .projectFile) .name)))
(defun indium-chrome--command (port url)
"Return the Chrome command to be executed with PORT and URL."
(list (indium-chrome--find-executable)
(format "--remote-debugging-port=%s" port)
(if indium-chrome-use-temporary-profile
(format "--user-data-dir=%s" indium-chrome-data-dir)
"")
url))
(defun indium-chrome--find-executable ()
"Find chrome executable using `indium-chrome-executable'."
(let ((executable (executable-find indium-chrome-executable)))
(unless executable
(user-error "Cannot find chrome/chromium binary (%s) in PATH" indium-chrome-executable))
executable))
(provide 'indium-chrome)
;;; indium-chrome.el ends here