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

Conversation

mmghv
Copy link
Contributor

@mmghv mmghv commented Jun 12, 2023

Description

This adds the build flag -devtools which enables the devtools in production when -debug is not used.

Using -debug automatically enables devtools but it also includes go debug info which increases the binary size and shows the debug console window, sometimes you only need the ability to show the devtools in production build in personal projects to be able to debug the frontend on the fly.

Note: -debug alone still enables the devtools.
Note: options.Debug.OpenInspectorOnStartup still only works with -debug.

Fixes #1523

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Windows
  • macOS
  • Linux

Here's how to test it :

1- Create a new project wails init -n testproject -t vanilla
2- Follow these instructions (replace [IDofThePR] with 2725), and make sure to add the replace directive in go.mod.
3- Change testproject/main.go to add this option, which needs be updated according to the test table :

func main() {
	// ...
	err := wails.Run(&options.App{
		// ...
		Debug: options.Debug{
			OpenInspectorOnStartup: false,
        	},
	})
	// ...
}

4- Build the application according to the following table and ensure the expected behavior in each case:

OpenInspectorOnStartup Command Expected behavior
false wails build no console window, no context menu
false wails build -debug console window + context menu & devtools AVAILABLE
true wails build -debug same as ^ + devtools opens on startup
false wails build -devtools no console window, context menu & devdools AVAILABLE
true wails build -devtools same as ^ (devtools SHOULD NOT open on startup)
false wails dev console window + context menu with devtools
true wails dev same as ^ + devtools opens on startup

(To make it easier you could do all tests where OpenInspectorOnStartup is false first, then change it to true and do the other tests)

Test Configuration

wails doctor
# Wails
Version  | v2.5.1
Revision | 5722b944a426565cf56556ae3a27d64893561825
Modified | false

# System
┌────────────────────────────────────┐
| OS           | Windows 10 Pro      |
| Version      | 2009 (Build: 19045) |
| ID           | 22H2                |
| Go Version   | go1.20.4            |
| Platform     | windows             |
| Architecture | amd64               |
└────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 114.0.1823.43 |
| Nodejs     | N/A          | Installed | 18.14.1       |
| npm        | N/A          | Installed | 9.3.1         |
| *upx       | N/A          | Installed | upx 4.0.2     |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

# Diagnosis
Optional package(s) installation details:
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@mmghv mmghv marked this pull request as ready for review June 12, 2023 11:34
@mmghv mmghv marked this pull request as draft June 12, 2023 11:35
@mmghv
Copy link
Contributor Author

mmghv commented Jun 13, 2023

Tested on Linux, all cases work as expected.

wails doctor
Version         | v2.5.1
Revision        | 4f886e180ea296f79e58864143e56ca8fdb00b5a
Modified        | false
Package Manager | apt

# System
┌─────────────────────────┐
| OS           | Ubuntu   |
| Version      | 22.04    |
| ID           | ubuntu   |
| Go Version   | go1.20.5 |
| Platform     | linux    |
| Architecture | amd64    |
└─────────────────────────┘

# Dependencies
┌──────────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name          | Status    | Version                 |
| *docker    | docker.io             | Installed |                         |
| gcc        | build-essential       | Installed | 11.3.0                  |
| libgtk-3   | libgtk-3-dev          | Installed | 3.24.33-1ubuntu2        |
| libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.38.6-0ubuntu0.22.04.1 |
| npm        | npm                   | Installed | 9.5.1                   |
| *nsis      | nsis                  | Available | 3.08-2                  |
| pkg-config | pkg-config            | Installed | 0.29.2-1ubuntu3         |
└──────────────────────── * - Optional Dependency ─────────────────────────┘

# Diagnosis
Optional package(s) installation details:
  - nsis: sudo apt install nsis

 SUCCESS  Your system is ready for Wails development!

@leaanthony Please test on macOS

@leaanthony
Copy link
Member

leaanthony commented Jun 13, 2023

@mmghv - When you say "Console window", do you mean the terminal which we use to run the app?

I've tested the scenarios above, but if I use runtime.LogErrorf(ctx, "App started") in app start, I can still see it in the console when using -devtools.

@mmghv
Copy link
Contributor Author

mmghv commented Jun 13, 2023

@leaanthony

When you say "Console window", do you mean the terminal which we use to run the app?

Yes, in debug mode on windows if I launch the app from file explorer, I get a terminal window in addition to the main window (that's why this feature was needed in the first place).
But if you run the app from the terminal, you will get the output there and won't get additional terminal window.

Anyway, when using -devtools you should see in the terminal the same you see when you build a normal app wails build, you see logError because it's the default loglevel in production.

If you instead did runtime.LogInfo(ctx, "App started") you should see it in debug mode only, I'm not sure of a better way to tell if you're in debug mode when running from the terminal, on linux I judged by the binary size.

@leaanthony
Copy link
Member

I tested on MacOS and it appeared to do what you would expect. I'm happy with this so far. Feel free to mark it ready for review when you are ready.

@mmghv mmghv marked this pull request as ready for review June 17, 2023 07:47
@mmghv
Copy link
Contributor Author

mmghv commented Jun 17, 2023

All ready, @stffabi you worked on this area of the code, could you please review it?

@leaanthony leaanthony requested a review from stffabi June 17, 2023 09:38
Copy link
Collaborator

@stffabi stffabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 , thanks for doing this and taking your time.

@leaanthony leaanthony merged commit fa851f2 into wailsapp:master Jun 18, 2023
@mmghv mmghv deleted the feature/1523_add-devtools-production-build-flag branch June 27, 2023 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support open devtools on app had been builded
3 participants