mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[WIP] refactor CGO methods
This commit is contained in:
committed by
Travis McLane
parent
a048233f4c
commit
02a1b540ce
@@ -34,7 +34,7 @@ type linuxApp struct {
|
||||
theme string
|
||||
}
|
||||
|
||||
func (l *linuxApp) GetFlags(options Options) map[string]any {
|
||||
func (a *linuxApp) GetFlags(options Options) map[string]any {
|
||||
if options.Flags == nil {
|
||||
options.Flags = make(map[string]any)
|
||||
}
|
||||
@@ -45,31 +45,27 @@ func getNativeApplication() *linuxApp {
|
||||
return globalApplication.impl.(*linuxApp)
|
||||
}
|
||||
|
||||
func (l *linuxApp) hide() {
|
||||
hideAllWindows(l.application)
|
||||
func (a *linuxApp) hide() {
|
||||
a.hideAllWindows()
|
||||
}
|
||||
|
||||
func (l *linuxApp) show() {
|
||||
showAllWindows(l.application)
|
||||
func (a *linuxApp) show() {
|
||||
a.showAllWindows()
|
||||
}
|
||||
|
||||
func (l *linuxApp) on(eventID uint) {
|
||||
func (a *linuxApp) on(eventID uint) {
|
||||
// TODO: Test register/unregister events
|
||||
//C.registerApplicationEvent(l.application, C.uint(eventID))
|
||||
}
|
||||
|
||||
func (l *linuxApp) setIcon(icon []byte) {
|
||||
func (a *linuxApp) setIcon(icon []byte) {
|
||||
log.Println("linuxApp.setIcon", "not implemented")
|
||||
}
|
||||
|
||||
func (l *linuxApp) name() string {
|
||||
func (a *linuxApp) name() string {
|
||||
return appName()
|
||||
}
|
||||
|
||||
func (l *linuxApp) getCurrentWindowID() uint {
|
||||
return getCurrentWindowID(l.application, l.windowMap)
|
||||
}
|
||||
|
||||
type rnr struct {
|
||||
f func()
|
||||
}
|
||||
@@ -78,7 +74,7 @@ func (r rnr) run() {
|
||||
r.f()
|
||||
}
|
||||
|
||||
func (l *linuxApp) setApplicationMenu(menu *Menu) {
|
||||
func (a *linuxApp) setApplicationMenu(menu *Menu) {
|
||||
// FIXME: How do we avoid putting a menu?
|
||||
if menu == nil {
|
||||
// Create a default menu
|
||||
@@ -87,55 +83,55 @@ func (l *linuxApp) setApplicationMenu(menu *Menu) {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *linuxApp) run() error {
|
||||
func (a *linuxApp) run() error {
|
||||
|
||||
l.parent.On(events.Linux.ApplicationStartup, func(evt *Event) {
|
||||
a.parent.On(events.Linux.ApplicationStartup, func(evt *Event) {
|
||||
fmt.Println("events.Linux.ApplicationStartup received!")
|
||||
})
|
||||
l.setupCommonEvents()
|
||||
l.monitorThemeChanges()
|
||||
return appRun(l.application)
|
||||
a.setupCommonEvents()
|
||||
a.monitorThemeChanges()
|
||||
return appRun(a.application)
|
||||
}
|
||||
|
||||
func (l *linuxApp) unregisterWindow(w windowPointer) {
|
||||
l.windowMapLock.Lock()
|
||||
delete(l.windowMap, w)
|
||||
l.windowMapLock.Unlock()
|
||||
func (a *linuxApp) unregisterWindow(w windowPointer) {
|
||||
a.windowMapLock.Lock()
|
||||
delete(a.windowMap, w)
|
||||
a.windowMapLock.Unlock()
|
||||
|
||||
// If this was the last window...
|
||||
if len(l.windowMap) == 0 && !l.parent.options.Linux.DisableQuitOnLastWindowClosed {
|
||||
l.destroy()
|
||||
if len(a.windowMap) == 0 && !a.parent.options.Linux.DisableQuitOnLastWindowClosed {
|
||||
a.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
func (l *linuxApp) destroy() {
|
||||
func (a *linuxApp) destroy() {
|
||||
if !globalApplication.shouldQuit() {
|
||||
return
|
||||
}
|
||||
globalApplication.cleanup()
|
||||
appDestroy(l.application)
|
||||
appDestroy(a.application)
|
||||
}
|
||||
|
||||
func (l *linuxApp) isOnMainThread() bool {
|
||||
func (a *linuxApp) isOnMainThread() bool {
|
||||
return isOnMainThread()
|
||||
}
|
||||
|
||||
// register our window to our parent mapping
|
||||
func (l *linuxApp) registerWindow(window pointer, id uint) {
|
||||
l.windowMapLock.Lock()
|
||||
l.windowMap[windowPointer(window)] = id
|
||||
l.windowMapLock.Unlock()
|
||||
func (a *linuxApp) registerWindow(window pointer, id uint) {
|
||||
a.windowMapLock.Lock()
|
||||
a.windowMap[windowPointer(window)] = id
|
||||
a.windowMapLock.Unlock()
|
||||
}
|
||||
|
||||
func (l *linuxApp) isDarkMode() bool {
|
||||
return strings.Contains(l.theme, "dark")
|
||||
func (a *linuxApp) isDarkMode() bool {
|
||||
return strings.Contains(a.theme, "dark")
|
||||
}
|
||||
|
||||
func (l *linuxApp) monitorThemeChanges() {
|
||||
func (a *linuxApp) monitorThemeChanges() {
|
||||
go func() {
|
||||
conn, err := dbus.ConnectSessionBus()
|
||||
if err != nil {
|
||||
l.parent.info("[WARNING] Failed to connect to session bus; monitoring for theme changes will not function:", err)
|
||||
a.parent.info("[WARNING] Failed to connect to session bus; monitoring for theme changes will not function:", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
@@ -168,10 +164,10 @@ func (l *linuxApp) monitorThemeChanges() {
|
||||
continue
|
||||
}
|
||||
|
||||
if theme != l.theme {
|
||||
l.theme = theme
|
||||
if theme != a.theme {
|
||||
a.theme = theme
|
||||
event := newApplicationEvent(events.Common.ThemeChanged)
|
||||
event.Context().setIsDarkMode(l.isDarkMode())
|
||||
event.Context().setIsDarkMode(a.isDarkMode())
|
||||
applicationEvents <- event
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package application
|
||||
|
||||
func (l *linuxApp) showAboutDialog(title string, message string, icon []byte) {
|
||||
window := globalApplication.getWindowForID(l.getCurrentWindowID())
|
||||
func (a *linuxApp) showAboutDialog(title string, message string, icon []byte) {
|
||||
window := globalApplication.getWindowForID(a.getCurrentWindowID())
|
||||
var parent uintptr
|
||||
if window != nil {
|
||||
parent, _ = window.(*WebviewWindow).NativeWindowHandle()
|
||||
|
||||
@@ -9,11 +9,11 @@ var commonApplicationEventMap = map[events.ApplicationEventType]events.Applicati
|
||||
events.Linux.SystemThemeChanged: events.Common.ThemeChanged,
|
||||
}
|
||||
|
||||
func (l *linuxApp) setupCommonEvents() {
|
||||
func (a *linuxApp) setupCommonEvents() {
|
||||
for sourceEvent, targetEvent := range commonApplicationEventMap {
|
||||
sourceEvent := sourceEvent
|
||||
targetEvent := targetEvent
|
||||
l.parent.On(sourceEvent, func(event *Event) {
|
||||
a.parent.On(sourceEvent, func(event *Event) {
|
||||
event.Id = uint(targetEvent)
|
||||
applicationEvents <- event
|
||||
})
|
||||
|
||||
@@ -1005,23 +1005,23 @@ func handleLoadChanged(webview *C.WebKitWebView, event C.WebKitLoadEvent, data C
|
||||
}
|
||||
}
|
||||
|
||||
func windowSetupSignalHandlers(windowId uint, window, webview pointer, emit func(e events.WindowEventType)) {
|
||||
func (w *linuxWebviewWindow) setupSignalHandlers(emit func(e events.WindowEventType)) {
|
||||
|
||||
c := NewCalloc()
|
||||
defer c.Free()
|
||||
|
||||
winID := unsafe.Pointer(uintptr(C.uint(windowId)))
|
||||
winID := unsafe.Pointer(uintptr(C.uint(w.parent.ID())))
|
||||
|
||||
// Set up the window close event
|
||||
C.signal_connect(unsafe.Pointer(window), c.String("delete-event"), C.handleDeleteEvent, winID)
|
||||
C.signal_connect(unsafe.Pointer(webview), c.String("load-changed"), C.handleLoadChanged, winID)
|
||||
wv := unsafe.Pointer(w.webview)
|
||||
C.signal_connect(unsafe.Pointer(w.window), c.String("delete-event"), C.handleDeleteEvent, winID)
|
||||
C.signal_connect(wv, c.String("load-changed"), C.handleLoadChanged, winID)
|
||||
|
||||
contentManager := C.webkit_web_view_get_user_content_manager((*C.WebKitWebView)(webview))
|
||||
contentManager := C.webkit_web_view_get_user_content_manager(w.webKitWebView())
|
||||
C.signal_connect(unsafe.Pointer(contentManager), c.String("script-message-received::external"), C.sendMessageToBackend, nil)
|
||||
C.signal_connect(unsafe.Pointer(webview), c.String("button-press-event"), C.onButtonEvent, winID)
|
||||
C.signal_connect(unsafe.Pointer(webview), c.String("button-release-event"), C.onButtonEvent, winID)
|
||||
C.signal_connect(unsafe.Pointer(webview), c.String("key-press-event"), C.onKeyPressEvent, winID)
|
||||
|
||||
}
|
||||
|
||||
//export handleLoadChanged
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package application
|
||||
|
||||
func (l *linuxApp) dispatchOnMainThread(id uint) {
|
||||
func (a *linuxApp) dispatchOnMainThread(id uint) {
|
||||
dispatchOnMainThread(id)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
func (l *linuxApp) getPrimaryScreen() (*Screen, error) {
|
||||
func (a *linuxApp) getPrimaryScreen() (*Screen, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (l *linuxApp) getScreens() ([]*Screen, error) {
|
||||
func (a *linuxApp) getScreens() ([]*Screen, error) {
|
||||
var wg sync.WaitGroup
|
||||
var screens []*Screen
|
||||
var err error
|
||||
wg.Add(1)
|
||||
InvokeSync(func() {
|
||||
screens, err = getScreens(l.application)
|
||||
screens, err = getScreens(a.application)
|
||||
wg.Done()
|
||||
})
|
||||
wg.Wait()
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"math"
|
||||
|
||||
"github.com/wailsapp/wails/v3/internal/assetserver"
|
||||
"github.com/wailsapp/wails/v3/internal/capabilities"
|
||||
"github.com/wailsapp/wails/v3/internal/runtime"
|
||||
@@ -102,15 +104,10 @@ func (w *linuxWebviewWindow) disableSizeConstraints() {
|
||||
w.setMinMaxSize(x, y, width*scale, height*scale)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) unfullscreen() {
|
||||
windowUnfullscreen(w.window)
|
||||
w.unmaximise()
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) fullscreen() {
|
||||
w.maximise()
|
||||
//w.lastWidth, w.lastHeight = w.size()
|
||||
x, y, width, height, scale := windowGetCurrentMonitorGeometry(w.window)
|
||||
x, y, width, height, scale := w.getCurrentMonitorGeometry()
|
||||
if x == -1 && y == -1 && width == -1 && height == -1 {
|
||||
return
|
||||
}
|
||||
@@ -137,27 +134,6 @@ func (w *linuxWebviewWindow) windowZoom() {
|
||||
w.zoom() // FIXME> This should be removed
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) close() {
|
||||
windowClose(w.window)
|
||||
getNativeApplication().unregisterWindow(windowPointer(w.window))
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) zoomIn() {
|
||||
windowZoomIn(w.webview)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) zoomOut() {
|
||||
windowZoomOut(w.webview)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) zoomReset() {
|
||||
windowZoomSet(w.webview, 1.0)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) reload() {
|
||||
windowReload(w.webview, "wails://")
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) forceReload() {
|
||||
w.reload()
|
||||
}
|
||||
@@ -192,16 +168,6 @@ func newWindowImpl(parent *WebviewWindow) *linuxWebviewWindow {
|
||||
return result
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setTitle(title string) {
|
||||
if !w.parent.options.Frameless {
|
||||
windowSetTitle(w.window, title)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setSize(width, height int) {
|
||||
windowResize(w.window, width, height)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setMinMaxSize(minWidth, minHeight, maxWidth, maxHeight int) {
|
||||
if minWidth == 0 {
|
||||
minWidth = -1
|
||||
@@ -357,6 +323,20 @@ func (w *linuxWebviewWindow) run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) destroy() {
|
||||
w.parent.markAsDestroyed()
|
||||
// Free menu
|
||||
if w.gtkmenu != nil {
|
||||
menuDestroy(w.gtkmenu)
|
||||
w.gtkmenu = nil
|
||||
}
|
||||
windowDestroy(w.window)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setEnabled(enabled bool) {
|
||||
widgetSetSensitive(w.window, enabled)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) startResize(border string) error {
|
||||
// FIXME: what do we need to do here?
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user