2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2019-2023 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2019-01-12 12:48:28 +00:00
|
|
|
import os, osproc, json
|
|
|
|
|
|
|
|
when defined(windows):
|
|
|
|
const
|
|
|
|
premixExecutable = "premix.exe"
|
|
|
|
browserLauncher = "cmd /c start"
|
|
|
|
elif defined(macos):
|
|
|
|
const
|
|
|
|
premixExecutable = "premix"
|
|
|
|
browserLauncher = "open"
|
|
|
|
else:
|
|
|
|
const
|
|
|
|
premixExecutable = "premix"
|
|
|
|
browserLauncher = "xdg-open"
|
|
|
|
|
2019-01-23 12:59:26 +00:00
|
|
|
proc getFileDir*(file: string): string =
|
|
|
|
var searchDirs = [".", "." / "build", "." / "premix"]
|
2019-01-12 12:48:28 +00:00
|
|
|
|
2019-01-23 12:59:26 +00:00
|
|
|
for dir in searchDirs:
|
|
|
|
if fileExists(dir / file):
|
|
|
|
return dir
|
2019-01-12 12:48:28 +00:00
|
|
|
|
2019-01-23 12:59:26 +00:00
|
|
|
result = ""
|
|
|
|
|
|
|
|
proc getFilePath(file: string): string =
|
|
|
|
let dir = getFileDir(file)
|
|
|
|
if dir.len > 0:
|
|
|
|
return dir / file
|
|
|
|
else:
|
|
|
|
return ""
|
2019-01-12 12:48:28 +00:00
|
|
|
|
|
|
|
proc launchPremix*(fileName: string, metaData: JsonNode) =
|
2019-01-23 12:59:26 +00:00
|
|
|
let premixExe = getFilePath(premixExecutable)
|
2019-01-12 12:48:28 +00:00
|
|
|
|
2019-01-23 12:59:26 +00:00
|
|
|
writeFile(fileName, metaData.pretty)
|
2019-01-12 12:48:28 +00:00
|
|
|
|
2019-01-23 12:59:26 +00:00
|
|
|
if premixExe.len > 0:
|
|
|
|
if execCmd(premixExe & " " & fileName) == 0:
|
|
|
|
if execCmd(browserLauncher & " " & getFilePath("index.html")) != 0:
|
2019-01-12 12:48:28 +00:00
|
|
|
echo "failed to launch default browser"
|
|
|
|
else:
|
2019-01-23 12:59:26 +00:00
|
|
|
echo "failed to execute the premix debugging tool"
|