diff --git a/cmd/editor/main.go b/cmd/editor/main.go index 7c0c828..77bf961 100644 --- a/cmd/editor/main.go +++ b/cmd/editor/main.go @@ -46,12 +46,12 @@ func main() { consoleBuilder := terminal.New(newXTermFunc) taskConsoleBuilder := taskconsole.New() - win, tasks := ide.New(app, editorBuilder, consoleBuilder, taskConsoleBuilder) + win, _ := ide.New(app, editorBuilder, consoleBuilder, taskConsoleBuilder) - if _, err := tasks.Start(goBinaryPath, "go", "version"); err != nil { - log.Error("Failed to start go version: ", err) - return - } + //if _, err := tasks.Start(goBinaryPath, "go", "version"); err != nil { + //log.Error("Failed to start go version: ", err) + //return + //} if err := os.MkdirAll("playground", 0700); err != nil { log.Error("Failed to make playground dir", err) @@ -62,15 +62,17 @@ func main() { return } - _, err := os.Stat("go.mod") - makeNewModule := os.IsNotExist(err) - if makeNewModule { - _, err := tasks.Start(goBinaryPath, "go", "mod", "init", "playground") - if err != nil { - log.Error("Failed to start module init: ", err) - return + /* + _, err := os.Stat("go.mod") + makeNewModule := os.IsNotExist(err) + if makeNewModule { + _, err := tasks.Start(goBinaryPath, "go", "mod", "init", "playground") + if err != nil { + log.Error("Failed to start module init: ", err) + return + } } - } + */ if _, err := os.Stat("main.go"); os.IsNotExist(err) { mainGoContents := `package main @@ -92,17 +94,19 @@ func main() { } } - if makeNewModule { - _, err := tasks.Start(goBinaryPath, "go", "mod", "tidy") - if err != nil { - log.Error("Failed to start go mod tidy: ", err) - return + /* + if makeNewModule { + _, err := tasks.Start(goBinaryPath, "go", "mod", "tidy") + if err != nil { + log.Error("Failed to start go mod tidy: ", err) + return + } } - } + */ - win.NewConsole() + //win.NewConsole() editor := win.NewEditor() - err = editor.OpenFile("main.go") + err := editor.OpenFile("main.go") if err != nil { log.Error("Failed to open main.go in editor: ", err) } diff --git a/internal/js/process/process.go b/internal/js/process/process.go index a8b7baf..acc80b3 100644 --- a/internal/js/process/process.go +++ b/internal/js/process/process.go @@ -95,9 +95,11 @@ func (p *workerProcess) Start() (err error) { message["files"] = true } - log.Warn("Starting process:", message) + log.Print("Starting process:", message) + log.PrintJSValues("kernel start proc message", message) + // TODO is p.kernel definitely the right port? this needs to be received by the kernel, but it's not making it there. in fact, seems like _nothing_ makes it there resp, err := jsworker.DoRequest(context.Background(), p.kernel, js.ValueOf(message), nil) - log.Warn("Process started:", resp, err) + log.Print("Process started:", resp, err) if err != nil { p.startErr = err return err diff --git a/internal/js/process/spawn.go b/internal/js/process/spawn.go index 4d2f9d6..d8a8a25 100644 --- a/internal/js/process/spawn.go +++ b/internal/js/process/spawn.go @@ -7,11 +7,13 @@ import ( "github.com/hack-pad/hackpad/internal/fs" "github.com/hack-pad/hackpad/internal/interop" + "github.com/hack-pad/hackpad/internal/log" "github.com/hack-pad/hackpad/internal/process" "github.com/pkg/errors" ) func spawn(args []js.Value) (interface{}, error) { + log.Warn("spawn call received") if len(args) == 0 { return nil, errors.Errorf("Invalid number of args, expected command name: %v", args) } diff --git a/internal/jsworker/message_port.go b/internal/jsworker/message_port.go index ec18db4..526b218 100644 --- a/internal/jsworker/message_port.go +++ b/internal/jsworker/message_port.go @@ -45,7 +45,12 @@ func wrapMessagePort(v js.Value, source, destination string) (*MessagePort, erro func (p *MessagePort) debug(args ...interface{}) { destination := fmt.Sprintf("(%s->%s) ", p.sourceName, p.destinationName) args = append([]interface{}{destination}, args...) - log.Print(args...) + callers := log.Callers(1, 10) + var groupArgs [][]interface{} + for _, c := range callers { + groupArgs = append(groupArgs, []interface{}{c}) + } + log.PrintGroup(fmt.Sprintln(args...), groupArgs...) } func (p *MessagePort) PostMessage(message js.Value, transfers []js.Value) (err error) { diff --git a/internal/jsworker/request.go b/internal/jsworker/request.go index 2eb4cf9..87c6d6b 100644 --- a/internal/jsworker/request.go +++ b/internal/jsworker/request.go @@ -81,6 +81,7 @@ func DoRequest(ctx context.Context, port *MessagePort, req js.Value, transfers [ id := newID() var resp messageRequest err := port.Listen(ctx, func(ev MessageEvent, err error) { + log.Print("Port Listen DoRequest") message := parseMessageRequest(ev.Data) if message.IsRequest { // only listen for responses, ignore requests return @@ -99,6 +100,7 @@ func DoRequest(ctx context.Context, port *MessagePort, req js.Value, transfers [ return js.Value{}, err } + log.Print("Listening DoRequest") err = port.PostMessage(messageRequest{ ID: id, Data: req, @@ -107,7 +109,9 @@ func DoRequest(ctx context.Context, port *MessagePort, req js.Value, transfers [ if err != nil { return js.Value{}, err } + log.Print("Awaiting response") <-ctx.Done() + log.Print("DoReq response received") if !receivedResponse { resp.Err = ctx.Err() } diff --git a/internal/kernel/op.go b/internal/kernel/op.go index fdb9053..462ad8d 100644 --- a/internal/kernel/op.go +++ b/internal/kernel/op.go @@ -3,7 +3,7 @@ package kernel type Op int const ( - OpStartProcess Op = iota + 1 + OpStartProcess Op = iota + 64 // arbitrarily higher than worker op codes, to help find mistakes OpStartCoprocess OpWaitProcess ) diff --git a/kernel.go b/kernel.go index 262d191..4786d35 100644 --- a/kernel.go +++ b/kernel.go @@ -129,6 +129,8 @@ func newKernelHandler(workers *jsworker.Manager, port *jsworker.MessagePort) jsw } func (k kernelHandler) Handle(req jsworker.RequestData) (response js.Value, transfers []js.Value, responseErr error) { + log.Warn("kernel received message") + panic("how is this not being hit?") if req.Err != nil { log.Error("Received error: ", req.Err) return diff --git a/main.go b/main.go index 850987a..e622aa1 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "syscall/js" "time" + "github.com/hack-pad/hackpad/internal/common" "github.com/hack-pad/hackpad/internal/global" "github.com/hack-pad/hackpad/internal/interop" jsfs "github.com/hack-pad/hackpad/internal/js/fs" @@ -21,7 +22,7 @@ import ( func main() { start := time.Now() - processPort, kernelPort, err := jsworker.NewChannel("kernel", "dom") + processPort, kernelPort, err := jsworker.NewChannel("dom", "kernel") if err != nil { panic(err) } @@ -79,15 +80,26 @@ func main() { } log.Printf("Startup took %.2f seconds", time.Since(start).Seconds()) - go func() { - v, err := jsprocess.Spawn("editor", []string{"editor", "--editor=editor"}, &process.ProcAttr{ - SameWorker: true, - }) - if err != nil { - panic(err) - } - log.PrintJSValues("spawned editor:", v) + //go func() { + //v, err := jsprocess.Spawn("editor", []string{"editor", "--editor=editor"}, &process.ProcAttr{ + //SameWorker: true, + //}) + //if err != nil { + //panic(err) + //} + //log.PrintJSValues("spawned editor:", v) + //}() + + err = func() (err error) { + defer common.CatchException(&err) + js.Global().Get("child_process").Call("spawn", "go") + return nil }() + if err != nil { + log.Error("Failed go command:", err) + panic(err) + } + log.Print("done spawning") select {} } diff --git a/worker_listener.go b/worker_listener.go index 7928b23..a41b0fb 100644 --- a/worker_listener.go +++ b/worker_listener.go @@ -23,6 +23,7 @@ func startWorkerListener(kernelPort *jsworker.MessagePort) error { _ = kernelPort.PostMessage(js.ValueOf("ready"), nil) }, func(req jsworker.RequestData) (response js.Value, transfers []js.Value, responseErr error) { + log.Warn("DOM worker received message") if req.Err != nil { log.Error("Received error: ", req.Err) return js.Value{}, nil, nil @@ -72,7 +73,6 @@ func doRequest(data js.Value) (js.Value, []js.Value, error) { cache := jsBoolProp(data, "cache") for _, mountPath := range mountPaths { - log.Warn("DOM overlaying FSs: ", mountPath) err := overlayIDB(context.Background(), mountPath, 0600, cache) if err != nil { return js.Value{}, nil, err