From d54bcb80e64fe57eb9b50bab22820a60f525e3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcial=20Gai=C3=9Fert?= Date: Tue, 28 May 2024 12:43:12 +0200 Subject: [PATCH] js-web: Also open web page in browser (linux/mac only) --- effekt/jvm/src/main/scala/effekt/Runner.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/effekt/jvm/src/main/scala/effekt/Runner.scala b/effekt/jvm/src/main/scala/effekt/Runner.scala index 7bdefdd7e..a8383fcbe 100644 --- a/effekt/jvm/src/main/scala/effekt/Runner.scala +++ b/effekt/jvm/src/main/scala/effekt/Runner.scala @@ -145,7 +145,7 @@ object JSWebRunner extends Runner[String] { /** * Creates an openable `.html` file besides the given `.js` file ([[path]]) - * and then returns the absolute path of the created executable. + * and then returns the absolute path of a shell script opening it. */ def build(path: String)(using C: Context): String = import java.nio.file.Path @@ -153,6 +153,7 @@ object JSWebRunner extends Runner[String] { val jsFilePath = (out / path).unixPath val jsFileName = jsFilePath.split("/").last val htmlFilePath = jsFilePath.stripSuffix(s".$extension") + ".html" + val shFilePath = jsFilePath.stripSuffix(s".$extension") val mainName = "$" + jsFileName.stripSuffix(".js") + ".main" val htmlContent = s""" @@ -166,7 +167,10 @@ object JSWebRunner extends Runner[String] { | |""".stripMargin IO.createFile(htmlFilePath, htmlContent, false) - htmlFilePath + IO.createFile(shFilePath, + s"#!/bin/sh\nxdg-open ${htmlFilePath} || open ${htmlFilePath} || echo \"Cannot open browser\"", + true) + shFilePath } trait ChezRunner extends Runner[String] {