Skip to content

Commit

Permalink
Refactor menu functions and streamline devtools toggle across systems
Browse files Browse the repository at this point in the history
This update adds implementation to several menu item functions, replacing their previous 'not implemented' state. This includes actions for close, reload, forcing reload, toggling of fullscreen, reset zoom, and others. The update also includes modifications for the handling of developer tools toggle under different build configurations. This refactoring is aimed to standardize devtools configuration across different operating systems.
  • Loading branch information
leaanthony committed Jan 21, 2024
1 parent c82facd commit 6522657
Show file tree
Hide file tree
Showing 27 changed files with 322 additions and 161 deletions.
10 changes: 7 additions & 3 deletions mkdocs-website/docs/en/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ Basically, try to break it and let us know if you find any issues! :smile:

{{ read_csv("alpha4-wails3-dev.csv") }}

- Windows does work, with the following caveats
- Sometimes the main app is built twice on change
- Closing the main window does not terminate the dev process, requiring ctrl-c to terminate
- Windows is partially working:
- Frontend changes work as expected
- Go changes cause the application to be built twice

- Mac is partially working:
- Frontend changes work as expectedFrontend changes work as expected
- Go changes terminates the vite process

`wails3 package` command:

Expand Down
2 changes: 1 addition & 1 deletion mkdocs-website/shared/alpha4-wails3-dev.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
" ",Mac,Windows,Linux
`wails3 dev`," ",:material-minus:," "
`wails3 dev`,:material-minus:,:material-minus:," "
24 changes: 7 additions & 17 deletions v3/internal/assetserver/assetserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package assetserver
import (
"fmt"
"html"
"net"
"net/http"
"net/http/httptest"
"net/http/httputil"
Expand Down Expand Up @@ -144,20 +145,6 @@ func (a *AssetServer) serveError(rw http.ResponseWriter, err error, msg string,
rw.WriteHeader(http.StatusInternalServerError)
}

func (a *AssetServer) LogDetails() {
if a.options.IsDebug {
var info = []any{
"assetsFS", a.options.Assets != nil,
"middleware", a.options.Middleware != nil,
"handler", a.options.Handler != nil,
}
if a.devServerURL != "" {
info = append(info, "devServerURL", a.devServerURL)
}
a.options.Logger.Info("AssetServer Info:", info...)
}
}

func (a *AssetServer) AddPluginScript(pluginName string, script string) {
if a.pluginScripts == nil {
a.pluginScripts = make(map[string]string)
Expand All @@ -170,6 +157,7 @@ func (a *AssetServer) AddPluginScript(pluginName string, script string) {

func GetStartURL(userURL string) (string, error) {
devServerURL := GetDevServerURL()
startURL := baseURL.String()
if devServerURL != "" {
// Parse the port
parsedURL, err := url.Parse(devServerURL)
Expand All @@ -178,7 +166,8 @@ func GetStartURL(userURL string) (string, error) {
}
port := parsedURL.Port()
if port != "" {
startURL += ":" + port
baseURL.Host = net.JoinHostPort(baseURL.Host, port)
startURL = baseURL.String()
}
} else {
if userURL != "" {
Expand All @@ -188,9 +177,10 @@ func GetStartURL(userURL string) (string, error) {
return "", fmt.Errorf("Error parsing URL: " + err.Error())
}
if parsedURL.Scheme == "" {
startURL = path.Join(startURL, userURL)
baseURL.Path = path.Join(baseURL.Path, userURL)
startURL = baseURL.String()
// if the original URL had a trailing slash, add it back
if strings.HasSuffix(userURL, "/") {
if strings.HasSuffix(userURL, "/") && !strings.HasSuffix(startURL, "/") {
startURL = startURL + "/"
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions v3/internal/assetserver/assetserver_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package assetserver

import "net/url"

var baseURL = url.URL{
Scheme: "wails",
Host: "localhost",
}
15 changes: 15 additions & 0 deletions v3/internal/assetserver/assetserver_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !production

package assetserver

func (a *AssetServer) LogDetails() {
var info = []any{
"assetsFS", a.options.Assets != nil,
"middleware", a.options.Middleware != nil,
"handler", a.options.Handler != nil,
}
if a.devServerURL != "" {
info = append(info, "devServerURL", a.devServerURL)
}
a.options.Logger.Info("AssetServer Info:", info...)
}
5 changes: 5 additions & 0 deletions v3/internal/assetserver/assetserver_production.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build production

package assetserver

func (a *AssetServer) LogDetails() {}
7 changes: 6 additions & 1 deletion v3/internal/assetserver/assetserver_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package assetserver

var startURL = "http://wails.localhost"
import "net/url"

var baseURL = url.URL{
Scheme: "http",
Host: "wails.localhost",
}
3 changes: 0 additions & 3 deletions v3/internal/assetserver/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ type Options struct {

// GetFlags returns the application flags
GetFlags func() []byte

// IsDebug is true if the server is running in debug mode
IsDebug bool
}

// Validate the options
Expand Down
2 changes: 1 addition & 1 deletion v3/internal/runtime/desktop/@wailsio/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wailsio/runtime",
"version": "3.0.0-alpha.16",
"version": "3.0.0-alpha.17",
"description": "Wails Runtime",
"main": "src/index.js",
"types": "types/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions v3/internal/runtime/desktop/@wailsio/runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as WML from './wml';
import * as Events from "./events";
import * as Dialogs from "./dialogs";
import * as Call from "./calls";
import {setupEventCallbacks} from "./events";

export { Application, Browser, Call, Clipboard, Dialogs, Events, Flags, Screens, System, Window, WML};

Expand Down
10 changes: 3 additions & 7 deletions v3/pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func New(appOptions Options) *App {
Handler: appOptions.Assets.Handler,
Middleware: assetserver.Middleware(appOptions.Assets.Middleware),
Logger: result.Logger,
IsDebug: result.isDebugMode,
RuntimeHandler: NewMessageProcessor(result.Logger),
GetCapabilities: func() []byte {
return globalApplication.capabilities.AsBytes()
Expand All @@ -102,7 +101,6 @@ func New(appOptions Options) *App {
srv, err := assetserver.NewAssetServer(opts)
if err != nil {
result.Logger.Error("Fatal error in application initialisation: " + err.Error())
os.Exit(1)
}

result.assets = srv
Expand All @@ -111,20 +109,17 @@ func New(appOptions Options) *App {
result.bindings, err = NewBindings(appOptions.Bind, appOptions.BindAliases)
if err != nil {
globalApplication.fatal("Fatal error in application initialisation: " + err.Error())
os.Exit(1)
}

result.plugins = NewPluginManager(appOptions.Plugins, srv)
err = result.plugins.Init()
if err != nil {
result.Quit()
os.Exit(1)
globalApplication.fatal("Fatal error in plugins initialisation: " + err.Error())
}

err = result.bindings.AddPlugins(appOptions.Plugins)
if err != nil {
globalApplication.fatal("Fatal error in application initialisation: " + err.Error())
os.Exit(1)
}

// Process keybindings
Expand Down Expand Up @@ -407,7 +402,7 @@ func (a *App) debug(message string, args ...any) {
func (a *App) fatal(message string, args ...any) {
msg := "A FATAL ERROR HAS OCCURRED: " + message
if a.Logger != nil {
go a.Logger.Error(msg, args...)
a.Logger.Error(msg, args...)
} else {
println(msg)
}
Expand Down Expand Up @@ -659,6 +654,7 @@ func (a *App) cleanup() {
func (a *App) Quit() {
if a.impl != nil {
InvokeSync(a.impl.destroy)
a.postQuit()
}
}

Expand Down
18 changes: 15 additions & 3 deletions v3/pkg/application/application_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
package application

import (
"errors"
"github.com/wailsapp/wails/v3/internal/assetserver"
"net/http"
"time"
)

var devMode = false

func (a *App) preRun() error {
// Check for frontend server url
frontendURL := assetserver.GetDevServerURL()
if frontendURL != "" {
devMode = true
// We want to check if the frontend server is running by trying to http get the url
// and if it is not, we wait 500ms and try again for a maximum of 10 times. If it is
// still not available, we return an error.
Expand All @@ -31,8 +33,18 @@ func (a *App) preRun() error {
a.Logger.Info("Retrying...")
}
}
a.Logger.Info("failed!")
return errors.New("unable to connect to frontend server. Please check it is running")
a.fatal("unable to connect to frontend server. Please check it is running", "FRONTEND_DEVSERVER_URL", frontendURL)
}
return nil
}

func (a *App) postQuit() {
if devMode {
a.Logger.Info("The application has terminated, but the watcher is still running.")
a.Logger.Info("To terminate the watcher, press CTRL+C")
}
}

func (a *App) enableDevTools() {

}
2 changes: 2 additions & 0 deletions v3/pkg/application/application_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ func newApplication(options Options) *App {
func (a *App) logStartup() {}

func (a *App) preRun() error { return nil }

func (a *App) postQuit() error { return nil }
4 changes: 2 additions & 2 deletions v3/pkg/application/menuitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func newRole(role Role) *MenuItem {
return newForceReloadMenuItem()
case ToggleFullscreen:
return newToggleFullscreenMenuItem()
case ToggleDevTools:
return newToggleDevToolsMenuItem()
case ShowDevTools:
return newShowDevToolsMenuItem()
case ResetZoom:
return newZoomResetMenuItem()
case ZoomIn:
Expand Down
14 changes: 14 additions & 0 deletions v3/pkg/application/menuitem_dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !production || devtools

package application

func newShowDevToolsMenuItem() *MenuItem {
return newMenuItem("Show Developer Tools").
SetAccelerator("Alt+Command+I").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.ToggleDevTools()
}
})
}
7 changes: 7 additions & 0 deletions v3/pkg/application/menuitem_production.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build production && !devtools

package application

func newShowDevToolsMenuItem() *MenuItem {
return nil
}
Loading

0 comments on commit 6522657

Please sign in to comment.