mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Add BrowserOpenURL and BrowserOpenFile to App.
Better WML assets for demo Fix dialog responses. Add `wml-openurl` Rename: data-wml -> wml Fix Alpha Feedback URL
This commit is contained in:
@@ -3,6 +3,7 @@ package application
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"github.com/pkg/browser"
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
@@ -802,3 +803,11 @@ func (a *App) UnregisterWindow(id uint) {
|
||||
defer a.windowsLock.Unlock()
|
||||
delete(a.windows, id)
|
||||
}
|
||||
|
||||
func (a *App) BrowserOpenURL(url string) error {
|
||||
return browser.OpenURL(url)
|
||||
}
|
||||
|
||||
func (a *App) BrowserOpenFile(path string) error {
|
||||
return browser.OpenFile(path)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
<div>Alpha</div>
|
||||
<div>
|
||||
<p class="button-42" onclick="window.open('https://wailsapp.github.io/wails/')">Documentation</p>
|
||||
<p class="button-42" onclick="window.open('https://wailsapp.github.io/wails/')">Feedback</p>
|
||||
<p class="button-42" onclick="window.open('https://wailsapp.github.io/wails/getting-started/feedback/')">Feedback</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -21,6 +21,7 @@ const (
|
||||
windowRequest = 6
|
||||
screensRequest = 7
|
||||
systemRequest = 8
|
||||
browserRequest = 9
|
||||
)
|
||||
|
||||
type MessageProcessor struct {
|
||||
@@ -139,6 +140,8 @@ func (m *MessageProcessor) HandleRuntimeCallWithIDs(rw http.ResponseWriter, r *h
|
||||
m.processCallMethod(method, rw, r, targetWindow, params)
|
||||
case systemRequest:
|
||||
m.processSystemMethod(method, rw, r, targetWindow, params)
|
||||
case browserRequest:
|
||||
m.processBrowserMethod(method, rw, r, targetWindow, params)
|
||||
default:
|
||||
m.httpError(rw, "Unknown runtime call: %d", object)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"github.com/pkg/browser"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
BrowserOpenURL = 0
|
||||
)
|
||||
|
||||
var browserMethods = map[int]string{
|
||||
BrowserOpenURL: "OpenURL",
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) processBrowserMethod(method int, rw http.ResponseWriter, _ *http.Request, _ Window, params QueryParams) {
|
||||
|
||||
args, err := params.Args()
|
||||
if err != nil {
|
||||
m.httpError(rw, "Unable to parse arguments: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
switch method {
|
||||
case BrowserOpenURL:
|
||||
url := args.String("url")
|
||||
if url == nil {
|
||||
m.Error("OpenURL: url is required")
|
||||
return
|
||||
}
|
||||
err := browser.OpenURL(*url)
|
||||
if err != nil {
|
||||
m.Error("OpenURL: %s", err.Error())
|
||||
return
|
||||
}
|
||||
m.ok(rw)
|
||||
m.Info("Runtime Call:", "method", "Browser."+browserMethods[method], "url", *url)
|
||||
default:
|
||||
m.httpError(rw, "Unknown browser method: %d", method)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (m *MessageProcessor) dialogErrorCallback(window Window, message string, di
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) dialogCallback(window Window, dialogID *string, result string, isJSON bool) {
|
||||
window.DialogResponse(*dialogID, result)
|
||||
window.DialogResponse(*dialogID, result, isJSON)
|
||||
}
|
||||
|
||||
func (m *MessageProcessor) processDialogMethod(method int, rw http.ResponseWriter, r *http.Request, window Window, params QueryParams) {
|
||||
|
||||
@@ -255,9 +255,13 @@ func (w *WebviewWindow) DialogError(dialogID string, result string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebviewWindow) DialogResponse(dialogID string, result string) {
|
||||
func (w *WebviewWindow) DialogResponse(dialogID string, result string, isJSON bool) {
|
||||
if w.impl != nil {
|
||||
w.impl.execJS(w.formatJS("_wails.dialogCallback('%s', %s, true);", dialogID, result))
|
||||
if isJSON {
|
||||
w.impl.execJS(w.formatJS("_wails.dialogCallback('%s', %s, true);", dialogID, result))
|
||||
} else {
|
||||
w.impl.execJS(fmt.Sprintf("_wails.dialogCallback('%s', '%s', false);", dialogID, result))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ type Callback interface {
|
||||
CallError(callID string, result string)
|
||||
CallResponse(callID string, result string)
|
||||
DialogError(dialogID string, result string)
|
||||
DialogResponse(dialogID string, result string)
|
||||
DialogResponse(dialogID string, result string, isJSON bool)
|
||||
}
|
||||
|
||||
type Window interface {
|
||||
|
||||
Reference in New Issue
Block a user