From 253b12e140905d3a38bcd09d55b9c5dbf0601d66 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Wed, 17 Jun 2020 13:17:16 +0200 Subject: [feat] working about dialog --- pkg/backend/bitmask.go | 2 + pkg/backend/status.go | 1 + pkg/config/version/gen.go | 3 -- pkg/config/version/genver/gen.go | 3 ++ pkg/config/version/genver/main.go | 95 +++++++++++++++++++++++++++++++++++++++ pkg/config/version/main.go | 95 --------------------------------------- 6 files changed, 101 insertions(+), 98 deletions(-) delete mode 100644 pkg/config/version/gen.go create mode 100644 pkg/config/version/genver/gen.go create mode 100644 pkg/config/version/genver/main.go delete mode 100644 pkg/config/version/main.go (limited to 'pkg') diff --git a/pkg/backend/bitmask.go b/pkg/backend/bitmask.go index feff115..2b58859 100644 --- a/pkg/backend/bitmask.go +++ b/pkg/backend/bitmask.go @@ -6,6 +6,7 @@ import ( "0xacab.org/leap/bitmask-vpn/pkg/bitmask" "0xacab.org/leap/bitmask-vpn/pkg/config" + "0xacab.org/leap/bitmask-vpn/pkg/config/version" ) func initializeBitmask() { @@ -58,6 +59,7 @@ func initializeContext(provider, appName string) { DonateURL: config.DonateURL, AskForDonations: wantDonations(), DonateDialog: false, + Version: version.VERSION, Status: st, } go trigger(OnStatusChanged) diff --git a/pkg/backend/status.go b/pkg/backend/status.go index 6b13dd3..84b27b7 100644 --- a/pkg/backend/status.go +++ b/pkg/backend/status.go @@ -34,6 +34,7 @@ type connectionCtx struct { AskForDonations bool `json:"askForDonations"` DonateDialog bool `json:"donateDialog"` DonateURL string `json:"donateURL"` + Version string `json:"version"` Status status `json:"status"` bm bitmask.Bitmask cfg *config.Config diff --git a/pkg/config/version/gen.go b/pkg/config/version/gen.go deleted file mode 100644 index 334ed50..0000000 --- a/pkg/config/version/gen.go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -//go:generate go run . -output version.go diff --git a/pkg/config/version/genver/gen.go b/pkg/config/version/genver/gen.go new file mode 100644 index 0000000..e453824 --- /dev/null +++ b/pkg/config/version/genver/gen.go @@ -0,0 +1,3 @@ +package main + +//go:generate go run . -output ../version.go diff --git a/pkg/config/version/genver/main.go b/pkg/config/version/genver/main.go new file mode 100644 index 0000000..e0d80b0 --- /dev/null +++ b/pkg/config/version/genver/main.go @@ -0,0 +1,95 @@ +package main + +import ( + "flag" + "io" + "log" + "os" + "os/exec" + "path/filepath" + "strings" + "text/template" + "time" +) + +var ( + flPackageName = flag.String("package", "version", "name for the generated golang package") + flVariableName = flag.String("variable", "VERSION", "variable name in the generated golang package") + flOutputFile = flag.String("output", "", "output filename (default stdout)") +) + +func main() { + flag.Parse() + dir := "." + if flag.NArg() > 0 { + dir = flag.Args()[0] + } + dir, err := filepath.Abs(dir) + if err != nil { + log.Fatal(err) + } + + var output io.Writer + if len(*flOutputFile) > 0 { + fh, err := os.Create(*flOutputFile) + if err != nil { + log.Fatal(err) + } + defer fh.Close() + output = fh + } else { + output = os.Stdout + } + + vers, err := GitDescribe(dir) + if err != nil { + log.Fatal(err) + } + vp := VersionPackage{ + Name: *flPackageName, + Path: dir, + Date: time.Now(), + Variable: *flVariableName, + Version: vers, + } + + packageTemplate.Execute(output, vp) +} + +// VersionPackage is the needed information to template a version package +type VersionPackage struct { + Name string + Path string + Date time.Time + Variable string + Version string +} + +var packageTemplate = template.Must(template.New("default").Parse(packageLayout)) +var packageLayout = `package {{.Name}} +// AUTO-GENERATED. DO NOT EDIT +// {{.Date}} + +// {{.Variable}} is generated by git-describe from gen.go +var {{.Variable}} = "{{.Version}}" + ` + +// GitDescribe calls `git describe` in the provided path +func GitDescribe(path string) (string, error) { + cwd, err := os.Getwd() + if err != nil { + return "", err + } + // TODO check if this is a directory + if err := os.Chdir(path); err != nil { + return "", err + } + defer os.Chdir(cwd) + + buf, err := exec.Command("git", "describe").CombinedOutput() + if err != nil { + return "", err + } + + return strings.TrimSpace(string(buf)), nil +} diff --git a/pkg/config/version/main.go b/pkg/config/version/main.go deleted file mode 100644 index a86b619..0000000 --- a/pkg/config/version/main.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "flag" - "io" - "log" - "os" - "os/exec" - "path/filepath" - "strings" - "text/template" - "time" -) - -var ( - flPackageName = flag.String("package", "main", "name for the generated golang package") - flVariableName = flag.String("variable", "VERSION", "variable name in the generated golang package") - flOutputFile = flag.String("output", "", "output filename (default stdout)") -) - -func main() { - flag.Parse() - dir := "." - if flag.NArg() > 0 { - dir = flag.Args()[0] - } - dir, err := filepath.Abs(dir) - if err != nil { - log.Fatal(err) - } - - var output io.Writer - if len(*flOutputFile) > 0 { - fh, err := os.Create(*flOutputFile) - if err != nil { - log.Fatal(err) - } - defer fh.Close() - output = fh - } else { - output = os.Stdout - } - - vers, err := GitDescribe(dir) - if err != nil { - log.Fatal(err) - } - vp := VersionPackage{ - Name: *flPackageName, - Path: dir, - Date: time.Now(), - Variable: *flVariableName, - Version: vers, - } - - packageTemplate.Execute(output, vp) -} - -// VersionPackage is the needed information to template a version package -type VersionPackage struct { - Name string - Path string - Date time.Time - Variable string - Version string -} - -var packageTemplate = template.Must(template.New("default").Parse(packageLayout)) -var packageLayout = `package {{.Name}} -// AUTO-GENERATED. DO NOT EDIT -// {{.Date}} - -// {{.Variable}} is generated by git-describe from gen.go -var {{.Variable}} = "{{.Version}}" - ` - -// GitDescribe calls `git describe` in the provided path -func GitDescribe(path string) (string, error) { - cwd, err := os.Getwd() - if err != nil { - return "", err - } - // TODO check if this is a directory - if err := os.Chdir(path); err != nil { - return "", err - } - defer os.Chdir(cwd) - - buf, err := exec.Command("git", "describe").CombinedOutput() - if err != nil { - return "", err - } - - return strings.TrimSpace(string(buf)), nil -} -- cgit v1.2.3