Skip to content

Commit

Permalink
Add operator BrowserOpenURL
Browse files Browse the repository at this point in the history
  • Loading branch information
jm9e committed May 25, 2019
1 parent 982b73e commit 93cc4f4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/elem/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func init() {
Register("slang.image.Encode", imageEncodeCfg)

Register("slang.system.Execute", systemExecuteCfg)
Register("slang.system.BrowserOpenURL", systemBrowserOpenURLCfg)

windowStores = make(map[string]*windowStore)
windowMutex = &sync.Mutex{}
Expand Down
54 changes: 54 additions & 0 deletions pkg/elem/system_browser_open_url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package elem

import (
"github.com/Bitspark/browser"
"github.com/Bitspark/slang/pkg/core"
)

var systemBrowserOpenURLCfg = &builtinConfig{
opDef: core.OperatorDef{
ServiceDefs: map[string]*core.ServiceDef{
core.MAIN_SERVICE: {
In: core.TypeDef{
Type: "map",
Map: map[string]*core.TypeDef{
"url": {
Type: "string",
},
},
},
Out: core.TypeDef{
Type: "map",
Map: map[string]*core.TypeDef{
"err": {
Type: "string",
},
},
},
},
},
},
opFunc: func(op *core.Operator) {
in := op.Main().In()
out := op.Main().Out()

for !op.CheckStop() {
i := in.Pull()
if core.IsMarker(i) || i == nil {
out.Push(i)
continue
}

im := i.(map[string]interface{})
path := im["url"].(string)

err := browser.OpenURL(path)

if err != nil {
out.Push(err.Error())
} else {
out.Push(nil)
}
}
},
}

0 comments on commit 93cc4f4

Please sign in to comment.