diff --git a/Taskfile.yml b/Taskfile.yml index 45a43bae4..a7559c2f3 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -346,7 +346,8 @@ tasks: method: timestamp cmds: # Generates both .ico and .icns files - - wails3 generate icons -input appicon.png + # commented out for now + # - wails3 generate icons -input appicon.png install:frontend:deps: summary: Install frontend dependencies diff --git a/build/appicon.png b/build/appicon.png index c40e57904..e6852fb3e 100644 Binary files a/build/appicon.png and b/build/appicon.png differ diff --git a/build/icon.ico b/build/icon.ico new file mode 100644 index 000000000..523704eaa Binary files /dev/null and b/build/icon.ico differ diff --git a/build/icons.icns b/build/icons.icns index 79cd56e67..be5c9df50 100644 Binary files a/build/icons.icns and b/build/icons.icns differ diff --git a/go.mod b/go.mod index 44ac8e0c5..c3487f7a6 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/sawka/txwrap v0.2.0 github.com/wailsapp/wails/v3 v3.0.0-alpha.0 github.com/wavetermdev/waveterm/wavesrv v0.0.0-20240508181017-d07068c09d94 + golang.org/x/sys v0.19.0 ) require ( @@ -55,7 +56,6 @@ require ( golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.21.0 // indirect - golang.org/x/sys v0.19.0 // indirect golang.org/x/tools v0.13.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/main.go b/main.go index 18678152e..202d68bec 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "embed" "log" "net/http" + "runtime" "strings" "github.com/wavetermdev/thenextwave/pkg/blockstore" @@ -24,7 +25,7 @@ import ( //go:embed dist var assets embed.FS -//go:embed build/appicon.png +//go:embed build/icons.icns var appIcon []byte func createAppMenu(app *application.App) *application.Menu { @@ -91,6 +92,12 @@ func main() { log.Printf("error ensuring wave home dir: %v\n", err) return } + waveLock, err := wavebase.AcquireWaveLock() + if err != nil { + log.Printf("error acquiring wave lock (another instance of Wave is likely running): %v\n", err) + return + } + log.Printf("wave home dir: %s\n", wavebase.GetWaveHomeDir()) err = blockstore.InitBlockstore() if err != nil { @@ -129,4 +136,5 @@ func main() { if err != nil { log.Printf("run error: %v\n", err) } + runtime.KeepAlive(waveLock) } diff --git a/pkg/wavebase/wavebase.go b/pkg/wavebase/wavebase.go index 4f5d74b62..5e5bcac25 100644 --- a/pkg/wavebase/wavebase.go +++ b/pkg/wavebase/wavebase.go @@ -12,10 +12,13 @@ import ( "os" "os/exec" "path" + "path/filepath" "runtime" "strings" "sync" "time" + + "golang.org/x/sys/unix" ) const WaveVersion = "v0.1.0" @@ -23,6 +26,7 @@ const DefaultWaveHome = "~/.w2" const WaveHomeVarName = "WAVETERM_HOME" const WaveDevVarName = "WAVETERM_DEV" const HomeVarName = "HOME" +const WaveLockFile = "waveterm.lock" var baseLock = &sync.Mutex{} var ensureDirCache = map[string]bool{} @@ -137,3 +141,19 @@ func DetermineLang() string { }) return osLang } + +func AcquireWaveLock() (*os.File, error) { + homeDir := GetWaveHomeDir() + lockFileName := filepath.Join(homeDir, WaveLockFile) + log.Printf("[base] acquiring lock on %s\n", lockFileName) + fd, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0600) + if err != nil { + return nil, err + } + err = unix.Flock(int(fd.Fd()), unix.LOCK_EX|unix.LOCK_NB) + if err != nil { + fd.Close() + return nil, err + } + return fd, nil +}