2020-10-29 08:50:25 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-10-29 16:52:31 +02:00
|
|
|
"context"
|
2021-02-10 01:46:49 +02:00
|
|
|
"fmt"
|
2020-10-29 08:50:25 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2021-04-01 12:14:49 +02:00
|
|
|
"path/filepath"
|
2020-10-29 08:50:25 +02:00
|
|
|
"strconv"
|
|
|
|
|
2021-02-10 01:46:49 +02:00
|
|
|
"github.com/google/uuid"
|
2020-10-29 08:50:25 +02:00
|
|
|
"github.com/webview/webview"
|
|
|
|
)
|
|
|
|
|
2021-02-10 01:46:49 +02:00
|
|
|
var sessionToken string = "su-" + uuid.New().String()
|
|
|
|
|
2021-01-26 20:52:42 +02:00
|
|
|
func runServer(ctx context.Context) {
|
2021-04-13 20:20:21 +02:00
|
|
|
executable, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Failed to get os.Executable()")
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
serverExecutable := filepath.Join(filepath.Dir(executable), "focalboard-server")
|
|
|
|
|
2021-04-01 12:14:49 +02:00
|
|
|
cmd := exec.CommandContext(ctx, serverExecutable, "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10), "-single-user")
|
2021-02-11 20:13:17 +02:00
|
|
|
cmd.Env = []string{fmt.Sprintf("FOCALBOARD_SINGLE_USER_TOKEN=%s", sessionToken)}
|
2020-10-29 08:50:25 +02:00
|
|
|
cmd.Stdout = os.Stdout
|
2021-04-13 20:20:21 +02:00
|
|
|
err = cmd.Run()
|
2020-10-29 08:50:25 +02:00
|
|
|
if err != nil {
|
2021-02-11 20:13:17 +02:00
|
|
|
log.Println("Failed to start server")
|
2020-10-29 08:50:25 +02:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
log.Printf("Just ran subprocess %d, exiting\n", cmd.Process.Pid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
debug := true
|
|
|
|
w := webview.New(debug)
|
|
|
|
defer w.Destroy()
|
2020-10-29 16:52:31 +02:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
2021-01-26 20:52:42 +02:00
|
|
|
go runServer(ctx)
|
2020-10-29 08:50:25 +02:00
|
|
|
|
2021-01-26 20:52:42 +02:00
|
|
|
w.SetTitle("Focalboard")
|
2020-10-29 08:50:25 +02:00
|
|
|
w.SetSize(1024, 768, webview.HintNone)
|
2021-02-10 01:46:49 +02:00
|
|
|
|
2021-04-16 13:42:37 +02:00
|
|
|
script := fmt.Sprintf("localStorage.setItem('focalboardSessionId', '%s');", sessionToken)
|
2021-02-10 01:46:49 +02:00
|
|
|
w.Init(script)
|
|
|
|
|
2021-01-21 00:09:41 +02:00
|
|
|
w.Navigate("http://localhost:8088")
|
2020-10-29 08:50:25 +02:00
|
|
|
w.Run()
|
2020-10-29 16:52:31 +02:00
|
|
|
cancel()
|
2020-10-29 08:50:25 +02:00
|
|
|
}
|