Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Add -devtools production build flag #2725

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions v2/cmd/wails/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func buildApplication(f *flags.Build) error {
OutputFile: f.OutputFilename,
CleanBinDirectory: f.Clean,
Mode: f.GetBuildMode(),
Devtools: f.Debug || f.Devtools,
Pack: !f.NoPackage,
LDFlags: f.LdFlags,
Compiler: f.Compiler,
Expand All @@ -82,6 +83,7 @@ func buildApplication(f *flags.Build) error {
{"Compiler", f.GetCompilerPath()},
{"Skip Bindings", bool2Str(f.SkipBindings)},
{"Build Mode", f.GetBuildModeAsString()},
{"Devtools", bool2Str(buildOptions.Devtools)},
{"Frontend Directory", projectOptions.GetFrontendDir()},
{"Obfuscated", bool2Str(f.Obfuscated)},
}
Expand Down
1 change: 1 addition & 0 deletions v2/cmd/wails/flags/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Build struct {
ForceBuild bool `name:"f" description:"Force build of application"`
UpdateWailsVersionGoMod bool `name:"u" description:"Updates go.mod to use the same Wails version as the CLI"`
Debug bool `description:"Builds the application in debug mode"`
Devtools bool `description:"Enable Devtools in productions, Already enabled in debug mode (-debug)"`
NSIS bool `description:"Generate NSIS installer for Windows"`
TrimPath bool `description:"Remove all file system paths from the resulting executable"`
WindowsConsole bool `description:"Keep the console when building for Windows"`
Expand Down
1 change: 1 addition & 0 deletions v2/cmd/wails/flags/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (d *Dev) GenerateBuildOptions() *build.Options {
result := &build.Options{
OutputType: "dev",
Mode: build.Dev,
Devtools: true,
Arch: runtime.GOARCH,
Pack: true,
Platform: runtime.GOOS,
Expand Down
4 changes: 4 additions & 0 deletions v2/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"context"

"github.com/wailsapp/wails/v2/internal/frontend"
"github.com/wailsapp/wails/v2/internal/logger"
"github.com/wailsapp/wails/v2/internal/menumanager"
Expand All @@ -20,6 +21,9 @@ type App struct {
// Indicates if the app is in debug mode
debug bool

// Indicates if the devtools is enabled
devtools bool

// OnStartup/OnShutdown
startupCallback func(ctx context.Context)
shutdownCallback func(ctx context.Context)
Expand Down
5 changes: 4 additions & 1 deletion v2/internal/app/app_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func (a *App) Run() error {
func CreateApp(appoptions *options.App) (*App, error) {
var err error

ctx := context.WithValue(context.Background(), "debug", true)
ctx := context.Background()
ctx = context.WithValue(ctx, "debug", true)
ctx = context.WithValue(ctx, "devtools", true)

// Set up logger
myLogger := logger.New(appoptions.Logger)
Expand Down Expand Up @@ -228,6 +230,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
startupCallback: appoptions.OnStartup,
shutdownCallback: appoptions.OnShutdown,
debug: true,
devtools: true,
}

result.options = appoptions
Expand Down
7 changes: 7 additions & 0 deletions v2/internal/app/app_devtools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build devtools

package app

func IsDevtoolsEnabled() bool {
return true
}
7 changes: 7 additions & 0 deletions v2/internal/app/app_devtools_not.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !devtools

package app

func IsDevtoolsEnabled() bool {
return false
}
3 changes: 3 additions & 0 deletions v2/internal/app/app_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ func CreateApp(appoptions *options.App) (*App, error) {
options.MergeDefaults(appoptions)

debug := IsDebug()
devtools := IsDevtoolsEnabled()
ctx = context.WithValue(ctx, "debug", debug)
ctx = context.WithValue(ctx, "devtools", devtools)

// Set up logger
myLogger := logger.New(appoptions.Logger)
Expand Down Expand Up @@ -93,6 +95,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
startupCallback: appoptions.OnStartup,
shutdownCallback: appoptions.OnShutdown,
debug: debug,
devtools: devtools,
options: appoptions,
}

Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/darwin/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 debug, 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 devtools, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled);
void Run(void*, const char* url);

void SetTitle(void* ctx, const char *title);
Expand Down
4 changes: 2 additions & 2 deletions v2/internal/frontend/desktop/darwin/Application.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#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 debug, 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 devtools, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled) {

[NSApplication sharedApplication];

WailsContext *result = [WailsContext new];

result.debug = debug;
result.devtools = devtools;

if ( windowStartState == WindowStartsFullscreen ) {
fullscreen = 1;
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/darwin/WailsContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

@property bool alwaysOnTop;

@property bool debug;
@property bool devtools;

@property (retain) WKUserContentController* userContentController;

Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/darwin/WailsContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable
[userContentController addScriptMessageHandler:self name:@"external"];
config.userContentController = userContentController;
self.userContentController = userContentController;
if (self.debug) {
if (self.devtools) {
[config.preferences setValue:@YES forKey:@"developerExtrasEnabled"];
} else {
// Disable default context menus
Expand Down
9 changes: 8 additions & 1 deletion v2/internal/frontend/desktop/darwin/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Frontend struct {
frontendOptions *options.App
logger *logger.Logger
debug bool
devtools bool

// Assets
assets *assetserver.AssetServer
Expand Down Expand Up @@ -151,12 +152,18 @@ func (f *Frontend) WindowSetDarkTheme() {

func (f *Frontend) Run(ctx context.Context) error {
f.ctx = ctx

var _debug = ctx.Value("debug")
var _devtools = ctx.Value("devtools")

if _debug != nil {
f.debug = _debug.(bool)
}
if _devtools != nil {
f.devtools = _devtools.(bool)
}

mainWindow := NewWindow(f.frontendOptions, f.debug)
mainWindow := NewWindow(f.frontendOptions, f.debug, f.devtools)
f.mainWindow = mainWindow
f.mainWindow.Center()

Expand Down
4 changes: 2 additions & 2 deletions v2/internal/frontend/desktop/darwin/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ int main(int argc, const char * argv[]) {
int hideWindowOnClose = 0;
const char* appearance = "NSAppearanceNameDarkAqua";
int windowIsTranslucent = 1;
int debug = 1;
int devtools = 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, debug, windowStartState,
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtools, windowStartState,
startsHidden, 400, 400, 600, 600, false);
SetBackgroundColour(result, 255, 0, 0, 255);
void *m = NewMenu("");
Expand Down
8 changes: 4 additions & 4 deletions v2/internal/frontend/desktop/darwin/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func bool2Cint(value bool) C.int {
return C.int(0)
}

func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window {

c := NewCalloc()
defer c.Free()
Expand All @@ -51,7 +51,7 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
alwaysOnTop := bool2Cint(frontendOptions.AlwaysOnTop)
hideWindowOnClose := bool2Cint(frontendOptions.HideWindowOnClose)
startsHidden := bool2Cint(frontendOptions.StartHidden)
debug := bool2Cint(debugMode)
devtoolsEnabled := bool2Cint(devtools)

var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int
Expand Down Expand Up @@ -86,7 +86,7 @@ func NewWindow(frontendOptions *options.App, debugMode 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, debug, windowStartState, startsHidden,
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, windowStartState, startsHidden,
minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings)

// Create menu
Expand Down Expand Up @@ -114,7 +114,7 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
result.SetApplicationMenu(frontendOptions.Menu)
}

if debugMode && frontendOptions.Debug.OpenInspectorOnStartup {
if debug && frontendOptions.Debug.OpenInspectorOnStartup {
showInspector(result.context)
}
return result
Expand Down
9 changes: 8 additions & 1 deletion v2/internal/frontend/desktop/linux/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Frontend struct {
frontendOptions *options.App
logger *logger.Logger
debug bool
devtools bool

// Assets
assets *assetserver.AssetServer
Expand Down Expand Up @@ -176,10 +177,16 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
go result.startMessageProcessor()

var _debug = ctx.Value("debug")
var _devtools = ctx.Value("devtools")

if _debug != nil {
result.debug = _debug.(bool)
}
result.mainWindow = NewWindow(appoptions, result.debug)
if _devtools != nil {
result.devtools = _devtools.(bool)
}

result.mainWindow = NewWindow(appoptions, result.debug, result.devtools)

C.install_signal_handlers()

Expand Down
8 changes: 5 additions & 3 deletions v2/internal/frontend/desktop/linux/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func gtkBool(input bool) C.gboolean {
type Window struct {
appoptions *options.App
debug bool
devtools bool
gtkWindow unsafe.Pointer
contentManager unsafe.Pointer
webview unsafe.Pointer
Expand All @@ -54,12 +55,13 @@ func bool2Cint(value bool) C.int {
return C.int(0)
}

func NewWindow(appoptions *options.App, debug bool) *Window {
func NewWindow(appoptions *options.App, debug bool, devtools bool) *Window {
validateWebKit2Version(appoptions)

result := &Window{
appoptions: appoptions,
debug: debug,
devtools: devtools,
minHeight: appoptions.MinHeight,
minWidth: appoptions.MinWidth,
maxHeight: appoptions.MaxHeight,
Expand Down Expand Up @@ -95,8 +97,8 @@ func NewWindow(appoptions *options.App, debug bool) *Window {
defer C.free(unsafe.Pointer(buttonPressedName))
C.ConnectButtons(unsafe.Pointer(webview))

if debug {
C.DevtoolsEnabled(unsafe.Pointer(webview), C.int(1), C.bool(appoptions.Debug.OpenInspectorOnStartup))
if devtools {
C.DevtoolsEnabled(unsafe.Pointer(webview), C.int(1), C.bool(debug && appoptions.Debug.OpenInspectorOnStartup))
} else {
C.DisableContextMenu(unsafe.Pointer(webview))
}
Expand Down
10 changes: 8 additions & 2 deletions v2/internal/frontend/desktop/windows/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Frontend struct {
logger *logger.Logger
chromium *edge.Chromium
debug bool
devtools bool

// Assets
assets *assetserver.AssetServer
Expand Down Expand Up @@ -142,9 +143,14 @@ func (f *Frontend) Run(ctx context.Context) error {
f.mainWindow = mainWindow

var _debug = ctx.Value("debug")
var _devtools = ctx.Value("devtools")

if _debug != nil {
f.debug = _debug.(bool)
}
if _devtools != nil {
f.devtools = _devtools.(bool)
}

f.WindowCenter()
f.setupChromium()
Expand Down Expand Up @@ -489,11 +495,11 @@ func (f *Frontend) setupChromium() {
if err != nil {
log.Fatal(err)
}
err = settings.PutAreDefaultContextMenusEnabled(f.debug)
err = settings.PutAreDefaultContextMenusEnabled(f.devtools)
if err != nil {
log.Fatal(err)
}
err = settings.PutAreDevToolsEnabled(f.debug)
err = settings.PutAreDevToolsEnabled(f.devtools)
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions v2/pkg/commands/build/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func (b *BaseBuilder) CompileProject(options *Options) error {
tags.Add("debug")
}

// This options allows you to enable devtools in production build (not dev build as it's always enabled there)
if options.Devtools {
tags.Add("devtools")
}

if options.Obfuscated {
tags.Add("obfuscated")
}
Expand Down
1 change: 1 addition & 0 deletions v2/pkg/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Options struct {
Logger *clilogger.CLILogger // All output to the logger
OutputType string // EG: desktop, server....
Mode Mode // release or dev
Devtools bool // Enable devtools in production
ProjectData *project.Project // The project data
Pack bool // Create a package for the app after building
Platform string // The platform to build for
Expand Down
3 changes: 2 additions & 1 deletion website/docs/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ If you are unsure about a template, inspect `package.json` and `wails.json` for
|:---------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
| -clean | Cleans the `build/bin` directory | |
| -compiler "compiler" | Use a different go compiler to build, eg go1.15beta1 | go |
| -debug | Retains debug information in the application. Allows the use of the devtools in the application window | |
| -debug | Retains debug information in the application and shows the debug console. Allows the use of the devtools in the application window | |
| -devtools | Allows the use of the devtools in the application window in production (when -debug is not used) | |
| -dryrun | Prints the build command without executing it | |
| -f | Force build application | |
| -garbleargs | Arguments to pass to garble | `-literals -tiny -seed=random` |
Expand Down
1 change: 1 addition & 0 deletions website/docs/tutorials/helloworld.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ App Type: desktop
Platforms: windows/amd64
Compiler: C:\Users\leaan\go\go1.18.3\bin\go.exe
Build Mode: Production
Devtools: false
Skip Frontend: false
Compress: false
Package: true
Expand Down
4 changes: 4 additions & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Avoid app crashing when the Linux GTK key is empty by @aminya in [PR](https://github.com/wailsapp/wails/pull/2672)

### Added

- Added `-devtools` production build flag. Added by @mmghv in [PR](https://github.com/wailsapp/wails/pull/2725)

### Changed

- Now uses new `go-webview2` module. Added by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/2687).
Expand Down