Skip to content

Commit

Permalink
shell: add static option to avoid livereloading (for debugging)
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Mar 7, 2024
1 parent 77804d6 commit 75d2bc2
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions shell/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
var openWatchResp js.Value = js.Null()

func openCmd() *cli.Command {
var static bool

cmd := &cli.Command{
Usage: "open <appname>",
Usage: "open [-static] <appname>",
Args: cli.ExactArgs(1),
Run: func(ctx *cli.Context, args []string) {
var path string
Expand All @@ -33,37 +35,40 @@ func openCmd() *cli.Command {
return
}

if !openWatchResp.IsNull() {
// close rpc channel
jsutil.Await(openWatchResp.Call("send", 0))
}
if !static {
if !openWatchResp.IsNull() {
// close rpc channel
jsutil.Await(openWatchResp.Call("send", 0))
}

var err error
var err error

// watch(path, recursive, eventMask, ignores)
openWatchResp, err = jsutil.WanixSyscallResp("fs.watch", path, true, 0, []any{})
if err != nil {
fmt.Fprintln(ctx, err)
return
}
// watch(path, recursive, eventMask, ignores)
openWatchResp, err = jsutil.WanixSyscallResp("fs.watch", path, true, 0, []any{})
if err != nil {
fmt.Fprintln(ctx, err)
return
}

go func() {
for {
event := jsutil.Await(openWatchResp.Call("receive"))
if event.IsNull() {
return
}
go func() {
for {
event := jsutil.Await(openWatchResp.Call("receive"))
if event.IsNull() {
return
}

if watchfs.EventType(event.Get("type").Int()) == watchfs.EventWrite && len(event.Get("path").String()) > len(path) {
// loadApp(target, path, focus)
jsutil.WanixSyscall("host.loadApp", "main", path, true)
if watchfs.EventType(event.Get("type").Int()) == watchfs.EventWrite && len(event.Get("path").String()) > len(path) {
// loadApp(target, path, focus)
jsutil.WanixSyscall("host.loadApp", "main", path, true)
}
}
}
}()
}()
}

// loadApp(target, path, focus)
jsutil.WanixSyscall("host.loadApp", "main", path, true)
},
}
cmd.Flags().BoolVar(&static, "static", false, "open without live reloading")
return cmd
}

0 comments on commit 75d2bc2

Please sign in to comment.