diff --git a/shell/open.go b/shell/open.go index 70b2bcb..a81e6d4 100644 --- a/shell/open.go +++ b/shell/open.go @@ -15,8 +15,10 @@ import ( var openWatchResp js.Value = js.Null() func openCmd() *cli.Command { + var static bool + cmd := &cli.Command{ - Usage: "open ", + Usage: "open [-static] ", Args: cli.ExactArgs(1), Run: func(ctx *cli.Context, args []string) { var path string @@ -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 }