diff --git a/Makefile b/Makefile index 9f4e3df83..8c496db8e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: prebuild clean cleanall server server-linux generate watch-server mac linux-app +.PHONY: prebuild clean cleanall server server-linux server-win64 generate watch-server webapp mac app linux-app all: server @@ -8,6 +8,7 @@ prebuild: go get github.com/spf13/viper go get github.com/lib/pq go get github.com/mattn/go-sqlite3 + cd webapp; npm install server: cd server; go build -o ../bin/octoserver ./main @@ -15,6 +16,9 @@ server: server-linux: cd server; env GOOS=linux GOARCH=amd64 go build -o ../bin/octoserver ./main +server-win64: + cd server; env GOOS=windows GOARCH=amd64 go build -o ../bin/octoserver.exe ./main + generate: cd server; go get -modfile=go.tools.mod github.com/golang/mock/mockgen cd server; go get -modfile=go.tools.mod github.com/jteeuwen/go-bindata @@ -49,6 +53,14 @@ mac: xcodebuild archive -workspace mac/Tasks.xcworkspace -scheme Tasks -archivePath mac/temp/tasks.xcarchive xcodebuild -exportArchive -archivePath mac/temp/tasks.xcarchive -exportPath mac/dist -exportOptionsPlist mac/export.plist +win: server-win64 webapp + cd win; make build + cp -R bin/octoserver.exe win/dist + cp -R config.json win/dist + mkdir -p win/dist/webapp + cp -R webapp/pack win/dist/webapp/pack + # cd win/dist; zip -r ../tasks-win.zip . + linux-app: server-linux webapp rm -rf linux/temp mkdir -p linux/temp/octo-linux-app/webapp diff --git a/win/Makefile b/win/Makefile new file mode 100644 index 000000000..f0bcd48ca --- /dev/null +++ b/win/Makefile @@ -0,0 +1,10 @@ +.PHONY: run build + +run: + go run ./main.go + +build: + mkdir -p dist + # env GOOS=windows GOARCH=amd64 go build -ldflags="-H windowsgui" -o dist/tasks-win.exe + # env GOOS=windows GOARCH=amd64 go build -ldflags -H=windowsgui -o dist/tasks-win.exe + env GOOS=windows GOARCH=amd64 go build -o dist/tasks-win.exe diff --git a/win/go.mod b/win/go.mod new file mode 100644 index 000000000..fd803680f --- /dev/null +++ b/win/go.mod @@ -0,0 +1,8 @@ +module github.com/mattermost/mattermost-octo-tasks/linux + +go 1.15 + +require ( + github.com/gonutz/w32 v1.0.0 + github.com/zserge/lorca v0.1.9 +) diff --git a/win/go.sum b/win/go.sum new file mode 100644 index 000000000..005734b98 --- /dev/null +++ b/win/go.sum @@ -0,0 +1,9 @@ +github.com/gonutz/w32 v1.0.0 h1:3t1z6ZfkFvirjFYBx9pHeHBuKoN/VBVk9yHb/m2Ll/k= +github.com/gonutz/w32 v1.0.0/go.mod h1:Rc/YP5K9gv0FW4p6X9qL3E7Y56lfMflEol1fLElfMW4= +github.com/zserge/lorca v0.1.9 h1:vbDdkqdp2/rmeg8GlyCewY2X8Z+b0s7BqWyIQL/gakc= +github.com/zserge/lorca v0.1.9/go.mod h1:bVmnIbIRlOcoV285KIRSe4bUABKi7R7384Ycuum6e4A= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/win/main.go b/win/main.go new file mode 100644 index 000000000..7ff012567 --- /dev/null +++ b/win/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "context" + "log" + "os" + "os/exec" + + "github.com/gonutz/w32" + "github.com/zserge/lorca" +) + +func runOctoTasks(ctx context.Context) *exec.Cmd { + // cmd := exec.CommandContext(ctx, "octoserver.exe", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10)) + cmd := exec.CommandContext(ctx, "octoserver.exe") + // cmd := exec.CommandContext(ctx, "cmd.exe", "/C", "start", "./octoserver.exe", "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10)) + // cmd := exec.CommandContext(ctx, "cmd.exe", "/C", "start", "./octoserver.exe") + + // cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + cmd.Stdout = os.Stdout + go func() { + err := cmd.Run() + if err != nil { + log.Fatal(err) + } + log.Printf("Just ran subprocess %d, exiting\n", cmd.Process.Pid) + }() + + return cmd +} + +func main() { + // log.Printf("PID: %s", strconv.FormatInt(int64(os.Getpid()), 10)) + hideConsole() + + ctx, cancel := context.WithCancel(context.Background()) + cmd := runOctoTasks(ctx) + + ui, err := lorca.New("http://localhost:8000", "", 1024, 768) + if err != nil { + log.Fatal(err) + } + // defer ui.Close() + + log.Printf("Started") + <-ui.Done() + + log.Printf("App Closed") + cancel() + if err := cmd.Process.Kill(); err != nil { + log.Fatal("failed to kill process: ", err) + } +} + +func hideConsole() { + console := w32.GetConsoleWindow() + if console != 0 { + _, consoleProcID := w32.GetWindowThreadProcessId(console) + if w32.GetCurrentProcessId() == consoleProcID { + w32.ShowWindowAsync(console, w32.SW_HIDE) + } + } +}