wails/v3/pkg/application/single_instance_darwin.go
Lea Anthony 873848a077 Merge iOS support from v3-alpha-feature/ios-support
This commit integrates iOS platform support for Wails v3, adapting the
iOS-specific code to work with the new transport layer architecture.

Key changes:
- Add iOS-specific application, webview, and runtime files
- Add iOS event types and processing
- Add iOS examples and templates
- Update messageprocessor to handle iOS requests
- Move badge_ios.go to dock package

Note: The iOS branch was based on an older v3-alpha and required
significant conflict resolution due to the transport layer refactor
(PR #4702). Some iOS-specific code may need further adaptation:
- processIOSMethod needs to be implemented with new RuntimeRequest signature
- iOS event generation in tasks/events/generate.go needs updating

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-10 18:34:21 +11:00

96 lines
2.2 KiB
Go

//go:build darwin && !ios
package application
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework Cocoa
#include <stdlib.h>
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
static void SendDataToFirstInstance(char *singleInstanceUniqueId, char* message) {
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:[NSString stringWithUTF8String:singleInstanceUniqueId]
object:nil
userInfo:@{@"message": [NSString stringWithUTF8String:message]}
deliverImmediately:YES];
}
*/
import "C"
import (
"os"
"syscall"
"unsafe"
)
type darwinLock struct {
file *os.File
uniqueID string
manager *singleInstanceManager
}
func newPlatformLock(manager *singleInstanceManager) (platformLock, error) {
return &darwinLock{
manager: manager,
}, nil
}
func (l *darwinLock) acquire(uniqueID string) error {
l.uniqueID = uniqueID
lockFilePath := os.TempDir()
lockFileName := uniqueID + ".lock"
var err error
l.file, err = createLockFile(lockFilePath + "/" + lockFileName)
if err != nil {
return alreadyRunningError
}
return nil
}
func (l *darwinLock) release() {
if l.file != nil {
syscall.Flock(int(l.file.Fd()), syscall.LOCK_UN)
l.file.Close()
os.Remove(l.file.Name())
l.file = nil
}
}
func (l *darwinLock) notify(data string) error {
singleInstanceUniqueId := C.CString(l.uniqueID)
defer C.free(unsafe.Pointer(singleInstanceUniqueId))
cData := C.CString(data)
defer C.free(unsafe.Pointer(cData))
C.SendDataToFirstInstance(singleInstanceUniqueId, cData)
os.Exit(l.manager.options.ExitCode)
return nil
}
// CreateLockFile tries to create a file with given name and acquire an
// exclusive lock on it. If the file already exists AND is still locked, it will
// fail.
func createLockFile(filename string) (*os.File, error) {
file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return nil, err
}
err = syscall.Flock(int(file.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
if err != nil {
file.Close()
return nil, err
}
return file, nil
}
//export handleSecondInstanceData
func handleSecondInstanceData(secondInstanceMessage *C.char) {
message := C.GoString(secondInstanceMessage)
secondInstanceBuffer <- message
}