Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single instance lock reset on macOS #3526

Merged
merged 4 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion v2/internal/frontend/desktop/darwin/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"log"
"net"
"net/url"
"os"
"unsafe"

"github.com/wailsapp/wails/v2/pkg/assetserver"
Expand Down Expand Up @@ -55,6 +56,9 @@ type Frontend struct {
debug bool
devtoolsEnabled bool

// Keep single instance lock file, so that it will not be GC and lock will exist while app is running
singleInstanceLockFile *os.File

// Assets
assets *assetserver.AssetServer
startURL *url.URL
Expand Down Expand Up @@ -186,7 +190,7 @@ func (f *Frontend) Run(ctx context.Context) error {
f.ctx = ctx

if f.frontendOptions.SingleInstanceLock != nil {
SetupSingleInstance(f.frontendOptions.SingleInstanceLock.UniqueId)
f.singleInstanceLockFile = SetupSingleInstance(f.frontendOptions.SingleInstanceLock.UniqueId)
}

_debug := ctx.Value("debug")
Expand Down
10 changes: 6 additions & 4 deletions v2/internal/frontend/desktop/darwin/single_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/wailsapp/wails/v2/pkg/options"
)

func SetupSingleInstance(uniqueID string) {
func SetupSingleInstance(uniqueID string) *os.File {
lockFilePath := getTempDir()
lockFileName := uniqueID + ".lock"
_, err := createLockFile(lockFilePath + "/" + lockFileName)
file, err := createLockFile(lockFilePath + "/" + lockFileName)
// if lockFile exist – send notification to second instance
if err != nil {
c := NewCalloc()
Expand All @@ -34,18 +34,20 @@ func SetupSingleInstance(uniqueID string) {

data, err := options.NewSecondInstanceData()
if err != nil {
return
return nil
}

serialized, err := json.Marshal(data)
if err != nil {
return
return nil
}

C.SendDataToFirstInstance(singleInstanceUniqueId, c.String(string(serialized)))

os.Exit(0)
}

return file
}

//export HandleSecondInstanceData
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed optional type generation where an extra `?` would be placed inside the field name instead of outside the name `"field?"?` vs `"field"?`. Fixed by [@atterpac](https://github.com/atterpac) in [#3476](https://github.com/wailsapp/wails/pull/3476)
- Fixed an issue where `WindowGetPosition` and `WindowSetPosition` values were inconsistent on MacOS. Fixed by [@cenan](https://github.com/wailsapp/wails/pull/3479)
- Fix scoop command usage typo. Fixed by [@fieu](https://github.com/fieu) in [#3501](https://github.com/wailsapp/wails/pull/3501)
- Fixed macOS single instance lock reset after some time. Fixed by [@APshenkin](https://github.com/APshenkin) in [PR](https://github.com/wailsapp/wails/pull/3526)

## v2.8.2 - 2024-05-08

Expand Down
Loading