mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Merge branch 'master' into v3-alpha
# Conflicts: # v2/internal/app/app_devtools.go # v2/internal/app/app_devtools_not.go
This commit is contained in:
@@ -44,14 +44,16 @@ func initialiseWatcher(cwd string) (*fsnotify.Watcher, error) {
|
||||
|
||||
func getIgnoreDirs(cwd string) []string {
|
||||
ignoreDirs := []string{filepath.Join(cwd, "build/*"), ".*", "node_modules"}
|
||||
|
||||
baseDir := filepath.Base(cwd)
|
||||
// Read .gitignore into ignoreDirs
|
||||
f, err := os.Open(filepath.Join(cwd, ".gitignore"))
|
||||
if err == nil {
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
ignoreDirs = append(ignoreDirs, line)
|
||||
if line != baseDir {
|
||||
ignoreDirs = append(ignoreDirs, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ require (
|
||||
github.com/leaanthony/go-ansi-parser v1.6.0
|
||||
github.com/leaanthony/gosod v1.0.3
|
||||
github.com/leaanthony/slicer v1.6.0
|
||||
github.com/leaanthony/u v1.1.0
|
||||
github.com/leaanthony/winicon v1.0.0
|
||||
github.com/matryer/is v1.4.0
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
|
||||
@@ -33,7 +34,7 @@ require (
|
||||
github.com/tc-hib/winres v0.1.5
|
||||
github.com/tidwall/sjson v1.1.7
|
||||
github.com/tkrajina/go-reflector v0.5.6
|
||||
github.com/wailsapp/go-webview2 v1.0.1
|
||||
github.com/wailsapp/go-webview2 v1.0.7
|
||||
github.com/wailsapp/mimetype v1.4.1
|
||||
github.com/wzshiming/ctc v1.2.3
|
||||
golang.org/x/mod v0.12.0
|
||||
|
||||
@@ -119,6 +119,10 @@ github.com/leaanthony/gosod v1.0.3/go.mod h1:BJ2J+oHsQIyIQpnLPjnqFGTMnOZXDbvWtRC
|
||||
github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5AzRtwV7m4AY=
|
||||
github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
|
||||
github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
|
||||
github.com/leaanthony/u v1.0.1 h1:tJLpf9EsuCgSB02ojRxg8KRqMgRN6mCTvFwI55kxRFE=
|
||||
github.com/leaanthony/u v1.0.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
|
||||
github.com/leaanthony/u v1.1.0 h1:2n0d2BwPVXSUq5yhe8lJPHdxevE2qK5G99PMStMZMaI=
|
||||
github.com/leaanthony/u v1.1.0/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
|
||||
github.com/leaanthony/winicon v1.0.0 h1:ZNt5U5dY71oEoKZ97UVwJRT4e+5xo5o/ieKuHuk8NqQ=
|
||||
github.com/leaanthony/winicon v1.0.0/go.mod h1:en5xhijl92aphrJdmRPlh4NI1L6wq3gEm0LpXAPghjU=
|
||||
github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c=
|
||||
@@ -214,8 +218,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
|
||||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
github.com/wailsapp/go-webview2 v1.0.1 h1:dEJIeEApW/MhO2tTMISZBFZPuW7kwrFA1NtgFB1z1II=
|
||||
github.com/wailsapp/go-webview2 v1.0.1/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
|
||||
github.com/wailsapp/go-webview2 v1.0.7 h1:s95+7irJsAsTy1RsjJ6N0cYX7tZ4gP7Uzawds0L2urs=
|
||||
github.com/wailsapp/go-webview2 v1.0.7/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
|
||||
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
|
||||
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
|
||||
github.com/wzshiming/ctc v1.2.3 h1:q+hW3IQNsjIlOFBTGZZZeIXTElFM4grF4spW/errh/c=
|
||||
|
||||
@@ -22,7 +22,7 @@ type App struct {
|
||||
debug bool
|
||||
|
||||
// Indicates if the devtools is enabled
|
||||
devtools bool
|
||||
devtoolsEnabled bool
|
||||
|
||||
// OnStartup/OnShutdown
|
||||
startupCallback func(ctx context.Context)
|
||||
|
||||
@@ -44,7 +44,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "debug", true)
|
||||
ctx = context.WithValue(ctx, "devtools", true)
|
||||
ctx = context.WithValue(ctx, "devtoolsEnabled", true)
|
||||
|
||||
// Set up logger
|
||||
myLogger := logger.New(appoptions.Logger)
|
||||
@@ -230,7 +230,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
||||
startupCallback: appoptions.OnStartup,
|
||||
shutdownCallback: appoptions.OnShutdown,
|
||||
debug: true,
|
||||
devtools: true,
|
||||
devtoolsEnabled: true,
|
||||
}
|
||||
|
||||
result.options = appoptions
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package app
|
||||
|
||||
// Note: devtools flag is also added in debug builds
|
||||
func IsDevtoolsEnabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package app
|
||||
|
||||
// Note: devtools flag is also added in debug builds
|
||||
func IsDevtoolsEnabled() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
||||
options.MergeDefaults(appoptions)
|
||||
|
||||
debug := IsDebug()
|
||||
devtools := IsDevtoolsEnabled()
|
||||
devtoolsEnabled := IsDevtoolsEnabled()
|
||||
ctx = context.WithValue(ctx, "debug", debug)
|
||||
ctx = context.WithValue(ctx, "devtools", devtools)
|
||||
ctx = context.WithValue(ctx, "devtoolsEnabled", devtoolsEnabled)
|
||||
|
||||
// Set up logger
|
||||
myLogger := logger.New(appoptions.Logger)
|
||||
@@ -95,7 +95,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
||||
startupCallback: appoptions.OnStartup,
|
||||
shutdownCallback: appoptions.OnShutdown,
|
||||
debug: debug,
|
||||
devtools: devtools,
|
||||
devtoolsEnabled: devtoolsEnabled,
|
||||
options: appoptions,
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
if (self.alwaysOnTop) {
|
||||
[self.mainWindow setLevel:NSStatusWindowLevel];
|
||||
[self.mainWindow setLevel:NSFloatingWindowLevel];
|
||||
}
|
||||
if ( !self.startHidden ) {
|
||||
[self.mainWindow makeKeyAndOrderFront:self];
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define WindowStartsMinimised 2
|
||||
#define WindowStartsFullscreen 3
|
||||
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtools, int defaultContextMenu, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled);
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences);
|
||||
void Run(void*, const char* url);
|
||||
|
||||
void SetTitle(void* ctx, const char *title);
|
||||
|
||||
@@ -14,20 +14,20 @@
|
||||
#import "WailsMenu.h"
|
||||
#import "WailsMenuItem.h"
|
||||
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtools, int defaultContextMenu, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled) {
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences) {
|
||||
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
WailsContext *result = [WailsContext new];
|
||||
|
||||
result.devtools = devtools;
|
||||
result.defaultContextMenu = defaultContextMenu;
|
||||
result.devtoolsEnabled = devtoolsEnabled;
|
||||
result.defaultContextMenuEnabled = defaultContextMenuEnabled;
|
||||
|
||||
if ( windowStartState == WindowStartsFullscreen ) {
|
||||
fullscreen = 1;
|
||||
}
|
||||
|
||||
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled];
|
||||
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled :preferences];
|
||||
[result SetTitle:safeInit(title)];
|
||||
[result Center];
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
|
||||
@property bool alwaysOnTop;
|
||||
|
||||
@property bool devtools;
|
||||
@property bool defaultContextMenu;
|
||||
@property bool devtoolsEnabled;
|
||||
@property bool defaultContextMenuEnabled;
|
||||
|
||||
@property (retain) WKUserContentController* userContentController;
|
||||
|
||||
@@ -55,7 +55,12 @@
|
||||
@property (retain) NSString* aboutTitle;
|
||||
@property (retain) NSString* aboutDescription;
|
||||
|
||||
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled;
|
||||
struct Preferences {
|
||||
bool *tabFocusesLinks;
|
||||
bool *textInteractionEnabled;
|
||||
};
|
||||
|
||||
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences;
|
||||
- (void) SetSize:(int)width :(int)height;
|
||||
- (void) SetPosition:(int)x :(int) y;
|
||||
- (void) SetMinSize:(int)minWidth :(int)minHeight;
|
||||
|
||||
@@ -136,7 +136,7 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled {
|
||||
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences {
|
||||
NSWindowStyleMask styleMask = 0;
|
||||
|
||||
if( !frameless ) {
|
||||
@@ -214,6 +214,16 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
||||
config.suppressesIncrementalRendering = true;
|
||||
config.applicationNameForUserAgent = @"wails.io";
|
||||
[config setURLSchemeHandler:self forURLScheme:@"wails"];
|
||||
|
||||
if (preferences.tabFocusesLinks != NULL) {
|
||||
config.preferences.tabFocusesLinks = *preferences.tabFocusesLinks;
|
||||
}
|
||||
|
||||
if (@available(macOS 11.3, *)) {
|
||||
if (preferences.textInteractionEnabled != NULL) {
|
||||
config.preferences.textInteractionEnabled = *preferences.textInteractionEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
// [config.preferences setValue:[NSNumber numberWithBool:true] forKey:@"developerExtrasEnabled"];
|
||||
|
||||
@@ -225,16 +235,18 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
||||
[userContentController addScriptMessageHandler:self name:@"external"];
|
||||
config.userContentController = userContentController;
|
||||
self.userContentController = userContentController;
|
||||
if (self.devtools) {
|
||||
|
||||
if (self.devtoolsEnabled) {
|
||||
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
|
||||
} else if (!self.defaultContextMenu) {
|
||||
}
|
||||
|
||||
if (!self.defaultContextMenuEnabled) {
|
||||
// Disable default context menus
|
||||
WKUserScript *initScript = [WKUserScript new];
|
||||
[initScript initWithSource:@"window.wails.flags.disableDefaultContextMenu = true;"
|
||||
injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
|
||||
forMainFrameOnly:false];
|
||||
[userContentController addUserScript:initScript];
|
||||
|
||||
}
|
||||
|
||||
self.webview = [WKWebView alloc];
|
||||
@@ -394,7 +406,7 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
||||
|
||||
- (void) SetAlwaysOnTop:(int)onTop {
|
||||
if (onTop) {
|
||||
[self.mainWindow setLevel:NSStatusWindowLevel];
|
||||
[self.mainWindow setLevel:NSFloatingWindowLevel];
|
||||
} else {
|
||||
[self.mainWindow setLevel:NSNormalWindowLevel];
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ type Frontend struct {
|
||||
frontendOptions *options.App
|
||||
logger *logger.Logger
|
||||
debug bool
|
||||
devtools bool
|
||||
devtoolsEnabled bool
|
||||
|
||||
// Assets
|
||||
assets *assetserver.AssetServer
|
||||
@@ -154,16 +154,16 @@ func (f *Frontend) Run(ctx context.Context) error {
|
||||
f.ctx = ctx
|
||||
|
||||
var _debug = ctx.Value("debug")
|
||||
var _devtools = ctx.Value("devtools")
|
||||
var _devtoolsEnabled = ctx.Value("devtoolsEnabled")
|
||||
|
||||
if _debug != nil {
|
||||
f.debug = _debug.(bool)
|
||||
}
|
||||
if _devtools != nil {
|
||||
f.devtools = _devtools.(bool)
|
||||
if _devtoolsEnabled != nil {
|
||||
f.devtoolsEnabled = _devtoolsEnabled.(bool)
|
||||
}
|
||||
|
||||
mainWindow := NewWindow(f.frontendOptions, f.debug, f.devtools)
|
||||
mainWindow := NewWindow(f.frontendOptions, f.debug, f.devtoolsEnabled)
|
||||
f.mainWindow = mainWindow
|
||||
f.mainWindow.Center()
|
||||
|
||||
@@ -323,6 +323,11 @@ func (f *Frontend) processMessage(message string) {
|
||||
return
|
||||
}
|
||||
|
||||
if message == "wails:openInspector" {
|
||||
showInspector(f.mainWindow.context)
|
||||
return
|
||||
}
|
||||
|
||||
//if strings.HasPrefix(message, "systemevent:") {
|
||||
// f.processSystemEvent(message)
|
||||
// return
|
||||
@@ -390,6 +395,6 @@ func processCallback(callbackID uint) {
|
||||
}
|
||||
|
||||
//export processURLRequest
|
||||
func processURLRequest(ctx unsafe.Pointer, wkURLSchemeTask unsafe.Pointer) {
|
||||
func processURLRequest(_ unsafe.Pointer, wkURLSchemeTask unsafe.Pointer) {
|
||||
requestBuffer <- webview.NewRequest(wkURLSchemeTask)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build darwin && !(dev || debug)
|
||||
//go:build darwin && !(dev || debug || devtools)
|
||||
|
||||
package darwin
|
||||
|
||||
@@ -6,6 +6,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func showInspector(context unsafe.Pointer) {
|
||||
func showInspector(_ unsafe.Pointer) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build darwin && (dev || debug)
|
||||
//go:build darwin && (dev || debug || devtools)
|
||||
|
||||
package darwin
|
||||
|
||||
@@ -11,6 +11,8 @@ package darwin
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "WailsContext.h"
|
||||
|
||||
extern void processMessage(const char *message);
|
||||
|
||||
@interface _WKInspector : NSObject
|
||||
- (void)show;
|
||||
- (void)detach;
|
||||
@@ -21,28 +23,44 @@ package darwin
|
||||
@end
|
||||
|
||||
void showInspector(void *inctx) {
|
||||
if (@available(macOS 12.0, *)) {
|
||||
WailsContext *ctx = (__bridge WailsContext*) inctx;
|
||||
ON_MAIN_THREAD(
|
||||
if (@available(macOS 12.0, *)) {
|
||||
WailsContext *ctx = (__bridge WailsContext*) inctx;
|
||||
|
||||
@try {
|
||||
[ctx.webview._inspector show];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Opening the inspector failed: %@", exception.reason);
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC);
|
||||
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
||||
// Detach must be deferred a little bit and is ignored directly after a show.
|
||||
@try {
|
||||
[ctx.webview._inspector detach];
|
||||
[ctx.webview._inspector show];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Detaching the inspector failed: %@", exception.reason);
|
||||
NSLog(@"Opening the inspector failed: %@", exception.reason);
|
||||
return;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
NSLog(@"Opening the inspector needs at least MacOS 12");
|
||||
}
|
||||
|
||||
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC);
|
||||
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
||||
// Detach must be deferred a little bit and is ignored directly after a show.
|
||||
@try {
|
||||
[ctx.webview._inspector detach];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Detaching the inspector failed: %@", exception.reason);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
NSLog(@"Opening the inspector needs at least MacOS 12");
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void setupF12hotkey() {
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent * _Nullable(NSEvent * _Nonnull event) {
|
||||
if (event.keyCode == 111 &&
|
||||
event.modifierFlags & NSEventModifierFlagFunction &&
|
||||
event.modifierFlags & NSEventModifierFlagCommand &&
|
||||
event.modifierFlags & NSEventModifierFlagShift) {
|
||||
processMessage("wails:openInspector");
|
||||
return nil;
|
||||
}
|
||||
return event;
|
||||
}];
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
@@ -50,6 +68,10 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
C.setupF12hotkey()
|
||||
}
|
||||
|
||||
func showInspector(context unsafe.Pointer) {
|
||||
C.showInspector(context)
|
||||
}
|
||||
|
||||
@@ -215,11 +215,11 @@ int main(int argc, const char * argv[]) {
|
||||
int hideWindowOnClose = 0;
|
||||
const char* appearance = "NSAppearanceNameDarkAqua";
|
||||
int windowIsTranslucent = 1;
|
||||
int devtools = 1;
|
||||
int defaultContextMenu = 1;
|
||||
int devtoolsEnabled = 1;
|
||||
int defaultContextMenuEnabled = 1;
|
||||
int windowStartState = 0;
|
||||
int startsHidden = 0;
|
||||
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtools, defaultContextMenu, windowStartState,
|
||||
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled, windowStartState,
|
||||
startsHidden, 400, 400, 600, 600, false);
|
||||
SetBackgroundColour(result, 255, 0, 0, 255);
|
||||
void *m = NewMenu("");
|
||||
|
||||
@@ -40,6 +40,11 @@ func bool2Cint(value bool) C.int {
|
||||
return C.int(0)
|
||||
}
|
||||
|
||||
func bool2CboolPtr(value bool) *C.bool {
|
||||
v := C.bool(value)
|
||||
return &v
|
||||
}
|
||||
|
||||
func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window {
|
||||
|
||||
c := NewCalloc()
|
||||
@@ -52,11 +57,12 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
|
||||
hideWindowOnClose := bool2Cint(frontendOptions.HideWindowOnClose)
|
||||
startsHidden := bool2Cint(frontendOptions.StartHidden)
|
||||
devtoolsEnabled := bool2Cint(devtools)
|
||||
defaultContextMenu := bool2Cint(frontendOptions.EnableDefaultContextMenu)
|
||||
defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu)
|
||||
|
||||
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
|
||||
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int
|
||||
var appearance, title *C.char
|
||||
var preferences C.struct_Preferences
|
||||
|
||||
width := C.int(frontendOptions.Width)
|
||||
height := C.int(frontendOptions.Height)
|
||||
@@ -80,6 +86,17 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
|
||||
titlebarAppearsTransparent = bool2Cint(mac.TitleBar.TitlebarAppearsTransparent)
|
||||
hideToolbarSeparator = bool2Cint(mac.TitleBar.HideToolbarSeparator)
|
||||
}
|
||||
|
||||
if mac.Preferences != nil {
|
||||
if mac.Preferences.TabFocusesLinks.IsSet() {
|
||||
preferences.tabFocusesLinks = bool2CboolPtr(mac.Preferences.TabFocusesLinks.Get())
|
||||
}
|
||||
|
||||
if mac.Preferences.TextInteractionEnabled.IsSet() {
|
||||
preferences.textInteractionEnabled = bool2CboolPtr(mac.Preferences.TextInteractionEnabled.Get())
|
||||
}
|
||||
}
|
||||
|
||||
windowIsTranslucent = bool2Cint(mac.WindowIsTranslucent)
|
||||
webviewIsTransparent = bool2Cint(mac.WebviewIsTransparent)
|
||||
|
||||
@@ -87,8 +104,8 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
|
||||
}
|
||||
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
|
||||
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
|
||||
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenu,
|
||||
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings)
|
||||
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled,
|
||||
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings, preferences)
|
||||
|
||||
// Create menu
|
||||
result := &Window{
|
||||
|
||||
@@ -110,7 +110,7 @@ type Frontend struct {
|
||||
frontendOptions *options.App
|
||||
logger *logger.Logger
|
||||
debug bool
|
||||
devtools bool
|
||||
devtoolsEnabled bool
|
||||
|
||||
// Assets
|
||||
assets *assetserver.AssetServer
|
||||
@@ -182,16 +182,16 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
|
||||
go result.startMessageProcessor()
|
||||
|
||||
var _debug = ctx.Value("debug")
|
||||
var _devtools = ctx.Value("devtools")
|
||||
var _devtoolsEnabled = ctx.Value("devtoolsEnabled")
|
||||
|
||||
if _debug != nil {
|
||||
result.debug = _debug.(bool)
|
||||
}
|
||||
if _devtools != nil {
|
||||
result.devtools = _devtools.(bool)
|
||||
if _devtoolsEnabled != nil {
|
||||
result.devtoolsEnabled = _devtoolsEnabled.(bool)
|
||||
}
|
||||
|
||||
result.mainWindow = NewWindow(appoptions, result.debug, result.devtools)
|
||||
result.mainWindow = NewWindow(appoptions, result.debug, result.devtoolsEnabled)
|
||||
|
||||
C.install_signal_handlers()
|
||||
|
||||
@@ -410,6 +410,11 @@ func (f *Frontend) processMessage(message string) {
|
||||
return
|
||||
}
|
||||
|
||||
if message == "wails:showInspector" {
|
||||
f.mainWindow.ShowInspector()
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(message, "resize:") {
|
||||
if !f.mainWindow.IsFullScreen() {
|
||||
sl := strings.Split(message, ":")
|
||||
|
||||
@@ -474,8 +474,7 @@ void DevtoolsEnabled(void *webview, int enabled, bool showInspector)
|
||||
|
||||
if (genabled && showInspector)
|
||||
{
|
||||
WebKitWebInspector *inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
|
||||
webkit_web_inspector_show(WEBKIT_WEB_INSPECTOR(inspector));
|
||||
ShowInspector(webview);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,3 +731,21 @@ GtkFileFilter *newFileFilter()
|
||||
g_object_ref(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ShowInspector(void *webview) {
|
||||
WebKitWebInspector *inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview));
|
||||
webkit_web_inspector_show(WEBKIT_WEB_INSPECTOR(inspector));
|
||||
}
|
||||
|
||||
void sendShowInspectorMessage() {
|
||||
processMessage("wails:showInspector");
|
||||
}
|
||||
|
||||
void InstallF12Hotkey(void *window)
|
||||
{
|
||||
// When the user presses Ctrl+Shift+F12, call ShowInspector
|
||||
GtkAccelGroup *accel_group = gtk_accel_group_new();
|
||||
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
|
||||
GClosure *closure = g_cclosure_new(G_CALLBACK(sendShowInspectorMessage), window, NULL);
|
||||
gtk_accel_group_connect(accel_group, GDK_KEY_F12, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE, closure);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user