Skip to content

Commit

Permalink
fix for mac + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilsen84 committed Feb 6, 2023
1 parent afd81de commit 5e7d36a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@ on:

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
strategy:
matrix:
platform: [
{ runner: windows-latest, exe: lunar-launcher-inject-windows.exe },
{ runner: macos-latest, exe: lunar-launcher-inject-mac },
{ runner: ubuntu-latest, exe: lunar-launcher-inject-linux }
]
runs-on: ${{ matrix.platform.runner }}
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: '1.20'

- name: Build
run: |
mkdir build && cd build
for target in windows,-windows.exe darwin,-macos linux,-linux
do
IFS=, read -r os suffix <<< ${target}
GOOS=${os} GOARCH=amd64 go build -v -o lunar-launcher-inject${suffix} ..
done
run: GOARCH=amd64 go build -v -o ${{ matrix.platform.exe }} -ldflags "-s -w"

- name: Upload Artifacts
run: gh release upload ${GITHUB_REF_NAME} build/*
- name: Upload Executable
run: gh release upload ${GITHUB_REF_NAME} ${{ matrix.platform.exe }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion chrome_debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func GetWebsocketDebuggerUrl(port int) (string, error) {
if err != nil {
return err
}

defer r.Body.Close()

body, err := io.ReadAll(r.Body)
Expand Down
30 changes: 16 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
_ "embed"
"errors"
"fmt"
"log"
"os"
Expand All @@ -22,7 +23,7 @@ func GetLunarExecutable() (string, error) {
return "", err
}
exe = home + `\AppData\Local\Programs\lunarclient\Lunar Client.exe`
case "macos":
case "darwin":
exe = "/Applications/Lunar Client.app/Contents/MacOS/Lunar Client"
case "linux":
exe = "/usr/bin/lunarclient"
Expand All @@ -31,35 +32,36 @@ func GetLunarExecutable() (string, error) {
}
}

if _, err := os.Stat(exe); err == nil {
return exe, nil
if _, err := os.Stat(exe); errors.Is(err, os.ErrNotExist) {
return "", fmt.Errorf("'%s' does not exist", exe)
}

return "", fmt.Errorf("'%s' does not exist", exe)
return exe, nil
}

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

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

ex, err := os.Executable()
if err != nil {
return
return err
}

return d.Send("Runtime.callFunctionOn", map[string]any{
Expand Down

0 comments on commit 5e7d36a

Please sign in to comment.