mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
windows custom protocol
This commit is contained in:
parent
f143bd6866
commit
9ebc82afbb
1 changed files with 31 additions and 11 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
|
|
@ -144,20 +145,35 @@ func (m *windowsApp) run() error {
|
|||
ctx: blankApplicationEventContext,
|
||||
}
|
||||
|
||||
// Check if there is 1 parameter passed to the application
|
||||
// and if the extension matches the options.FileAssociations string
|
||||
if len(os.Args) == 2 {
|
||||
arg := os.Args[1]
|
||||
ext := filepath.Ext(arg)
|
||||
if slices.Contains(m.parent.options.FileAssociations, ext) {
|
||||
if len(os.Args) == 2 { // Case: program + 1 argument
|
||||
arg1 := os.Args[1]
|
||||
// Check if the argument is likely a URL from a custom protocol invocation
|
||||
if strings.Contains(arg1, "://") {
|
||||
m.parent.info("Application launched with argument, potentially a URL from custom protocol", "url", arg1)
|
||||
eventContext := newApplicationEventContext()
|
||||
eventContext.setOpenedWithFile(arg)
|
||||
// EmitEvent application started event
|
||||
eventContext.setURL(arg1)
|
||||
applicationEvents <- &ApplicationEvent{
|
||||
Id: uint(events.Common.ApplicationOpenedWithFile),
|
||||
Id: uint(events.Common.ApplicationLaunchedWithUrl),
|
||||
ctx: eventContext,
|
||||
}
|
||||
} else {
|
||||
// If not a URL-like string, check for file association
|
||||
if m.parent.options.FileAssociations != nil {
|
||||
ext := filepath.Ext(arg1)
|
||||
if slices.Contains(m.parent.options.FileAssociations, ext) {
|
||||
m.parent.info("Application launched with file via file association", "file", arg1)
|
||||
eventContext := newApplicationEventContext()
|
||||
eventContext.setOpenedWithFile(arg1)
|
||||
applicationEvents <- &ApplicationEvent{
|
||||
Id: uint(events.Common.ApplicationOpenedWithFile),
|
||||
ctx: eventContext,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if len(os.Args) > 2 {
|
||||
// Log if multiple arguments are passed, though typical protocol/file launch is a single arg.
|
||||
m.parent.info("Application launched with multiple arguments", "args", os.Args[1:])
|
||||
}
|
||||
|
||||
_ = m.runMainLoop()
|
||||
|
|
@ -377,7 +393,9 @@ func newPlatformApp(app *App) *windowsApp {
|
|||
func (a *App) logPlatformInfo() {
|
||||
var args []any
|
||||
args = append(args, "Go-WebView2Loader", webviewloader.UsingGoWebview2Loader)
|
||||
webviewVersion, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(a.options.Windows.WebviewBrowserPath)
|
||||
webviewVersion, err := webviewloader.GetAvailableCoreWebView2BrowserVersionString(
|
||||
a.options.Windows.WebviewBrowserPath,
|
||||
)
|
||||
if err != nil {
|
||||
args = append(args, "WebView2", "Error: "+err.Error())
|
||||
} else {
|
||||
|
|
@ -392,7 +410,9 @@ func (a *App) logPlatformInfo() {
|
|||
|
||||
func (a *App) platformEnvironment() map[string]any {
|
||||
result := map[string]any{}
|
||||
webviewVersion, _ := webviewloader.GetAvailableCoreWebView2BrowserVersionString(a.options.Windows.WebviewBrowserPath)
|
||||
webviewVersion, _ := webviewloader.GetAvailableCoreWebView2BrowserVersionString(
|
||||
a.options.Windows.WebviewBrowserPath,
|
||||
)
|
||||
result["Go-WebView2Loader"] = webviewloader.UsingGoWebview2Loader
|
||||
result["WebView2"] = webviewVersion
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue