refactor: use go workspace for syncthing gui (#549)

This commit is contained in:
naison
2025-04-19 12:09:06 +08:00
committed by GitHub
parent c9f1ce6522
commit 48e30b4344
15 changed files with 2072 additions and 142 deletions

View File

@@ -43,6 +43,14 @@ func init() {
if err != nil {
panic(err)
}
err = os.MkdirAll(GetSyncthingPath(), 0755)
if err != nil {
panic(err)
}
err = os.Chmod(GetSyncthingPath(), 0755)
if err != nil {
panic(err)
}
path := filepath.Join(HomePath, ConfigFile)
_, err = os.Stat(path)
@@ -74,10 +82,6 @@ func GetSyncthingPath() string {
return filepath.Join(DaemonPath, SyncthingDir)
}
func GetSyncthingGUIPath() string {
return filepath.Join(DaemonPath, SyncthingDir, SyncthingGUIDir)
}
func GetConfigFilePath() string {
return filepath.Join(HomePath, ConfigFile)
}

View File

@@ -9,8 +9,6 @@ import (
const (
SyncthingDir = "syncthing"
SyncthingGUIDir = "gui"
DefaultRemoteDir = "/kubevpn-data"
// EnvDisableSyncthingLog disable syncthing log, because it can not set output writer, only write os.Stdout or io.Discard

View File

@@ -0,0 +1,3 @@
module github.com/syncthing/syncthing/lib/api/auto
go 1.23.2

View File

File diff suppressed because one or more lines are too long

View File

@@ -1,72 +0,0 @@
package syncthing
import (
"archive/zip"
"bytes"
"embed"
"io"
"os"
"path/filepath"
"github.com/wencaiwulue/kubevpn/v2/pkg/config"
)
//go:embed gui.zip
var assetsZip embed.FS
func MakeSureGui() error {
return ExtractSyncthingGUIZipToDir(assetsZip, "gui.zip", config.GetSyncthingPath())
}
func ExtractSyncthingGUIZipToDir(fs embed.FS, zipPath, targetDir string) error {
zipData, err := fs.Open(zipPath)
if err != nil {
return err
}
defer zipData.Close()
all, err := io.ReadAll(zipData)
if err != nil {
return err
}
zipReader, err := zip.NewReader(bytes.NewReader(all), int64(len(all)))
if err != nil {
return err
}
for _, file := range zipReader.File {
filePath := filepath.Join(targetDir, file.Name)
if file.FileInfo().IsDir() {
if err = os.MkdirAll(filePath, file.Mode()); err != nil {
return err
}
continue
}
if err = os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
return err
}
var fileWriter *os.File
fileWriter, err = os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
if err != nil {
return err
}
var fileReader io.ReadCloser
fileReader, err = file.Open()
if err != nil {
_ = fileWriter.Close()
return err
}
_, err = io.Copy(fileWriter, fileReader)
_ = fileReader.Close()
_ = fileWriter.Close()
if err != nil {
return err
}
}
return nil
}

Binary file not shown.

View File

@@ -10,7 +10,6 @@ import (
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/db/backend"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/locations"
"github.com/syncthing/syncthing/lib/logger"
"github.com/syncthing/syncthing/lib/netutil"
"github.com/syncthing/syncthing/lib/svcutil"
@@ -34,17 +33,10 @@ var (
)
func StartClient(ctx context.Context, localDir string, localAddr, remoteAddr string) error {
if err := MakeSureGui(); err != nil {
return err
}
err := cmdutil.SetConfigDataLocationsFromFlags(pkgconfig.GetSyncthingPath(), "", "")
if err != nil {
return err
}
err = locations.Set(locations.GUIAssets, pkgconfig.GetSyncthingGUIPath())
if err != nil {
return err
}
var l = logger.New().NewFacility("main", "Main package")
spec := svcutil.SpecWithDebugLogger(l)
earlyService := suture.New("early", spec)
@@ -134,18 +126,10 @@ func StartClient(ctx context.Context, localDir string, localAddr, remoteAddr str
}
func StartServer(ctx context.Context, detach bool, remoteDir string) error {
if err := MakeSureGui(); err != nil {
return err
}
err := cmdutil.SetConfigDataLocationsFromFlags(pkgconfig.GetSyncthingPath(), "", "")
if err != nil {
return err
}
err = locations.Set(locations.GUIAssets, pkgconfig.GetSyncthingGUIPath())
if err != nil {
return err
}
spec := svcutil.SpecWithDebugLogger(logger.New().NewFacility("", ""))
earlyService := suture.New("early", spec)
earlyService.ServeBackground(ctx)