mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-17 01:19:29 +08:00
[v3 mac] Basic common event support. Taskfile refactor
This commit is contained in:
parent
3094c19cf3
commit
f210357bfe
22
v3/STATUS.md
22
v3/STATUS.md
@ -26,8 +26,8 @@ Application interface methods
|
||||
|
||||
Webview Window Interface Methods
|
||||
|
||||
| Method | Windows | Linux | Mac | Notes |
|
||||
|----------------------------------------------------|---------|-------|-----|------------------------------------------|
|
||||
| Method | Windows | Linux | Mac | Notes |
|
||||
|----------------------------------------------------|---------|-------|-----|------------------------------------------|
|
||||
| center() | Y | | Y | |
|
||||
| close() | | | Y | |
|
||||
| destroy() | | | Y | |
|
||||
@ -44,7 +44,7 @@ Webview Window Interface Methods
|
||||
| isMinimised() bool | Y | | Y | |
|
||||
| maximise() | Y | | Y | |
|
||||
| minimise() | Y | | Y | |
|
||||
| nativeWindowHandle() (uintptr, error) | Y | | | |
|
||||
| nativeWindowHandle() (uintptr, error) | Y | | Y | |
|
||||
| on(eventID uint) | | | Y | |
|
||||
| openContextMenu(menu *Menu, data *ContextMenuData) | | | Y | |
|
||||
| position() (int, int) | Y | | Y | |
|
||||
@ -264,14 +264,14 @@ Built-in plugin support:
|
||||
|
||||
## Packaging
|
||||
|
||||
| | Windows | Linux | Mac | Notes |
|
||||
|-----------------|---------|-------|-----|-------|
|
||||
| Icon Generation | | | Y | |
|
||||
| Icon Embedding | | | Y | |
|
||||
| Info.plist | | | Y | |
|
||||
| NSIS Installer | | | - | |
|
||||
| Mac bundle | | | Y | |
|
||||
| Windows exe | | | - | |
|
||||
| | Windows | Linux | Mac | Notes |
|
||||
|-----------------|---------|-------|-----|-------|
|
||||
| Icon Generation | | | Y | |
|
||||
| Icon Embedding | | | Y | |
|
||||
| Info.plist | | | Y | |
|
||||
| NSIS Installer | | | - | |
|
||||
| Mac bundle | | | Y | |
|
||||
| Windows exe | | | - | |
|
||||
|
||||
## Frameless Windows
|
||||
|
||||
|
@ -4,73 +4,73 @@ version: '3'
|
||||
|
||||
tasks:
|
||||
|
||||
build-runtime-debug:
|
||||
build:runtime:debug:
|
||||
dir: internal/runtime
|
||||
internal: true
|
||||
cmds:
|
||||
- npx esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_debug_desktop_{{.PLATFORM}}.js --define:DEBUG=true --define:WINDOWS={{.WINDOWS}} --define:DARWIN={{.DARWIN}} --define:LINUX={{.LINUX}} --define:PLATFORM={{.PLATFORM}}
|
||||
|
||||
build-runtime-debug-windows:
|
||||
build:runtime:debug:windows:
|
||||
cmds:
|
||||
- task: build-runtime-debug
|
||||
- task: build:runtime:debug
|
||||
vars:
|
||||
WINDOWS: true
|
||||
DARWIN: false
|
||||
LINUX: false
|
||||
PLATFORM: windows
|
||||
|
||||
build-runtime-debug-linux:
|
||||
build:runtime:debug:linux:
|
||||
cmds:
|
||||
- task: build-runtime-debug
|
||||
- task: build:runtime:debug
|
||||
vars:
|
||||
WINDOWS: false
|
||||
DARWIN: false
|
||||
LINUX: true
|
||||
PLATFORM: linux
|
||||
|
||||
build-runtime-debug-darwin:
|
||||
build:runtime:debug:darwin:
|
||||
cmds:
|
||||
- task: build-runtime-debug
|
||||
- task: build:runtime:debug
|
||||
vars:
|
||||
WINDOWS: false
|
||||
DARWIN: true
|
||||
LINUX: false
|
||||
PLATFORM: darwin
|
||||
|
||||
build-runtime-production:
|
||||
build:runtime:production:
|
||||
dir: internal/runtime
|
||||
internal: true
|
||||
cmds:
|
||||
- npx esbuild desktop/main.js --bundle --minify --outfile=runtime_production_desktop_{{.PLATFORM}}.js --define:DEBUG=true --define:WINDOWS={{.WINDOWS}} --define:DARWIN={{.DARWIN}} --define:LINUX={{.LINUX}} --define:PLATFORM={{.PLATFORM}}
|
||||
|
||||
build-runtime-production-windows:
|
||||
build:runtime:production:windows:
|
||||
cmds:
|
||||
- task: build-runtime-production
|
||||
- task: build:runtime:production
|
||||
vars:
|
||||
WINDOWS: true
|
||||
DARWIN: false
|
||||
LINUX: false
|
||||
PLATFORM: windows
|
||||
|
||||
build-runtime-production-linux:
|
||||
build:runtime:production:linux:
|
||||
cmds:
|
||||
- task: build-runtime-production
|
||||
- task: build:runtime:production
|
||||
vars:
|
||||
WINDOWS: false
|
||||
DARWIN: false
|
||||
LINUX: true
|
||||
PLATFORM: linux
|
||||
|
||||
build-runtime-production-darwin:
|
||||
build:runtime:production:darwin:
|
||||
cmds:
|
||||
- task: build-runtime-production
|
||||
- task: build:runtime:production
|
||||
vars:
|
||||
WINDOWS: false
|
||||
DARWIN: true
|
||||
LINUX: false
|
||||
PLATFORM: darwin
|
||||
|
||||
install-runtime-dev-deps:
|
||||
install:runtime-dev-deps:
|
||||
dir: internal/runtime/dev
|
||||
internal: true
|
||||
sources:
|
||||
@ -79,7 +79,7 @@ tasks:
|
||||
- npm install
|
||||
|
||||
|
||||
install-runtime-deps:
|
||||
install:runtime-deps:
|
||||
dir: internal/runtime
|
||||
internal: true
|
||||
sources:
|
||||
@ -87,35 +87,35 @@ tasks:
|
||||
cmds:
|
||||
- npm install
|
||||
|
||||
test-runtime:
|
||||
test:runtime:
|
||||
dir: internal/runtime
|
||||
cmds:
|
||||
- npx vitest run
|
||||
|
||||
update-runtime:
|
||||
update:runtime:
|
||||
dir: internal/runtime
|
||||
cmds:
|
||||
- npx npm-check-updates -u
|
||||
|
||||
build-runtime-all:
|
||||
build:runtime-all:
|
||||
dir: internal/runtime
|
||||
deps:
|
||||
- build-runtime-production-darwin
|
||||
- build-runtime-production-windows
|
||||
- build-runtime-production-linux
|
||||
- build-runtime-debug-darwin
|
||||
- build-runtime-debug-windows
|
||||
- build-runtime-debug-linux
|
||||
- build:runtime:production:darwin
|
||||
- build:runtime:production:windows
|
||||
- build:runtime:production:linux
|
||||
- build:runtime:debug:darwin
|
||||
- build:runtime:debug:windows
|
||||
- build:runtime:debug:linux
|
||||
|
||||
cmds:
|
||||
- cmd: echo "build complete"
|
||||
|
||||
build-runtime:
|
||||
build:runtime:
|
||||
dir: internal/runtime
|
||||
deps:
|
||||
- install-runtime-deps
|
||||
- install:runtime-deps
|
||||
cmds:
|
||||
- task: build-runtime-all
|
||||
- task: build:runtime-all
|
||||
|
||||
recreate-template-dir:
|
||||
dir: internal/templates
|
||||
@ -125,7 +125,7 @@ tasks:
|
||||
- rm -rf {{.TEMPLATE_DIR}}
|
||||
- mkdir -p {{.TEMPLATE_DIR}}
|
||||
|
||||
generate-template:
|
||||
generate:template:
|
||||
dir: internal/templates/{{.TEMPLATE}}
|
||||
deps:
|
||||
- task: recreate-template-dir
|
||||
@ -152,49 +152,54 @@ tasks:
|
||||
- go install
|
||||
- echo "Reinstalled wails CLI"
|
||||
|
||||
generate-templates:
|
||||
generate:events:
|
||||
dir: tasks/events
|
||||
cmds:
|
||||
- go run generate.go
|
||||
|
||||
generate:templates:
|
||||
dir: internal/templates/
|
||||
deps:
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: svelte
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: svelte-ts
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: vue
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: vue-ts
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: react
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: react-ts
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: preact
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: preact-ts
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: lit
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: lit-ts
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: vanilla
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: vanilla-ts
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: react-swc
|
||||
- task: generate-template
|
||||
- task: generate:template
|
||||
vars:
|
||||
TEMPLATE: react-swc-ts
|
||||
cmds:
|
||||
|
@ -26,10 +26,12 @@ func main() {
|
||||
},
|
||||
})
|
||||
|
||||
// Custom event handling
|
||||
app.Events.On("myevent", func(e *application.WailsEvent) {
|
||||
log.Printf("[Go] WailsEvent received: %+v\n", e)
|
||||
})
|
||||
|
||||
// OS specific application events
|
||||
app.On(events.Mac.ApplicationDidFinishLaunching, func() {
|
||||
for {
|
||||
log.Println("Sending event")
|
||||
@ -41,6 +43,11 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
// Platform agnostic events
|
||||
app.On(events.Common.ApplicationStarted, func() {
|
||||
println("events.Common.ApplicationStarted fired!")
|
||||
})
|
||||
|
||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
Title: "Events Demo",
|
||||
Mac: application.MacWindow{
|
||||
|
@ -186,6 +186,7 @@ func (m *macosApp) run() error {
|
||||
C.setActivationPolicy(C.int(m.parent.options.Mac.ActivationPolicy))
|
||||
C.activateIgnoringOtherApps()
|
||||
})
|
||||
m.setupCommonEvents()
|
||||
// setup event listeners
|
||||
for eventID := range m.parent.applicationEventListeners {
|
||||
m.on(eventID)
|
||||
|
@ -24,6 +24,8 @@ type WailsEvent struct {
|
||||
Sender string `json:"sender"`
|
||||
}
|
||||
|
||||
var commonEvents = make(chan uint)
|
||||
|
||||
func (e WailsEvent) ToJSON() string {
|
||||
marshal, err := json.Marshal(&e)
|
||||
if err != nil {
|
||||
|
17
v3/pkg/application/events_common_darwin.go
Normal file
17
v3/pkg/application/events_common_darwin.go
Normal file
@ -0,0 +1,17 @@
|
||||
//go:build darwin
|
||||
|
||||
package application
|
||||
|
||||
import "github.com/wailsapp/wails/v3/pkg/events"
|
||||
|
||||
var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{
|
||||
events.Mac.ApplicationDidFinishLaunching: events.Common.ApplicationStarted,
|
||||
}
|
||||
|
||||
func (m *macosApp) setupCommonEvents() {
|
||||
for sourceEvent, targetEvent := range commonApplicationEventMap {
|
||||
m.parent.On(sourceEvent, func() {
|
||||
applicationEvents <- uint(targetEvent)
|
||||
})
|
||||
}
|
||||
}
|
@ -1,14 +1,11 @@
|
||||
//go:build darwin
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "webview_window_darwin.h"
|
||||
#import "../events/events.h"
|
||||
|
||||
extern void processMessage(unsigned int, const char*);
|
||||
extern void processURLRequest(unsigned int, void *);
|
||||
extern bool hasListeners(unsigned int);
|
||||
|
||||
@implementation WebviewWindow
|
||||
- (WebviewWindow*) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
|
||||
{
|
||||
@ -50,7 +47,6 @@ extern bool hasListeners(unsigned int);
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation WebviewWindowDelegate
|
||||
- (BOOL)windowShouldClose:(NSWindow *)sender {
|
||||
if( self.hideOnClose ) {
|
||||
|
@ -7,6 +7,18 @@ const (
|
||||
FilesDropped WindowEventType = iota
|
||||
)
|
||||
|
||||
var Common = newCommonEvents()
|
||||
|
||||
type commonEvents struct {
|
||||
ApplicationStarted ApplicationEventType
|
||||
}
|
||||
|
||||
func newCommonEvents() commonEvents {
|
||||
return commonEvents{
|
||||
ApplicationStarted: 1152,
|
||||
}
|
||||
}
|
||||
|
||||
var Mac = newMacEvents()
|
||||
|
||||
type macEvents struct {
|
||||
|
@ -126,3 +126,4 @@ windows:APMSuspend
|
||||
windows:APMResumeAutomatic
|
||||
windows:APMResumeSuspend
|
||||
windows:APMPowerSettingChange
|
||||
common:ApplicationStarted
|
||||
|
@ -16,6 +16,16 @@ const (
|
||||
FilesDropped WindowEventType = iota
|
||||
)
|
||||
|
||||
var Common = newCommonEvents()
|
||||
|
||||
type commonEvents struct {
|
||||
$$COMMONEVENTSDECL}
|
||||
|
||||
func newCommonEvents() commonEvents {
|
||||
return commonEvents{
|
||||
$$COMMONEVENTSVALUES }
|
||||
}
|
||||
|
||||
var Mac = newMacEvents()
|
||||
|
||||
type macEvents struct {
|
||||
@ -68,6 +78,9 @@ func main() {
|
||||
windowsEventsDecl := bytes.NewBufferString("")
|
||||
windowsEventsValues := bytes.NewBufferString("")
|
||||
|
||||
commonEventsDecl := bytes.NewBufferString("")
|
||||
commonEventsValues := bytes.NewBufferString("")
|
||||
|
||||
var id int
|
||||
var maxMacEvents int
|
||||
var line []byte
|
||||
@ -145,6 +158,16 @@ func main() {
|
||||
|
||||
`)
|
||||
}
|
||||
case "common":
|
||||
eventType := "ApplicationEventType"
|
||||
if strings.HasPrefix(event, "Window") {
|
||||
eventType = "WindowEventType"
|
||||
}
|
||||
if strings.HasPrefix(event, "WebView") {
|
||||
eventType = "WindowEventType"
|
||||
}
|
||||
commonEventsDecl.WriteString("\t" + eventTitle + " " + eventType + "\n")
|
||||
commonEventsValues.WriteString("\t\t" + event + ": " + strconv.Itoa(id) + ",\n")
|
||||
case "windows":
|
||||
eventType := "ApplicationEventType"
|
||||
if strings.HasPrefix(event, "Window") {
|
||||
@ -200,6 +223,8 @@ func main() {
|
||||
templateToWrite = strings.ReplaceAll(templateToWrite, "$$MACEVENTSVALUES", macEventsValues.String())
|
||||
templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSDECL", windowsEventsDecl.String())
|
||||
templateToWrite = strings.ReplaceAll(templateToWrite, "$$WINDOWSEVENTSVALUES", windowsEventsValues.String())
|
||||
templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONEVENTSDECL", commonEventsDecl.String())
|
||||
templateToWrite = strings.ReplaceAll(templateToWrite, "$$COMMONEVENTSVALUES", commonEventsValues.String())
|
||||
err = os.WriteFile("../../pkg/events/events.go", []byte(templateToWrite), 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -213,7 +238,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Load the window_delegate.m file
|
||||
windowDelegate, err := os.ReadFile("../../pkg/application/webview_window.m")
|
||||
windowDelegate, err := os.ReadFile("../../pkg/application/webview_window_darwin.m")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -243,13 +268,13 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
err = os.WriteFile("../../pkg/application/webview_window.m", buffer.Bytes(), 0755)
|
||||
err = os.WriteFile("../../pkg/application/webview_window_darwin.m", buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Load the app_delegate.m file
|
||||
appDelegate, err := os.ReadFile("../../pkg/application/app_delegate.m")
|
||||
appDelegate, err := os.ReadFile("../../pkg/application/application_darwin_delegate.m")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -277,7 +302,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
err = os.WriteFile("../../pkg/application/app_delegate.m", buffer.Bytes(), 0755)
|
||||
err = os.WriteFile("../../pkg/application/application_darwin_delegate.m", buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user