Skip to content

Commit

Permalink
Update OpenURI to take in options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 16, 2024
1 parent 4b725dd commit aff469f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions openuri/openuri.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,28 @@ const (
openURICallName = openURIBaseName + ".OpenURI"
)

// OpenURIOptions holds optional settings that can be passed to the OpenURI call.
type OpenURIOptions struct {
HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element.
Writeable bool // Whether to allow the chosen application to write to the file. This key only takes effect the uri points to a local file that is exported in the document portal, and the chosen application is sandboxed itself.
Ask bool // Whether to ask the user to choose an app. If this is not passed, or false, the portal may use a default or pick the last choice.
}

// OpenURI opens the given URI in the corresponding application.
func OpenURI(parentWindow, uri string) error {
func OpenURI(parentWindow, uri string, options *OpenURIOptions) error {
conn, err := dbus.SessionBus() // Shared connection, don't close.
if err != nil {
return err
}

data := map[string]dbus.Variant{}
data := map[string]dbus.Variant{
"writable": dbus.MakeVariant(options.Writeable),
"ask": dbus.MakeVariant(options.Ask),
}

if options.HandleToken != "" {
data["handle_token"] = dbus.MakeVariant(options.HandleToken)
}

obj := conn.Object(apis.ObjectName, apis.ObjectPath)
call := obj.Call(openURICallName, 0, parentWindow, uri, data)
Expand Down

0 comments on commit aff469f

Please sign in to comment.