mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-11 22:49:29 +08:00
ToggleDevTools -> OpenDevTools
More refactor CGO methods.
This commit is contained in:
parent
4cd4b46772
commit
a34ccbff33
@ -439,6 +439,11 @@ func main() {
|
||||
w.SetEnabled(true)
|
||||
})
|
||||
})
|
||||
stateMenu.Add("Open Dev Tools").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
w.OpenDevTools()
|
||||
})
|
||||
})
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
stateMenu.Add("Flash Start").OnClick(func(ctx *application.Context) {
|
||||
|
@ -644,13 +644,14 @@ func getScreens(app pointer) ([]*Screen, error) {
|
||||
}
|
||||
|
||||
// widgets
|
||||
func widgetSetSensitive(widget pointer, enabled bool) {
|
||||
value := C.int(0)
|
||||
|
||||
func (w *linuxWebviewWindow) setEnabled(enabled bool) {
|
||||
var value C.int
|
||||
if enabled {
|
||||
value = C.int(1)
|
||||
}
|
||||
|
||||
C.gtk_widget_set_sensitive((*C.GtkWidget)(widget), value)
|
||||
C.gtk_widget_set_sensitive(w.gtkWidget(), value)
|
||||
}
|
||||
|
||||
func widgetSetVisible(widget pointer, hidden bool) {
|
||||
@ -692,32 +693,41 @@ func (w *linuxWebviewWindow) execJS(js string) {
|
||||
C.free(unsafe.Pointer(value))
|
||||
}
|
||||
|
||||
func windowDestroy(window pointer) {
|
||||
// Should this truly 'destroy' ?
|
||||
C.gtk_window_close((*C.GtkWindow)(window))
|
||||
//C.gtk_widget_destroy((*C.GtkWidget)(window))
|
||||
func (w *linuxWebviewWindow) destroy() {
|
||||
w.parent.markAsDestroyed()
|
||||
// Free menu
|
||||
if w.gtkmenu != nil {
|
||||
C.gtk_widget_destroy((*C.GtkWidget)(w.gtkmenu))
|
||||
w.gtkmenu = nil
|
||||
}
|
||||
w.destroy()
|
||||
}
|
||||
|
||||
func menuDestroy(gtkMenu pointer) {
|
||||
C.gtk_widget_destroy((*C.GtkWidget)(gtkMenu))
|
||||
func (w *linuxWebviewWindow) fullscreen() {
|
||||
w.maximise()
|
||||
//w.lastWidth, w.lastHeight = w.size()
|
||||
x, y, width, height, scale := w.getCurrentMonitorGeometry()
|
||||
if x == -1 && y == -1 && width == -1 && height == -1 {
|
||||
return
|
||||
}
|
||||
w.setMinMaxSize(0, 0, width*scale, height*scale)
|
||||
w.setSize(width*scale, height*scale)
|
||||
C.gtk_window_fullscreen(w.gtkWindow())
|
||||
w.setRelativePosition(0, 0)
|
||||
}
|
||||
|
||||
func windowFullscreen(window pointer) {
|
||||
C.gtk_window_fullscreen((*C.GtkWindow)(window))
|
||||
}
|
||||
|
||||
func windowGetCurrentMonitor(window pointer) *C.GdkMonitor {
|
||||
func (w *linuxWebviewWindow) getCurrentMonitor() *C.GdkMonitor {
|
||||
// Get the monitor that the window is currently on
|
||||
display := C.gtk_widget_get_display((*C.GtkWidget)(window))
|
||||
gdk_window := C.gtk_widget_get_window((*C.GtkWidget)(window))
|
||||
if gdk_window == nil {
|
||||
display := C.gtk_widget_get_display(w.gtkWidget())
|
||||
gdkWindow := C.gtk_widget_get_window(w.gtkWidget())
|
||||
if gdkWindow == nil {
|
||||
return nil
|
||||
}
|
||||
return C.gdk_display_get_monitor_at_window(display, gdk_window)
|
||||
return C.gdk_display_get_monitor_at_window(display, gdkWindow)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) getCurrentMonitorGeometry() (x int, y int, width int, height int, scale int) {
|
||||
monitor := windowGetCurrentMonitor(w.window)
|
||||
monitor := w.getCurrentMonitor()
|
||||
if monitor == nil {
|
||||
return -1, -1, -1, -1, 1
|
||||
}
|
||||
@ -727,10 +737,10 @@ func (w *linuxWebviewWindow) getCurrentMonitorGeometry() (x int, y int, width in
|
||||
return int(result.x), int(result.y), int(result.width), int(result.height), scale
|
||||
}
|
||||
|
||||
func windowGetSize(window pointer) (int, int) {
|
||||
func (w *linuxWebviewWindow) size() (int, int) {
|
||||
var windowWidth C.int
|
||||
var windowHeight C.int
|
||||
C.gtk_window_get_size((*C.GtkWindow)(window), &windowWidth, &windowHeight)
|
||||
C.gtk_window_get_size(w.gtkWindow(), &windowWidth, &windowHeight)
|
||||
return int(windowWidth), int(windowHeight)
|
||||
}
|
||||
|
||||
@ -738,7 +748,7 @@ func (w *linuxWebviewWindow) relativePosition() (int, int) {
|
||||
x, y := w.absolutePosition()
|
||||
// The position must be relative to the screen it is on
|
||||
// We need to get the screen it is on
|
||||
monitor := windowGetCurrentMonitor(w.window)
|
||||
monitor := w.getCurrentMonitor()
|
||||
geometry := C.GdkRectangle{}
|
||||
C.gdk_monitor_get_geometry(monitor, &geometry)
|
||||
x = x - int(geometry.x)
|
||||
@ -1014,7 +1024,7 @@ func (w *linuxWebviewWindow) setupSignalHandlers(emit func(e events.WindowEventT
|
||||
C.signal_connect(wv, c.String("key-press-event"), C.onKeyPressEvent, winID)
|
||||
}
|
||||
|
||||
func windowShowDevTools(webview pointer) {
|
||||
func openDevTools(webview pointer) {
|
||||
inspector := C.webkit_web_view_get_inspector((*C.WebKitWebView)(webview))
|
||||
C.webkit_web_inspector_show(inspector)
|
||||
}
|
||||
@ -1029,7 +1039,7 @@ func (w *linuxWebviewWindow) startDrag() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func windowToggleDevTools(webview pointer) {
|
||||
func enableDevTools(webview pointer) {
|
||||
settings := C.webkit_web_view_get_settings((*C.WebKitWebView)(webview))
|
||||
enabled := C.webkit_settings_get_enable_developer_extras(settings)
|
||||
switch enabled {
|
||||
|
@ -976,7 +976,7 @@ func windowSetupSignalHandlers(windowId uint, window, webview pointer, emit func
|
||||
*/
|
||||
}
|
||||
|
||||
func windowToggleDevTools(webview pointer) {
|
||||
func windowOpenDevTools(webview pointer) {
|
||||
settings := webkitWebViewGetSettings(pointer(webview))
|
||||
webkitSettingsSetEnableDeveloperExtras(
|
||||
settings,
|
||||
|
@ -167,8 +167,8 @@ func newRole(role Role) *MenuItem {
|
||||
return newForceReloadMenuItem()
|
||||
case ToggleFullscreen:
|
||||
return newToggleFullscreenMenuItem()
|
||||
case ShowDevTools:
|
||||
return newShowDevToolsMenuItem()
|
||||
case OpenDevTools:
|
||||
return newOpenDevToolsMenuItem()
|
||||
case ResetZoom:
|
||||
return newZoomResetMenuItem()
|
||||
case ZoomIn:
|
||||
|
@ -576,17 +576,6 @@ func newToggleFullscreenMenuItem() *MenuItem {
|
||||
return result
|
||||
}
|
||||
|
||||
func newToggleDevToolsMenuItem() *MenuItem {
|
||||
return newMenuItem("Toggle Developer Tools").
|
||||
SetAccelerator("Alt+Command+I").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ToggleDevTools()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newZoomResetMenuItem() *MenuItem {
|
||||
// reset zoom menu item
|
||||
return newMenuItem("Actual Size").
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
package application
|
||||
|
||||
func newShowDevToolsMenuItem() *MenuItem {
|
||||
return newMenuItem("Show Developer Tools").
|
||||
func newOpenDevToolsMenuItem() *MenuItem {
|
||||
return newMenuItem("Open Developer Tools").
|
||||
SetAccelerator("Alt+Command+I").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ToggleDevTools()
|
||||
currentWindow.OpenDevTools()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -294,17 +294,6 @@ func newToggleFullscreenMenuItem() *MenuItem {
|
||||
return result
|
||||
}
|
||||
|
||||
func newToggleDevToolsMenuItem() *MenuItem {
|
||||
return newMenuItem("Toggle Developer Tools").
|
||||
SetAccelerator("Alt+Command+I").
|
||||
OnClick(func(ctx *Context) {
|
||||
currentWindow := globalApplication.CurrentWindow()
|
||||
if currentWindow != nil {
|
||||
currentWindow.ToggleDevTools()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newZoomResetMenuItem() *MenuItem {
|
||||
// reset zoom menu item
|
||||
return newMenuItem("Actual Size").
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
package application
|
||||
|
||||
func newShowDevToolsMenuItem() *MenuItem {
|
||||
func newOpenDevToolsMenuItem() *MenuItem {
|
||||
return nil
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ const (
|
||||
Close Role = iota
|
||||
Reload Role = iota
|
||||
ForceReload Role = iota
|
||||
ShowDevTools Role = iota
|
||||
OpenDevTools Role = iota
|
||||
ResetZoom Role = iota
|
||||
ZoomIn Role = iota
|
||||
ZoomOut Role = iota
|
||||
|
@ -3,5 +3,5 @@
|
||||
package application
|
||||
|
||||
func addDevToolMenuItem(viewMenu *Menu) {
|
||||
viewMenu.AddRole(ShowDevTools)
|
||||
viewMenu.AddRole(OpenDevTools)
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ type (
|
||||
destroy()
|
||||
reload()
|
||||
forceReload()
|
||||
toggleDevTools()
|
||||
openDevTools()
|
||||
zoomReset()
|
||||
zoomIn()
|
||||
zoomOut()
|
||||
@ -817,11 +817,11 @@ func (w *WebviewWindow) ToggleMaximise() {
|
||||
})
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) ToggleDevTools() {
|
||||
func (w *WebviewWindow) OpenDevTools() {
|
||||
if w.impl == nil && !w.isDestroyed() {
|
||||
return
|
||||
}
|
||||
InvokeSync(w.impl.toggleDevTools)
|
||||
InvokeSync(w.impl.openDevTools)
|
||||
}
|
||||
|
||||
// ZoomReset resets the zoom level of the webview content to 100%
|
||||
|
@ -761,8 +761,6 @@ import (
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
)
|
||||
|
||||
var showDevTools = func(window unsafe.Pointer) {}
|
||||
|
||||
type macosWebviewWindow struct {
|
||||
nsWindow unsafe.Pointer
|
||||
parent *WebviewWindow
|
||||
@ -906,8 +904,8 @@ func (w *macosWebviewWindow) zoomReset() {
|
||||
C.windowZoomReset(w.nsWindow)
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) toggleDevTools() {
|
||||
showDevTools(w.nsWindow)
|
||||
func (w *macosWebviewWindow) openDevTools() {
|
||||
openDevTools(w.nsWindow)
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) reload() {
|
||||
|
@ -19,15 +19,7 @@ package application
|
||||
- (_WKInspector *)_inspector;
|
||||
@end
|
||||
|
||||
//void showDevTools(void *window) {
|
||||
// // get main window
|
||||
// WebviewWindow* nsWindow = (WebviewWindow*)window;
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [nsWindow.webView._inspector show];
|
||||
// });
|
||||
//}
|
||||
|
||||
void showDevTools(void *window) {
|
||||
void openDevTools(void *window) {
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (@available(macOS 12.0, *)) {
|
||||
@ -55,12 +47,9 @@ void windowEnableDevTools(void* nsWindow) {
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func init() {
|
||||
showDevTools = func(window unsafe.Pointer) {
|
||||
C.showDevTools(window)
|
||||
}
|
||||
func (w *macosWebviewWindow) openDevTools() {
|
||||
openDevTools(w.nsWindow)
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) enableDevTools() {
|
||||
|
@ -3,3 +3,4 @@
|
||||
package application
|
||||
|
||||
func (w *macosWebviewWindow) enableDevTools() {}
|
||||
func (w *macosWebviewWindow) openDevTools() {}
|
||||
|
@ -12,8 +12,6 @@ import (
|
||||
"math"
|
||||
)
|
||||
|
||||
var showDevTools = func(window pointer) {}
|
||||
|
||||
type dragInfo struct {
|
||||
XRoot int
|
||||
YRoot int
|
||||
@ -103,19 +101,6 @@ func (w *linuxWebviewWindow) disableSizeConstraints() {
|
||||
w.setMinMaxSize(x, y, width*scale, height*scale)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) fullscreen() {
|
||||
w.maximise()
|
||||
//w.lastWidth, w.lastHeight = w.size()
|
||||
x, y, width, height, scale := w.getCurrentMonitorGeometry()
|
||||
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()
|
||||
}
|
||||
@ -146,7 +131,7 @@ func (w *linuxWebviewWindow) center() {
|
||||
if x == -1 && y == -1 && width == -1 && height == -1 {
|
||||
return
|
||||
}
|
||||
windowWidth, windowHeight := windowGetSize(w.window)
|
||||
windowWidth, windowHeight := w.size()
|
||||
|
||||
newX := ((width - windowWidth) / 2) + x
|
||||
newY := ((height - windowHeight) / 2) + y
|
||||
@ -195,18 +180,6 @@ func (w *linuxWebviewWindow) setMaxSize(width, height int) {
|
||||
w.setMinMaxSize(w.parent.options.MinWidth, w.parent.options.MinHeight, width, height)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) showDevTools() {
|
||||
windowShowDevTools(w.webview)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) toggleDevTools() {
|
||||
showDevTools(w.webview)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) size() (int, int) {
|
||||
return windowGetSize(w.window)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setRelativePosition(x, y int) {
|
||||
mx, my, _, _, _ := w.getCurrentMonitorGeometry()
|
||||
w.move(x+mx, y+my)
|
||||
@ -331,27 +304,13 @@ func (w *linuxWebviewWindow) run() {
|
||||
}
|
||||
}
|
||||
if w.parent.options.DevToolsEnabled || globalApplication.isDebugMode {
|
||||
w.toggleDevTools()
|
||||
w.enableDevTools()
|
||||
if w.parent.options.OpenInspectorOnStartup {
|
||||
w.showDevTools()
|
||||
w.openDevTools()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
11
v3/pkg/application/webview_window_linux_dev.go
Normal file
11
v3/pkg/application/webview_window_linux_dev.go
Normal file
@ -0,0 +1,11 @@
|
||||
//go:build linux && !production
|
||||
|
||||
package application
|
||||
|
||||
func (w *linuxWebviewWindow) openDevTools() {
|
||||
openDevTools(w.webview)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) enableDevTools() {
|
||||
enableDevTools(w.webview)
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
//go:build linux && !production
|
||||
|
||||
package application
|
||||
|
||||
func init() {
|
||||
showDevTools = func(wv pointer) {
|
||||
windowToggleDevTools(wv)
|
||||
}
|
||||
}
|
7
v3/pkg/application/webview_window_linux_production.go
Normal file
7
v3/pkg/application/webview_window_linux_production.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build linux && production && !devtools
|
||||
|
||||
package application
|
||||
|
||||
func (w *linuxWebviewWindow) openDevTools() {}
|
||||
|
||||
func (w *linuxWebviewWindow) enableDevTools() {}
|
@ -4,7 +4,7 @@ package application
|
||||
|
||||
import "github.com/wailsapp/go-webview2/pkg/edge"
|
||||
|
||||
func (w *windowsWebviewWindow) toggleDevTools() {
|
||||
func (w *windowsWebviewWindow) openDevTools() {
|
||||
w.chromium.OpenDevToolsWindow()
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ package application
|
||||
|
||||
import "github.com/wailsapp/go-webview2/pkg/edge"
|
||||
|
||||
func (w *windowsWebviewWindow) toggleDevTools() {}
|
||||
func (w *windowsWebviewWindow) openDevTools() {}
|
||||
|
||||
func (w *windowsWebviewWindow) enableDevTools(settings *edge.ICoreWebViewSettings) {
|
||||
err := settings.PutAreDevToolsEnabled(false)
|
||||
|
@ -65,7 +65,7 @@ type Window interface {
|
||||
SetZoom(magnification float64) Window
|
||||
Show() Window
|
||||
Size() (width int, height int)
|
||||
ToggleDevTools()
|
||||
OpenDevTools()
|
||||
ToggleFullscreen()
|
||||
ToggleMaximise()
|
||||
UnFullscreen()
|
||||
|
Loading…
Reference in New Issue
Block a user