mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-20 19:09:29 +08:00
[examples] update label on click
This commit is contained in:
parent
68cfd130d3
commit
a9d834d715
@ -3,6 +3,7 @@ module github.com/wailsapp/wails/v3
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/ebitengine/purego v0.3.2
|
||||
github.com/go-task/task/v3 v3.20.0
|
||||
github.com/google/go-cmp v0.5.9
|
||||
github.com/jackmordaunt/icns/v2 v2.2.1
|
||||
@ -72,3 +73,5 @@ require (
|
||||
)
|
||||
|
||||
replace github.com/wailsapp/wails/v2 => ../v2
|
||||
|
||||
replace github.com/ebitengine/purego v0.3.2 => github.com/TotallyGamerJet/purego v0.2.0-alpha.0.20230404174033-5655abccca7e
|
||||
|
@ -11,6 +11,8 @@ github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzX
|
||||
github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c=
|
||||
github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE=
|
||||
github.com/MarvinJWendt/testza v0.5.1 h1:a9Fqx6vQrHQ4CyiaLhktfTTelwGotmFWy8MNhyaohw8=
|
||||
github.com/TotallyGamerJet/purego v0.2.0-alpha.0.20230404174033-5655abccca7e h1:wQ7ot+e0mwJYkbomtIX9tU0dOV9lFTmwAgUGqvQTIUg=
|
||||
github.com/TotallyGamerJet/purego v0.2.0-alpha.0.20230404174033-5655abccca7e/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
|
||||
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
||||
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
||||
|
@ -363,6 +363,13 @@ func (a *App) Run() error {
|
||||
}
|
||||
}()
|
||||
|
||||
a.impl.setApplicationMenu(a.ApplicationMenu)
|
||||
|
||||
// set the application menu
|
||||
if runtime.GOOS == "darwin" {
|
||||
a.impl.setIcon(a.options.Icon)
|
||||
}
|
||||
|
||||
// run windows
|
||||
for _, window := range a.windows {
|
||||
go window.run()
|
||||
@ -373,12 +380,6 @@ func (a *App) Run() error {
|
||||
go systray.Run()
|
||||
}
|
||||
|
||||
// set the application menu
|
||||
if runtime.GOOS == "darwin" {
|
||||
a.impl.setApplicationMenu(a.ApplicationMenu)
|
||||
a.impl.setIcon(a.options.Icon)
|
||||
}
|
||||
|
||||
err := a.impl.run()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -185,6 +185,7 @@ func (m *macosApp) run() error {
|
||||
C.setApplicationShouldTerminateAfterLastWindowClosed(C.bool(m.parent.options.Mac.ApplicationShouldTerminateAfterLastWindowClosed))
|
||||
C.setActivationPolicy(C.int(m.parent.options.Mac.ActivationPolicy))
|
||||
C.activateIgnoringOtherApps()
|
||||
globalApplication.activate()
|
||||
})
|
||||
// setup event listeners
|
||||
for eventID := range m.parent.applicationEventListeners {
|
||||
|
@ -4,19 +4,16 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (m *MessageProcessor) callErrorCallback(window *WebviewWindow, message string, callID *string, err error) {
|
||||
errorMsg := fmt.Sprintf(message, err)
|
||||
m.Error(errorMsg)
|
||||
msg := "_wails.callErrorCallback('" + *callID + "', " + strconv.Quote(errorMsg) + ");"
|
||||
window.ExecJS(msg)
|
||||
window.CallError(callID, errorMsg)
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) callCallback(window *WebviewWindow, callID *string, result string, isJSON bool) {
|
||||
msg := fmt.Sprintf("_wails.callCallback('%s', %s, %v);", *callID, strconv.Quote(result), isJSON)
|
||||
window.ExecJS(msg)
|
||||
window.CallResponse(callID, result)
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) processCallMethod(method string, rw http.ResponseWriter, _ *http.Request, window *WebviewWindow, params QueryParams) {
|
||||
|
@ -5,19 +5,16 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (m *MessageProcessor) dialogErrorCallback(window *WebviewWindow, message string, dialogID *string, err error) {
|
||||
errorMsg := fmt.Sprintf(message, err)
|
||||
m.Error(errorMsg)
|
||||
msg := "_wails.dialogErrorCallback('" + *dialogID + "', " + strconv.Quote(errorMsg) + ");"
|
||||
window.ExecJS(msg)
|
||||
window.DialogError(dialogID, errorMsg)
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) dialogCallback(window *WebviewWindow, dialogID *string, result string, isJSON bool) {
|
||||
msg := fmt.Sprintf("_wails.dialogCallback('%s', %s, %v);", *dialogID, strconv.Quote(result), isJSON)
|
||||
window.ExecJS(msg)
|
||||
window.DialogResponse(dialogID, result)
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) processDialogMethod(method string, rw http.ResponseWriter, r *http.Request, window *WebviewWindow, params QueryParams) {
|
||||
|
@ -1,12 +1,14 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/samber/lo"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/logger"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
@ -14,54 +16,57 @@ import (
|
||||
|
||||
type (
|
||||
webviewWindowImpl interface {
|
||||
setTitle(title string)
|
||||
setSize(width, height int)
|
||||
setAlwaysOnTop(alwaysOnTop bool)
|
||||
setURL(url string)
|
||||
setResizable(resizable bool)
|
||||
setMinSize(width, height int)
|
||||
setMaxSize(width, height int)
|
||||
execJS(js string)
|
||||
setBackgroundColour(color RGBA)
|
||||
run()
|
||||
center()
|
||||
size() (int, int)
|
||||
width() int
|
||||
height() int
|
||||
position() (int, int)
|
||||
destroy()
|
||||
reload()
|
||||
forceReload()
|
||||
toggleDevTools()
|
||||
zoomReset()
|
||||
zoomIn()
|
||||
zoomOut()
|
||||
getZoom() float64
|
||||
setZoom(zoom float64)
|
||||
close()
|
||||
zoom()
|
||||
setHTML(html string)
|
||||
setPosition(x int, y int)
|
||||
on(eventID uint)
|
||||
minimise()
|
||||
unminimise()
|
||||
maximise()
|
||||
unmaximise()
|
||||
destroy()
|
||||
disableSizeConstraints()
|
||||
execJS(js string)
|
||||
focus()
|
||||
forceReload()
|
||||
fullscreen()
|
||||
unfullscreen()
|
||||
isMinimised() bool
|
||||
isMaximised() bool
|
||||
getScreen() (*Screen, error)
|
||||
getZoom() float64
|
||||
height() int
|
||||
hide()
|
||||
hide()
|
||||
isFullscreen() bool
|
||||
isMaximised() bool
|
||||
isMinimised() bool
|
||||
isNormal() bool
|
||||
isVisible() bool
|
||||
setFullscreenButtonEnabled(enabled bool)
|
||||
focus()
|
||||
show()
|
||||
hide()
|
||||
getScreen() (*Screen, error)
|
||||
setFrameless(bool)
|
||||
openContextMenu(menu *Menu, data *ContextMenuData)
|
||||
maximise()
|
||||
minimise()
|
||||
nativeWindowHandle() uintptr
|
||||
on(eventID uint)
|
||||
openContextMenu(menu *Menu, data *ContextMenuData)
|
||||
position() (int, int)
|
||||
reload()
|
||||
restore() // FIXME: not used
|
||||
run()
|
||||
setAlwaysOnTop(alwaysOnTop bool)
|
||||
setBackgroundColour(color RGBA)
|
||||
setFrameless(bool)
|
||||
setFullscreenButtonEnabled(enabled bool)
|
||||
setHTML(html string)
|
||||
setMaxSize(width, height int)
|
||||
setMinSize(width, height int)
|
||||
setPosition(x int, y int)
|
||||
setResizable(resizable bool)
|
||||
setSize(width, height int)
|
||||
setTitle(title string)
|
||||
setURL(url string)
|
||||
setZoom(zoom float64)
|
||||
show()
|
||||
size() (int, int)
|
||||
toggleDevTools()
|
||||
unfullscreen()
|
||||
unmaximise()
|
||||
unminimise()
|
||||
width() int
|
||||
zoom()
|
||||
zoomIn()
|
||||
zoomOut()
|
||||
zoomReset()
|
||||
}
|
||||
)
|
||||
|
||||
@ -131,6 +136,39 @@ func (w *WebviewWindow) addCancellationFunction(canceller func()) {
|
||||
w.cancellers = append(w.cancellers, canceller)
|
||||
}
|
||||
|
||||
// formatJS ensures the 'data' provided marshals to valid json or panics
|
||||
func (w *WebviewWindow) formatJS(f string, callID string, data string) string {
|
||||
j, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return fmt.Sprintf(f, callID, j)
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) CallError(callID *string, result string) {
|
||||
if w.impl != nil {
|
||||
w.impl.execJS(w.formatJS("_wails.callErrorCallback('%s', %s);", *callID, result))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) CallResponse(callID *string, result string) {
|
||||
if w.impl != nil {
|
||||
w.impl.execJS(w.formatJS("_wails.callCallback('%s', %s, true);", *callID, result))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) DialogError(dialogID *string, result string) {
|
||||
if w.impl != nil {
|
||||
w.impl.execJS(w.formatJS("_wails.dialogErrorCallback('%s', %s);", *dialogID, result))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) DialogResponse(dialogID *string, result string) {
|
||||
if w.impl != nil {
|
||||
w.impl.execJS(w.formatJS("_wails.dialogCallback('%s', %s, true);", *dialogID, result))
|
||||
}
|
||||
}
|
||||
|
||||
// SetTitle sets the title of the window
|
||||
func (w *WebviewWindow) SetTitle(title string) *WebviewWindow {
|
||||
w.implLock.RLock()
|
||||
@ -744,8 +782,9 @@ func (w *WebviewWindow) SetFrameless(frameless bool) *WebviewWindow {
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) dispatchWailsEvent(event *WailsEvent) {
|
||||
msg := fmt.Sprintf("_wails.dispatchWailsEvent(%s);", event.ToJSON())
|
||||
w.ExecJS(msg)
|
||||
if w.impl != nil {
|
||||
w.impl.execJS(fmt.Sprintf("_wails.dispatchWailsEvent(%s);", event.ToJSON()))
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) info(message string, args ...any) {
|
||||
|
Loading…
Reference in New Issue
Block a user