mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Refactor menu functions and streamline devtools toggle across systems
This update adds implementation to several menu item functions, replacing their previous 'not implemented' state. This includes actions for close, reload, forcing reload, toggling of fullscreen, reset zoom, and others. The update also includes modifications for the handling of developer tools toggle under different build configurations. This refactoring is aimed to standardize devtools configuration across different operating systems.
This commit is contained in:
@@ -256,13 +256,6 @@ void windowSetMaxSize(void* nsWindow, int width, int height) {
|
||||
[window setMaxSize:size];
|
||||
}
|
||||
|
||||
// Enable NSWindow devtools
|
||||
void windowEnableDevTools(void* nsWindow) {
|
||||
WebviewWindow* window = (WebviewWindow*)nsWindow;
|
||||
// Enable devtools in webview
|
||||
[window.webView.configuration.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
|
||||
}
|
||||
|
||||
// windowZoomReset
|
||||
void windowZoomReset(void* nsWindow) {
|
||||
WebviewWindow* window = (WebviewWindow*)nsWindow;
|
||||
@@ -734,7 +727,7 @@ void windowFocus(void *window) {
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"net/url"
|
||||
"github.com/wailsapp/wails/v3/internal/assetserver"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
@@ -969,15 +962,6 @@ func (w *macosWebviewWindow) execJS(js string) {
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) setURL(uri string) {
|
||||
if uri != "" {
|
||||
parsedURL, err := url.Parse(uri)
|
||||
if err == nil && parsedURL.Scheme == "" && parsedURL.Host == "" {
|
||||
// TODO handle this in a central location, the scheme and host might be platform dependant.
|
||||
parsedURL.Scheme = "wails"
|
||||
parsedURL.Host = "wails"
|
||||
uri = parsedURL.String()
|
||||
}
|
||||
}
|
||||
C.navigationLoadURL(w.nsWindow, C.CString(uri))
|
||||
}
|
||||
|
||||
@@ -1017,9 +1001,6 @@ func (w *macosWebviewWindow) setMaxSize(width, height int) {
|
||||
func (w *macosWebviewWindow) setResizable(resizable bool) {
|
||||
C.windowSetResizable(w.nsWindow, C.bool(resizable))
|
||||
}
|
||||
func (w *macosWebviewWindow) enableDevTools() {
|
||||
C.windowEnableDevTools(w.nsWindow)
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) size() (int, int) {
|
||||
var width, height C.int
|
||||
@@ -1109,9 +1090,8 @@ func (w *macosWebviewWindow) run() {
|
||||
w.setMaxSize(options.MaxWidth, options.MaxHeight)
|
||||
}
|
||||
//w.setZoom(options.Zoom)
|
||||
if globalApplication.isDebugMode || options.DevToolsEnabled {
|
||||
w.enableDevTools()
|
||||
}
|
||||
w.enableDevTools()
|
||||
|
||||
w.setBackgroundColour(options.BackgroundColour)
|
||||
|
||||
switch macOptions.Backdrop {
|
||||
@@ -1157,17 +1137,34 @@ func (w *macosWebviewWindow) run() {
|
||||
}
|
||||
C.windowCenter(w.nsWindow)
|
||||
|
||||
if options.URL != "" {
|
||||
w.setURL(options.URL)
|
||||
startURL, err := assetserver.GetStartURL(options.URL)
|
||||
if err != nil {
|
||||
globalApplication.fatal(err.Error())
|
||||
}
|
||||
|
||||
w.setURL(startURL)
|
||||
|
||||
// We need to wait for the HTML to load before we can execute the javascript
|
||||
w.parent.On(events.Mac.WebViewDidFinishNavigation, func(_ *WindowEvent) {
|
||||
if options.JS != "" {
|
||||
w.execJS(options.JS)
|
||||
}
|
||||
if options.CSS != "" {
|
||||
C.windowInjectCSS(w.nsWindow, C.CString(options.CSS))
|
||||
}
|
||||
InvokeAsync(func() {
|
||||
if options.JS != "" {
|
||||
w.execJS(options.JS)
|
||||
}
|
||||
if options.CSS != "" {
|
||||
C.windowInjectCSS(w.nsWindow, C.CString(options.CSS))
|
||||
}
|
||||
if options.Hidden == false {
|
||||
C.windowShow(w.nsWindow)
|
||||
w.setHasShadow(!options.Mac.DisableShadow)
|
||||
} else {
|
||||
// We have to wait until the window is shown before we can remove the shadow
|
||||
var cancel func()
|
||||
cancel = w.parent.On(events.Mac.WindowDidBecomeKey, func(_ *WindowEvent) {
|
||||
w.setHasShadow(!options.Mac.DisableShadow)
|
||||
cancel()
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// Translate ShouldClose to common WindowClosing event
|
||||
@@ -1186,17 +1183,6 @@ func (w *macosWebviewWindow) run() {
|
||||
if options.HTML != "" {
|
||||
w.setHTML(options.HTML)
|
||||
}
|
||||
if options.Hidden == false {
|
||||
C.windowShow(w.nsWindow)
|
||||
w.setHasShadow(!options.Mac.DisableShadow)
|
||||
} else {
|
||||
// We have to wait until the window is shown before we can remove the shadow
|
||||
var cancel func()
|
||||
cancel = w.parent.On(events.Mac.WindowDidBecomeKey, func(_ *WindowEvent) {
|
||||
w.setHasShadow(!options.Mac.DisableShadow)
|
||||
cancel()
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user