mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 03:20:09 +08:00
[v2] Add -devtools production build flag (#2725)
* [v2] Add devtools production build flag * Update changelog * Fix changelog spacing --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
parent
31a5c90673
commit
fa851f29c5
@ -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,
|
||||
@ -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)},
|
||||
}
|
||||
|
@ -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"`
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
@ -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)
|
||||
|
@ -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)
|
||||
@ -228,6 +230,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
||||
startupCallback: appoptions.OnStartup,
|
||||
shutdownCallback: appoptions.OnShutdown,
|
||||
debug: true,
|
||||
devtools: true,
|
||||
}
|
||||
|
||||
result.options = appoptions
|
||||
|
7
v2/internal/app/app_devtools.go
Normal file
7
v2/internal/app/app_devtools.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build devtools
|
||||
|
||||
package app
|
||||
|
||||
func IsDevtoolsEnabled() bool {
|
||||
return true
|
||||
}
|
7
v2/internal/app/app_devtools_not.go
Normal file
7
v2/internal/app/app_devtools_not.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build !devtools
|
||||
|
||||
package app
|
||||
|
||||
func IsDevtoolsEnabled() bool {
|
||||
return false
|
||||
}
|
@ -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)
|
||||
@ -93,6 +95,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
|
||||
startupCallback: appoptions.OnStartup,
|
||||
shutdownCallback: appoptions.OnShutdown,
|
||||
debug: debug,
|
||||
devtools: devtools,
|
||||
options: appoptions,
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
@property bool alwaysOnTop;
|
||||
|
||||
@property bool debug;
|
||||
@property bool devtools;
|
||||
|
||||
@property (retain) WKUserContentController* userContentController;
|
||||
|
||||
|
@ -225,7 +225,7 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
|
||||
[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
|
||||
|
@ -47,6 +47,7 @@ type Frontend struct {
|
||||
frontendOptions *options.App
|
||||
logger *logger.Logger
|
||||
debug bool
|
||||
devtools bool
|
||||
|
||||
// Assets
|
||||
assets *assetserver.AssetServer
|
||||
@ -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()
|
||||
|
||||
|
@ -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("");
|
||||
|
@ -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()
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -106,6 +106,7 @@ type Frontend struct {
|
||||
frontendOptions *options.App
|
||||
logger *logger.Logger
|
||||
debug bool
|
||||
devtools bool
|
||||
|
||||
// Assets
|
||||
assets *assetserver.AssetServer
|
||||
@ -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()
|
||||
|
||||
|
@ -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
|
||||
@ -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,
|
||||
@ -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))
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ type Frontend struct {
|
||||
logger *logger.Logger
|
||||
chromium *edge.Chromium
|
||||
debug bool
|
||||
devtools bool
|
||||
|
||||
// Assets
|
||||
assets *assetserver.AssetServer
|
||||
@ -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()
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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` |
|
||||
|
@ -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
|
||||
|
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user