|
349 | 349 | (defn- waiting-to-connect-message [url] |
350 | 350 | (print-str "Waiting for browser to connect to" url "...")) |
351 | 351 |
|
352 | | -(defn- maybe-browse-url [base-url] |
353 | | - (try |
354 | | - (browse/browse-url (str base-url "?rel=" (System/currentTimeMillis))) |
355 | | - (catch Throwable t |
356 | | - (if-some [error-message (not-empty (.getMessage t))] |
357 | | - (println "Failed to launch a browser:\n" error-message "\n") |
358 | | - (println "Could not launch a browser.\n")) |
359 | | - (println "You can instead launch a non-browser REPL (Node or Nashorn).\n") |
360 | | - (println "You can disable automatic browser launch with this REPL option") |
361 | | - (println " :launch-browser false") |
362 | | - (println "and you can specify the listen IP address with this REPL option") |
363 | | - (println " :host \"127.0.0.1\"\n") |
364 | | - (println (waiting-to-connect-message base-url))))) |
365 | | - |
366 | | -(defn setup [{:keys [working-dir launch-browser server-state] :as repl-env} {:keys [output-dir] :as opts}] |
| 352 | +(defn- maybe-browse-url |
| 353 | + ([base-url] |
| 354 | + (maybe-browse-url base-url false)) |
| 355 | + ([base-url new-window] |
| 356 | + (try |
| 357 | + (browse/browse-url |
| 358 | + (cond-> base-url |
| 359 | + new-window (str "?rel=" (System/currentTimeMillis)))) |
| 360 | + (catch Throwable t |
| 361 | + (if-some [error-message (not-empty (.getMessage t))] |
| 362 | + (println "Failed to launch a browser:\n" error-message "\n") |
| 363 | + (println "Could not launch a browser.\n")) |
| 364 | + (println "You can instead launch a non-browser REPL (Node or Nashorn).\n") |
| 365 | + (println "You can disable automatic browser launch with this REPL option") |
| 366 | + (println " :launch-browser false") |
| 367 | + (println "and you can specify the listen IP address with this REPL option") |
| 368 | + (println " :host \"127.0.0.1\"\n") |
| 369 | + (println (waiting-to-connect-message base-url))))) |
| 370 | +) |
| 371 | + |
| 372 | +(defn setup [{:keys [working-dir launch-browser new-window server-state] :as repl-env} {:keys [output-dir] :as opts}] |
367 | 373 | (locking lock |
368 | 374 | (when-not (:socket @server-state) |
369 | 375 | (binding [browser-state (:browser-state repl-env) |
|
391 | 397 | (server/start repl-env) |
392 | 398 | (let [base-url (str "http://" (:host repl-env) ":" (:port repl-env))] |
393 | 399 | (if launch-browser |
394 | | - (maybe-browse-url base-url) |
| 400 | + (maybe-browse-url base-url new-window) |
395 | 401 | (println (waiting-to-connect-message base-url))))))) |
396 | 402 | (.put outs (thread-name) *out*) |
397 | 403 | (swap! server-state update :listeners inc)) |
|
458 | 464 | {:host host |
459 | 465 | :port port |
460 | 466 | :launch-browser true |
| 467 | + :new-window false |
461 | 468 | :working-dir (->> [".repl" (util/clojurescript-version)] |
462 | | - (remove empty?) (string/join "-")) |
| 469 | + (remove empty?) (string/join "-")) |
463 | 470 | :static-dir (cond-> ["." "out/"] output-dir (conj output-dir)) |
464 | 471 | :preloaded-libs [] |
465 | 472 | :src "src/" |
|
0 commit comments