From 20a5cf4c08491aa49ecc385c643237d8adec5a9c Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Fri, 17 Apr 2020 01:30:36 +0530 Subject: [PATCH] Kelp UI: Fix basepath and use pingURL to ping server in tailFile before redirect (#404) * 1 - show error hint if base unix and native paths are different * 2 - catch cycles in initialization of kelpos.go * 3 - fix instance of calling String() on an OSPath * 4 - incorporate pingURL into tailFileHTML * 5 - keep debug mode for electron enabled * 6 - add check for kelp server to be run from root kelp directory in local mode * 7 - always execute commands from the working directory * 8 - use only binary directory as basepth in both native and unix formats, eliminating ambiguity * 9 - working directory command to OS should be specified in Native form * 10 - fix getBinaryDirectoryUnix by invoking toUnixFilepath before returning * 11 - kelpBinPath -> kelpBinName * 12 - added comments related to fix of using kelp binary name instead of absolute path --- cmd/server_amd64.go | 27 ++++- gui/backend/api_server.go | 21 +++- gui/backend/start_bot.go | 3 + .../fs_bin_gen/gui/filesystem_vfsdata_dev.go | 4 +- support/kelpos/kelpos.go | 19 +++- support/kelpos/ospath.go | 55 ++++++++-- support/kelpos/ospath_test.go | 102 ++++++++++++++++-- support/kelpos/process.go | 5 +- 8 files changed, 204 insertions(+), 32 deletions(-) diff --git a/cmd/server_amd64.go b/cmd/server_amd64.go index e3b4a6fc1..41ff59f3b 100644 --- a/cmd/server_amd64.go +++ b/cmd/server_amd64.go @@ -35,6 +35,7 @@ import ( "github.com/stellar/kelp/support/networking" "github.com/stellar/kelp/support/prefs" "github.com/stellar/kelp/support/sdk" + "github.com/stellar/kelp/support/utils" ) const kelpPrefsDirectory = ".kelp" @@ -89,6 +90,17 @@ func init() { isLocalMode := env == envDev isLocalDevMode := isLocalMode && *options.dev kos := kelpos.GetKelpOS() + if isLocalMode { + wd, e := os.Getwd() + if e != nil { + panic(errors.Wrap(e, "could not get working directory")) + } + if filepath.Base(wd) != "kelp" { + e := fmt.Errorf("need to invoke from the root 'kelp' directory") + utils.PrintErrorHintf(e.Error()) + panic(e) + } + } var logFilepath *kelpos.OSPath if !isLocalDevMode { @@ -517,7 +529,7 @@ func openElectron(trayIconPath *kelpos.OSPath, url string) { AppIconDefaultPath: "resources/kelp-icon@2x.png", AcceptTCPTimeout: time.Minute * 2, }, - Debug: false, + Debug: true, Windows: []*bootstrap.Window{&bootstrap.Window{ Homepage: url, Options: &astilectron.WindowOptions{ @@ -697,10 +709,21 @@ const tailFileHTML = `