From 9ebc82afbb83a10dfd062dd353e01d29aa02086e Mon Sep 17 00:00:00 2001 From: Atterpac Date: Sun, 18 May 2025 16:48:18 -0400 Subject: [PATCH] windows custom protocol --- v3/pkg/application/application_windows.go | 42 +++++++++++++++++------ 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/v3/pkg/application/application_windows.go b/v3/pkg/application/application_windows.go index bc8428be1..c9504a6ac 100644 --- a/v3/pkg/application/application_windows.go +++ b/v3/pkg/application/application_windows.go @@ -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