1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-30 08:36:54 +02:00
focalboard/linux/main.go

55 lines
1.2 KiB
Go
Raw Normal View History

2020-10-29 08:50:25 +02:00
package main
import (
"context"
2021-02-10 01:46:49 +02:00
"fmt"
2020-10-29 08:50:25 +02:00
"log"
"os"
"os/exec"
"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")
cmd := exec.CommandContext(ctx, serverExecutable, "--monitorpid", strconv.FormatInt(int64(os.Getpid()), 10), "-single-user")
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 {
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()
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
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()
cancel()
2020-10-29 08:50:25 +02:00
}