Refactor menu functions and streamline devtools toggle across systems

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.
This commit is contained in:
Lea Anthony
2024-01-21 20:52:08 +11:00
parent c82facd6ff
commit 6522657893
27 changed files with 326 additions and 165 deletions
+7 -3
View File
@@ -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:
+1 -1
View File
@@ -1,2 +1,2 @@
" ",Mac,Windows,Linux
`wails3 dev`," ",:material-minus:," "
`wails3 dev`,:material-minus:,:material-minus:," "
1 Mac Windows Linux
2 `wails3 dev` :material-minus: :material-minus:
+7 -17
View File
@@ -3,6 +3,7 @@ package assetserver
import (
"fmt"
"html"
"net"
"net/http"
"net/http/httptest"
"net/http/httputil"
@@ -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)
@@ -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)
@@ -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 != "" {
@@ -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 {
@@ -0,0 +1,8 @@
package assetserver
import "net/url"
var baseURL = url.URL{
Scheme: "wails",
Host: "localhost",
}
@@ -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...)
}
@@ -0,0 +1,5 @@
//go:build production
package assetserver
func (a *AssetServer) LogDetails() {}
@@ -1,3 +1,8 @@
package assetserver
var startURL = "http://wails.localhost"
import "net/url"
var baseURL = url.URL{
Scheme: "http",
Host: "wails.localhost",
}
-3
View File
@@ -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
@@ -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",
@@ -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};
+3 -7
View File
@@ -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()
@@ -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
@@ -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
@@ -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)
}
@@ -659,6 +654,7 @@ func (a *App) cleanup() {
func (a *App) Quit() {
if a.impl != nil {
InvokeSync(a.impl.destroy)
a.postQuit()
}
}
+15 -3
View File
@@ -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.
@@ -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() {
}
@@ -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 }
+2 -2
View File
@@ -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:
+14
View File
@@ -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()
}
})
}
@@ -0,0 +1,7 @@
//go:build production && !devtools
package application
func newShowDevToolsMenuItem() *MenuItem {
return nil
}
+91 -28
View File
@@ -4,6 +4,7 @@ package application
import (
"github.com/wailsapp/wails/v3/pkg/w32"
"runtime"
"unsafe"
)
@@ -209,54 +210,116 @@ func newAboutMenuItem() *MenuItem {
}
func newCloseMenuItem() *MenuItem {
panic("implement me")
return newMenuItem("Close").
SetAccelerator("CmdOrCtrl+w").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.Close()
}
})
}
func newReloadMenuItem() *MenuItem {
panic("implement me")
return newMenuItem("Reload").
SetAccelerator("CmdOrCtrl+r").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.Reload()
}
})
}
func newForceReloadMenuItem() *MenuItem {
panic("implement me")
return newMenuItem("Force Reload").
SetAccelerator("CmdOrCtrl+Shift+r").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.ForceReload()
}
})
}
func newToggleFullscreenMenuItem() *MenuItem {
panic("implement me")
}
func newToggleDevToolsMenuItem() *MenuItem {
panic("implement me")
result := newMenuItem("Toggle Full Screen").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.ToggleFullscreen()
}
})
if runtime.GOOS == "darwin" {
result.SetAccelerator("Ctrl+Command+F")
} else {
result.SetAccelerator("F11")
}
return result
}
func newZoomResetMenuItem() *MenuItem {
panic("implement me")
// reset zoom menu item
return newMenuItem("Actual Size").
SetAccelerator("CmdOrCtrl+0").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.ZoomReset()
}
})
}
func newZoomInMenuItem() *MenuItem {
panic("implement me")
return newMenuItem("Zoom In").
SetAccelerator("CmdOrCtrl+plus").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.ZoomIn()
}
})
}
func newZoomOutMenuItem() *MenuItem {
panic("implement me")
}
func newMinimizeMenuItem() *MenuItem {
panic("implement me")
}
func newZoomMenuItem() *MenuItem {
panic("implement me")
return newMenuItem("Zoom Out").
SetAccelerator("CmdOrCtrl+-").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.ZoomOut()
}
})
}
func newFullScreenMenuItem() *MenuItem {
panic("implement me")
return newMenuItem("Fullscreen").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.Fullscreen()
}
})
}
func newMinimizeMenuItem() *MenuItem {
return newMenuItem("Minimize").
SetAccelerator("CmdOrCtrl+M").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.Minimise()
}
})
}
func newZoomMenuItem() *MenuItem {
return newMenuItem("Zoom").
OnClick(func(ctx *Context) {
currentWindow := globalApplication.CurrentWindow()
if currentWindow != nil {
currentWindow.Zoom()
}
})
}
// ---------- unsupported on windows ----------
+2 -2
View File
@@ -36,7 +36,7 @@ const (
Close Role = iota
Reload Role = iota
ForceReload Role = iota
ToggleDevTools Role = iota
ShowDevTools Role = iota
ResetZoom Role = iota
ZoomIn Role = iota
ZoomOut Role = iota
@@ -76,7 +76,7 @@ func newViewMenu() *MenuItem {
viewMenu := NewMenu()
viewMenu.AddRole(Reload)
viewMenu.AddRole(ForceReload)
viewMenu.AddRole(ToggleDevTools)
addDevToolMenuItem(viewMenu)
viewMenu.AddSeparator()
viewMenu.AddRole(ResetZoom)
viewMenu.AddRole(ZoomIn)
+7
View File
@@ -0,0 +1,7 @@
//go:build !production || devtools
package application
func addDevToolMenuItem(viewMenu *Menu) {
viewMenu.AddRole(ShowDevTools)
}
+5
View File
@@ -0,0 +1,5 @@
//go:build production && !devtools
package application
func addDevToolMenuItem(viewMenu *Menu) {}

Some files were not shown because too many files have changed in this diff Show More