Minor Improvements

* Made Refresh() more robust - when an error is encountered, the layer(set) is reloaded automatically.
* JS errors are now output to console instead of alerts.
This commit is contained in:
Unknown
2018-04-04 15:14:59 -04:00
parent d52e896ac3
commit 4bf7eca6b0
5 changed files with 42 additions and 36 deletions

20
ps.go
View File

@@ -73,10 +73,10 @@ func SaveAs(path string) error {
func DoJs(path string, args ...string) (out []byte, err error) {
// Temp file for js to output to.
outpath := filepath.Join(os.Getenv("TEMP"), "js_out.txt")
defer os.Remove(outpath)
if !strings.HasSuffix(path, ".jsx") {
path += ".jsx"
}
defer os.Remove(outpath)
args = append([]string{outpath}, args...)
@@ -87,14 +87,12 @@ func DoJs(path string, args ...string) (out []byte, err error) {
args = append([]string{path}, args...)
cmd, err := run("dojs", args...)
if err != nil {
return []byte{}, err
if err == nil {
file, err := ioutil.ReadFile(outpath)
if err == nil {
cmd = append(cmd, file...)
}
}
file, err := ioutil.ReadFile(outpath)
if err != nil {
return cmd, err
}
cmd = append(cmd, file...)
return cmd, err
}
@@ -138,11 +136,7 @@ func run(name string, args ...string) ([]byte, error) {
cmd.Stdout = &out
cmd.Stderr = &errs
err := cmd.Run()
if err != nil {
return out.Bytes(), err
// return append(out.Bytes(), errs.Bytes()...), err
}
if len(errs.Bytes()) != 0 {
if err != nil || len(errs.Bytes()) != 0 {
return out.Bytes(), errors.New(string(errs.Bytes()))
}
return out.Bytes(), nil