mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 15:11:53 +08:00
[v2] Refactor devtools (better naming to remove confusion) (#2921)
This commit is contained in:
parent
db519de1cd
commit
34c725231c
@ -22,7 +22,7 @@ type App struct {
|
|||||||
debug bool
|
debug bool
|
||||||
|
|
||||||
// Indicates if the devtools is enabled
|
// Indicates if the devtools is enabled
|
||||||
devtools bool
|
devtoolsEnabled bool
|
||||||
|
|
||||||
// OnStartup/OnShutdown
|
// OnStartup/OnShutdown
|
||||||
startupCallback func(ctx context.Context)
|
startupCallback func(ctx context.Context)
|
||||||
|
@ -44,7 +44,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = context.WithValue(ctx, "debug", true)
|
ctx = context.WithValue(ctx, "debug", true)
|
||||||
ctx = context.WithValue(ctx, "devtools", true)
|
ctx = context.WithValue(ctx, "devtoolsEnabled", true)
|
||||||
|
|
||||||
// Set up logger
|
// Set up logger
|
||||||
myLogger := logger.New(appoptions.Logger)
|
myLogger := logger.New(appoptions.Logger)
|
||||||
@ -230,7 +230,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
|||||||
startupCallback: appoptions.OnStartup,
|
startupCallback: appoptions.OnStartup,
|
||||||
shutdownCallback: appoptions.OnShutdown,
|
shutdownCallback: appoptions.OnShutdown,
|
||||||
debug: true,
|
debug: true,
|
||||||
devtools: true,
|
devtoolsEnabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
result.options = appoptions
|
result.options = appoptions
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
|
// Note: devtools flag is also added in debug builds
|
||||||
func IsDevtoolsEnabled() bool {
|
func IsDevtoolsEnabled() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
package app
|
package app
|
||||||
|
|
||||||
|
// Note: devtools flag is also added in debug builds
|
||||||
func IsDevtoolsEnabled() bool {
|
func IsDevtoolsEnabled() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
|||||||
options.MergeDefaults(appoptions)
|
options.MergeDefaults(appoptions)
|
||||||
|
|
||||||
debug := IsDebug()
|
debug := IsDebug()
|
||||||
devtools := IsDevtoolsEnabled()
|
devtoolsEnabled := IsDevtoolsEnabled()
|
||||||
ctx = context.WithValue(ctx, "debug", debug)
|
ctx = context.WithValue(ctx, "debug", debug)
|
||||||
ctx = context.WithValue(ctx, "devtools", devtools)
|
ctx = context.WithValue(ctx, "devtoolsEnabled", devtoolsEnabled)
|
||||||
|
|
||||||
// Set up logger
|
// Set up logger
|
||||||
myLogger := logger.New(appoptions.Logger)
|
myLogger := logger.New(appoptions.Logger)
|
||||||
@ -95,7 +95,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
|||||||
startupCallback: appoptions.OnStartup,
|
startupCallback: appoptions.OnStartup,
|
||||||
shutdownCallback: appoptions.OnShutdown,
|
shutdownCallback: appoptions.OnShutdown,
|
||||||
debug: debug,
|
debug: debug,
|
||||||
devtools: devtools,
|
devtoolsEnabled: devtoolsEnabled,
|
||||||
options: appoptions,
|
options: appoptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#define WindowStartsMinimised 2
|
#define WindowStartsMinimised 2
|
||||||
#define WindowStartsFullscreen 3
|
#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 defaultContextMenu, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled);
|
||||||
void Run(void*, const char* url);
|
void Run(void*, const char* url);
|
||||||
|
|
||||||
void SetTitle(void* ctx, const char *title);
|
void SetTitle(void* ctx, const char *title);
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
#import "WailsMenu.h"
|
#import "WailsMenu.h"
|
||||||
#import "WailsMenuItem.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 defaultContextMenu, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled) {
|
||||||
|
|
||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
WailsContext *result = [WailsContext new];
|
WailsContext *result = [WailsContext new];
|
||||||
|
|
||||||
result.devtools = devtools;
|
result.devtoolsEnabled = devtoolsEnabled;
|
||||||
result.defaultContextMenu = defaultContextMenu;
|
result.defaultContextMenu = defaultContextMenu;
|
||||||
|
|
||||||
if ( windowStartState == WindowStartsFullscreen ) {
|
if ( windowStartState == WindowStartsFullscreen ) {
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
@property bool alwaysOnTop;
|
@property bool alwaysOnTop;
|
||||||
|
|
||||||
@property bool devtools;
|
@property bool devtoolsEnabled;
|
||||||
@property bool defaultContextMenu;
|
@property bool defaultContextMenu;
|
||||||
|
|
||||||
@property (retain) WKUserContentController* userContentController;
|
@property (retain) WKUserContentController* userContentController;
|
||||||
|
@ -225,7 +225,7 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
|||||||
[userContentController addScriptMessageHandler:self name:@"external"];
|
[userContentController addScriptMessageHandler:self name:@"external"];
|
||||||
config.userContentController = userContentController;
|
config.userContentController = userContentController;
|
||||||
self.userContentController = userContentController;
|
self.userContentController = userContentController;
|
||||||
if (self.devtools) {
|
if (self.devtoolsEnabled) {
|
||||||
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
|
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
|
||||||
} else if (!self.defaultContextMenu) {
|
} else if (!self.defaultContextMenu) {
|
||||||
// Disable default context menus
|
// Disable default context menus
|
||||||
|
@ -47,7 +47,7 @@ type Frontend struct {
|
|||||||
frontendOptions *options.App
|
frontendOptions *options.App
|
||||||
logger *logger.Logger
|
logger *logger.Logger
|
||||||
debug bool
|
debug bool
|
||||||
devtools bool
|
devtoolsEnabled bool
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
assets *assetserver.AssetServer
|
assets *assetserver.AssetServer
|
||||||
@ -154,16 +154,16 @@ func (f *Frontend) Run(ctx context.Context) error {
|
|||||||
f.ctx = ctx
|
f.ctx = ctx
|
||||||
|
|
||||||
var _debug = ctx.Value("debug")
|
var _debug = ctx.Value("debug")
|
||||||
var _devtools = ctx.Value("devtools")
|
var _devtoolsEnabled = ctx.Value("devtoolsEnabled")
|
||||||
|
|
||||||
if _debug != nil {
|
if _debug != nil {
|
||||||
f.debug = _debug.(bool)
|
f.debug = _debug.(bool)
|
||||||
}
|
}
|
||||||
if _devtools != nil {
|
if _devtoolsEnabled != nil {
|
||||||
f.devtools = _devtools.(bool)
|
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 = mainWindow
|
||||||
f.mainWindow.Center()
|
f.mainWindow.Center()
|
||||||
|
|
||||||
|
@ -215,11 +215,11 @@ int main(int argc, const char * argv[]) {
|
|||||||
int hideWindowOnClose = 0;
|
int hideWindowOnClose = 0;
|
||||||
const char* appearance = "NSAppearanceNameDarkAqua";
|
const char* appearance = "NSAppearanceNameDarkAqua";
|
||||||
int windowIsTranslucent = 1;
|
int windowIsTranslucent = 1;
|
||||||
int devtools = 1;
|
int devtoolsEnabled = 1;
|
||||||
int defaultContextMenu = 1;
|
int defaultContextMenu = 1;
|
||||||
int windowStartState = 0;
|
int windowStartState = 0;
|
||||||
int startsHidden = 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, defaultContextMenu, windowStartState,
|
||||||
startsHidden, 400, 400, 600, 600, false);
|
startsHidden, 400, 400, 600, 600, false);
|
||||||
SetBackgroundColour(result, 255, 0, 0, 255);
|
SetBackgroundColour(result, 255, 0, 0, 255);
|
||||||
void *m = NewMenu("");
|
void *m = NewMenu("");
|
||||||
|
@ -110,7 +110,7 @@ type Frontend struct {
|
|||||||
frontendOptions *options.App
|
frontendOptions *options.App
|
||||||
logger *logger.Logger
|
logger *logger.Logger
|
||||||
debug bool
|
debug bool
|
||||||
devtools bool
|
devtoolsEnabled bool
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
assets *assetserver.AssetServer
|
assets *assetserver.AssetServer
|
||||||
@ -182,16 +182,16 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
|
|||||||
go result.startMessageProcessor()
|
go result.startMessageProcessor()
|
||||||
|
|
||||||
var _debug = ctx.Value("debug")
|
var _debug = ctx.Value("debug")
|
||||||
var _devtools = ctx.Value("devtools")
|
var _devtoolsEnabled = ctx.Value("devtoolsEnabled")
|
||||||
|
|
||||||
if _debug != nil {
|
if _debug != nil {
|
||||||
result.debug = _debug.(bool)
|
result.debug = _debug.(bool)
|
||||||
}
|
}
|
||||||
if _devtools != nil {
|
if _devtoolsEnabled != nil {
|
||||||
result.devtools = _devtools.(bool)
|
result.devtoolsEnabled = _devtoolsEnabled.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.mainWindow = NewWindow(appoptions, result.debug, result.devtools)
|
result.mainWindow = NewWindow(appoptions, result.debug, result.devtoolsEnabled)
|
||||||
|
|
||||||
C.install_signal_handlers()
|
C.install_signal_handlers()
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func gtkBool(input bool) C.gboolean {
|
|||||||
type Window struct {
|
type Window struct {
|
||||||
appoptions *options.App
|
appoptions *options.App
|
||||||
debug bool
|
debug bool
|
||||||
devtools bool
|
devtoolsEnabled bool
|
||||||
gtkWindow unsafe.Pointer
|
gtkWindow unsafe.Pointer
|
||||||
contentManager unsafe.Pointer
|
contentManager unsafe.Pointer
|
||||||
webview unsafe.Pointer
|
webview unsafe.Pointer
|
||||||
@ -56,17 +56,17 @@ func bool2Cint(value bool) C.int {
|
|||||||
return C.int(0)
|
return C.int(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWindow(appoptions *options.App, debug bool, devtools bool) *Window {
|
func NewWindow(appoptions *options.App, debug bool, devtoolsEnabled bool) *Window {
|
||||||
validateWebKit2Version(appoptions)
|
validateWebKit2Version(appoptions)
|
||||||
|
|
||||||
result := &Window{
|
result := &Window{
|
||||||
appoptions: appoptions,
|
appoptions: appoptions,
|
||||||
debug: debug,
|
debug: debug,
|
||||||
devtools: devtools,
|
devtoolsEnabled: devtoolsEnabled,
|
||||||
minHeight: appoptions.MinHeight,
|
minHeight: appoptions.MinHeight,
|
||||||
minWidth: appoptions.MinWidth,
|
minWidth: appoptions.MinWidth,
|
||||||
maxHeight: appoptions.MaxHeight,
|
maxHeight: appoptions.MaxHeight,
|
||||||
maxWidth: appoptions.MaxWidth,
|
maxWidth: appoptions.MaxWidth,
|
||||||
}
|
}
|
||||||
|
|
||||||
gtkWindow := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
gtkWindow := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
||||||
@ -103,7 +103,7 @@ func NewWindow(appoptions *options.App, debug bool, devtools bool) *Window {
|
|||||||
defer C.free(unsafe.Pointer(buttonPressedName))
|
defer C.free(unsafe.Pointer(buttonPressedName))
|
||||||
C.ConnectButtons(unsafe.Pointer(webview))
|
C.ConnectButtons(unsafe.Pointer(webview))
|
||||||
|
|
||||||
if devtools {
|
if devtoolsEnabled {
|
||||||
C.DevtoolsEnabled(unsafe.Pointer(webview), C.int(1), C.bool(debug && appoptions.Debug.OpenInspectorOnStartup))
|
C.DevtoolsEnabled(unsafe.Pointer(webview), C.int(1), C.bool(debug && appoptions.Debug.OpenInspectorOnStartup))
|
||||||
// Install Ctrl-Shift-F12 hotkey to call ShowInspector
|
// Install Ctrl-Shift-F12 hotkey to call ShowInspector
|
||||||
C.InstallF12Hotkey(unsafe.Pointer(gtkWindow))
|
C.InstallF12Hotkey(unsafe.Pointer(gtkWindow))
|
||||||
|
@ -48,7 +48,7 @@ type Frontend struct {
|
|||||||
logger *logger.Logger
|
logger *logger.Logger
|
||||||
chromium *edge.Chromium
|
chromium *edge.Chromium
|
||||||
debug bool
|
debug bool
|
||||||
devtools bool
|
devtoolsEnabled bool
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
assets *assetserver.AssetServer
|
assets *assetserver.AssetServer
|
||||||
@ -143,13 +143,13 @@ func (f *Frontend) Run(ctx context.Context) error {
|
|||||||
f.mainWindow = mainWindow
|
f.mainWindow = mainWindow
|
||||||
|
|
||||||
var _debug = ctx.Value("debug")
|
var _debug = ctx.Value("debug")
|
||||||
var _devtools = ctx.Value("devtools")
|
var _devtoolsEnabled = ctx.Value("devtoolsEnabled")
|
||||||
|
|
||||||
if _debug != nil {
|
if _debug != nil {
|
||||||
f.debug = _debug.(bool)
|
f.debug = _debug.(bool)
|
||||||
}
|
}
|
||||||
if _devtools != nil {
|
if _devtoolsEnabled != nil {
|
||||||
f.devtools = _devtools.(bool)
|
f.devtoolsEnabled = _devtoolsEnabled.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.WindowCenter()
|
f.WindowCenter()
|
||||||
@ -458,7 +458,7 @@ func (f *Frontend) setupChromium() {
|
|||||||
chromium.WebResourceRequestedCallback = f.processRequest
|
chromium.WebResourceRequestedCallback = f.processRequest
|
||||||
chromium.NavigationCompletedCallback = f.navigationCompleted
|
chromium.NavigationCompletedCallback = f.navigationCompleted
|
||||||
chromium.AcceleratorKeyCallback = func(vkey uint) bool {
|
chromium.AcceleratorKeyCallback = func(vkey uint) bool {
|
||||||
if vkey == w32.VK_F12 && f.devtools {
|
if vkey == w32.VK_F12 && f.devtoolsEnabled {
|
||||||
var keyState [256]byte
|
var keyState [256]byte
|
||||||
if w32.GetKeyboardState(keyState[:]) {
|
if w32.GetKeyboardState(keyState[:]) {
|
||||||
// Check if CTRL is pressed
|
// Check if CTRL is pressed
|
||||||
@ -511,11 +511,11 @@ func (f *Frontend) setupChromium() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
err = settings.PutAreDefaultContextMenusEnabled(f.devtools || f.frontendOptions.EnableDefaultContextMenu)
|
err = settings.PutAreDefaultContextMenusEnabled(f.devtoolsEnabled || f.frontendOptions.EnableDefaultContextMenu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
err = settings.PutAreDevToolsEnabled(f.devtools)
|
err = settings.PutAreDevToolsEnabled(f.devtoolsEnabled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user