From 758c4c2c8d4289848ec8ef5053c82aa6c71c7fc8 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 6 Feb 2024 05:50:36 +1100 Subject: [PATCH] Refactor Linux application handling in webview This update introduces a LinuxOptions struct for Linux-specific application configurations and refines webview for Linux. The 'windows' map has been renamed to 'windowMap' to avoid confusion. Moreover, a method to unregister Windows has been added to ensure the Linux application automatically quits when the last window closes, unless explicitly disabled in the new LinuxOptions structure. Reset Window position after hiding. Some debug output has been removed. --- v3/pkg/application/application_linux.go | 19 ++++++++--- v3/pkg/application/webview_window_linux.go | 39 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/v3/pkg/application/application_linux.go b/v3/pkg/application/application_linux.go index c9692945..578bbbd5 100644 --- a/v3/pkg/application/application_linux.go +++ b/v3/pkg/application/application_linux.go @@ -67,7 +67,7 @@ func (l *linuxApp) name() string { } func (l *linuxApp) getCurrentWindowID() uint { - return getCurrentWindowID(l.application, l.windows) + return getCurrentWindowID(l.application, l.windowMap) } type rnr struct { @@ -112,6 +112,17 @@ func (l *linuxApp) run() error { return appRun(l.application) } +func (l *linuxApp) unregisterWindow(w windowPointer) { + l.windowMapLock.Lock() + delete(l.windowMap, w) + l.windowMapLock.Unlock() + + // If this was the last window... + if len(l.windowMap) == 0 && !l.parent.options.Linux.DisableQuitOnLastWindowClosed { + l.destroy() + } +} + func (l *linuxApp) destroy() { if !globalApplication.shouldQuit() { return @@ -126,9 +137,9 @@ func (l *linuxApp) isOnMainThread() bool { // register our window to our parent mapping func (l *linuxApp) registerWindow(window pointer, id uint) { - l.windowsLock.Lock() - l.windows[windowPointer(window)] = id - l.windowsLock.Unlock() + l.windowMapLock.Lock() + l.windowMap[windowPointer(window)] = id + l.windowMapLock.Unlock() } func (l *linuxApp) isDarkMode() bool { diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index d990316d..7845c760 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -110,6 +110,24 @@ 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) + if x == -1 && y == -1 && width == -1 && height == -1 { + return + } + w.setMinMaxSize(0, 0, width*scale, height*scale) + w.setSize(width*scale, height*scale) + windowFullscreen(w.window) + w.setRelativePosition(0, 0) +} + func (w *linuxWebviewWindow) unminimise() { w.present() } @@ -127,6 +145,27 @@ 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() }