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:
Lea Anthony
2024-01-21 20:52:32 +11:00
parent c82facd6ff
commit 6522657893
27 changed files with 326 additions and 165 deletions
@@ -0,0 +1,68 @@
//go:build darwin && (!production || devtools)
package application
/*
#cgo CFLAGS: -mmacosx-version-min=10.13 -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
#include "webview_window_darwin.h"
@interface _WKInspector : NSObject
- (void)show;
- (void)detach;
@end
@interface WKWebView ()
- (_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) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
dispatch_async(dispatch_get_main_queue(), ^{
if (@available(macOS 12.0, *)) {
WebviewWindow* nsWindow = (WebviewWindow*)window;
@try {
[nsWindow.webView._inspector show];
} @catch (NSException *exception) {
NSLog(@"Opening the inspector failed: %@", exception.reason);
return;
}
} else {
NSLog(@"Opening the inspector needs at least MacOS 12");
}
});
#endif
}
// Enable NSWindow devtools
void windowEnableDevTools(void* nsWindow) {
WebviewWindow* window = (WebviewWindow*)nsWindow;
// Enable devtools in webview
[window.webView.configuration.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
}
*/
import "C"
import "unsafe"
func init() {
showDevTools = func(window unsafe.Pointer) {
C.showDevTools(window)
}
}
func (w *macosWebviewWindow) enableDevTools() {
C.windowEnableDevTools(w.nsWindow)
}