-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Integrated Single Process Option of Wails app #1351
Comments
In the meantime, you can do something like this, not sure if it is a good method, but it seem to work for me. // Create a mutex to keep a program running on single instance. Return error if program is already running.
func CreateMutex(name string) (uintptr, error) {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
procCreateMutex := kernel32.NewProc("CreateMutexW")
ret, _, err := procCreateMutex.Call(0, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(name))))
switch int(err.(syscall.Errno)) {
case 0:
return ret, nil
default:
return ret, err
}
} Call the function in the import (
sysWindows "golang.org/x/sys/windows"
)
// Create mutex to keep app running in single instance
if _, mutexErr := CreateMutex("YourAppName"); mutexErr != nil {
// Do whatever... for me, I call a messagebox...
sysWindows.MessageBox(
sysWindows.GetShellWindow(),
syscall.StringToUTF16Ptr("Application is already running!"),
syscall.StringToUTF16Ptr("Warning"),
sysWindows.MB_OK|sysWindows.MB_ICONEXCLAMATION|sysWindows.MB_SYSTEMMODAL) //See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messageboxw for details
os.Exit(0) //Exit if the program is already running
} |
I'd love to integrate this into the options as a callback. Thoughts? |
file locks is one of ways to go |
There's another way making this on windows - Events. CreateEventW It will look something like this (in C, but porting it to Go is pretty straightforward):
|
This has been implemented as a v3 plugin. Windows + Mac currently supported. |
Describe the solution you'd like
Currently wails does not have integrated option to make sure only 1 process is running at a time. Pls consider add this feature to wails. Thx.
The text was updated successfully, but these errors were encountered: