Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilsen84 committed Jan 20, 2023
1 parent 0ece1e8 commit afd81de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
4 changes: 2 additions & 2 deletions chrome_debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func StartProcessAndConnectDebugger(program string) (*ChromeDebugger, *exec.Cmd,
}

func ConnectDebugger(port int) (*ChromeDebugger, error) {
url, err := getWebsocketUrl(port)
url, err := GetWebsocketDebuggerUrl(port)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +64,7 @@ func ConnectDebugger(port int) (*ChromeDebugger, error) {
}, nil
}

func getWebsocketUrl(port int) (string, error) {
func GetWebsocketDebuggerUrl(port int) (string, error) {
var url string

err := retry.Do(
Expand Down
56 changes: 25 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func GetLunarExecutable() (string, error) {
} else {
switch runtime.GOOS {
case "windows":
var home, err = os.UserHomeDir()
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
Expand All @@ -38,54 +38,48 @@ func GetLunarExecutable() (string, error) {
return "", fmt.Errorf("'%s' does not exist", exe)
}

func GetExecutableDirectory() (string, error) {
ex, err := os.Executable()
if err != nil {
return "", err
}

return filepath.Dir(ex), nil
}

//go:embed inject.js
var injectJs string

func main() {
log.SetFlags(0)

func Run() (err error) {
lunarExe, err := GetLunarExecutable()
if err != nil {
log.Println(err)
log.Fatalln("failed to locate the lunar launcher executable, try passing it by argument")
return fmt.Errorf("%w\nfailed to locate the lunar launcher executable, try passing it by argument", err)
}

d, cmd, err := StartProcessAndConnectDebugger(lunarExe)
if cmd != nil {
defer func() {
if err != nil {
_ = cmd.Process.Kill()
}
}()
}
if err != nil {
if cmd != nil {
_ = cmd.Process.Kill()
}

log.Fatalln(err)
return
}
defer d.Close()
dir, err := GetExecutableDirectory()

ex, err := os.Executable()
if err != nil {
_ = cmd.Process.Kill()
log.Fatalln(err)
return
}

err = d.Send("Runtime.callFunctionOn", map[string]any{
return d.Send("Runtime.callFunctionOn", map[string]any{
"executionContextId": 1,
"functionDeclaration": injectJs,
"arguments": []any{
map[string]any{
"value": dir,
"value": filepath.Dir(ex),
},
},
"executionContextId": 1,
})
}

if err != nil {
_ = cmd.Process.Kill()
func main() {
log.SetFlags(0)

if err := Run(); err != nil {
log.Fatalln(err)
}
}

//go:embed inject.js
var injectJs string

0 comments on commit afd81de

Please sign in to comment.