diff --git a/go.mod b/go.mod index b6ba4adc..84fa843e 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect github.com/nicksnyder/go-i18n/v2 v2.5.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rymdport/portal v0.3.0 // indirect + github.com/rymdport/portal v0.4.0 // indirect github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect github.com/stretchr/testify v1.10.0 // indirect diff --git a/go.sum b/go.sum index f657f5c3..73768d3b 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rymdport/portal v0.3.0 h1:QRHcwKwx3kY5JTQcsVhmhC3TGqGQb9LFghVNUy8AdB8= -github.com/rymdport/portal v0.3.0/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4= +github.com/rymdport/portal v0.4.0 h1:0i1amcprI7gnulxp4AahwSuFlN84287/A9pVWValjCI= +github.com/rymdport/portal v0.4.0/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4= github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE= github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ= diff --git a/vendor/github.com/rymdport/portal/CHANGELOG.md b/vendor/github.com/rymdport/portal/CHANGELOG.md new file mode 100644 index 00000000..f60248e0 --- /dev/null +++ b/vendor/github.com/rymdport/portal/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +Changes are listed below. Before v1.0.0, versions that change the minor field contain breaking changes. Patch releases still only contain fixes. + +## v0.4.0 + +- Rename the `Writeable` field in `openuri.OpenURIOptions` to `Writable` to fix spelling error. +- Implement the `OpenFile` and `OpenDirectory` functions in the `OpenURI` protocol. +- Implement the `Trash` protocol. +- Add some new helpers to the `settings/appearance` package to convert `any` values to corresponding values. Useful inside the change listener of the `settings` package. \ No newline at end of file diff --git a/vendor/github.com/rymdport/portal/README.md b/vendor/github.com/rymdport/portal/README.md index 4e1dd220..dcf96bf0 100644 --- a/vendor/github.com/rymdport/portal/README.md +++ b/vendor/github.com/rymdport/portal/README.md @@ -84,7 +84,8 @@ The list below contains all of the portal APIs available as of 2024-03-14. Check - [ ] Secret - [ ] Session - [x] Settings -- [ ] Trash +- [x] Trash +- [ ] Usb - [ ] Wallpaper diff --git a/vendor/github.com/rymdport/portal/openuri/opendir.go b/vendor/github.com/rymdport/portal/openuri/opendir.go new file mode 100644 index 00000000..acd5081a --- /dev/null +++ b/vendor/github.com/rymdport/portal/openuri/opendir.go @@ -0,0 +1,42 @@ +package openuri + +import ( + "github.com/godbus/dbus/v5" + "github.com/rymdport/portal/internal/apis" + "github.com/rymdport/portal/internal/convert" +) + +const openDirCallName = openURIBaseName + ".OpenDirectory" + +// OpenDirOptions holds optional settings that can be passed to the OpenDir call. +type OpenDirOptions struct { + HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element. + Writable 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. +} + +// OpenDirectory asks to open the directory containing a local file in the file browser. +// The input parameter fd should be a file descriptor like the one given from [*os.File.Fd] for example. +func OpenDirectory(parentWindow string, fd uintptr, options *OpenDirOptions) error { + conn, err := dbus.SessionBus() // Shared connection, don't close. + if err != nil { + return err + } + + data := map[string]dbus.Variant{} + + if options != nil { + data = map[string]dbus.Variant{ + "writable": convert.FromBool(options.Writable), + "ask": convert.FromBool(options.Ask), + } + + if options.HandleToken != "" { + data["handle_token"] = convert.FromString(options.HandleToken) + } + } + + obj := conn.Object(apis.ObjectName, apis.ObjectPath) + call := obj.Call(openDirCallName, 0, parentWindow, dbus.UnixFD(fd), data) + return call.Err +} diff --git a/vendor/github.com/rymdport/portal/openuri/openfile.go b/vendor/github.com/rymdport/portal/openuri/openfile.go new file mode 100644 index 00000000..cc2b8dc7 --- /dev/null +++ b/vendor/github.com/rymdport/portal/openuri/openfile.go @@ -0,0 +1,42 @@ +package openuri + +import ( + "github.com/godbus/dbus/v5" + "github.com/rymdport/portal/internal/apis" + "github.com/rymdport/portal/internal/convert" +) + +const openFileCallName = openURIBaseName + ".OpenFile" + +// OpenFileOptions holds optional settings that can be passed to the OpenFile call. +type OpenFileOptions struct { + HandleToken string // A string that will be used as the last element of the handle. Must be a valid object path element. + Writable 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. +} + +// OpenFile asks to open a local file. +// The input parameter fd should be a file descriptor like the one given from [*os.File.Fd] for example. +func OpenFile(parentWindow string, fd uintptr, options *OpenFileOptions) error { + conn, err := dbus.SessionBus() // Shared connection, don't close. + if err != nil { + return err + } + + data := map[string]dbus.Variant{} + + if options != nil { + data = map[string]dbus.Variant{ + "writable": convert.FromBool(options.Writable), + "ask": convert.FromBool(options.Ask), + } + + if options.HandleToken != "" { + data["handle_token"] = convert.FromString(options.HandleToken) + } + } + + obj := conn.Object(apis.ObjectName, apis.ObjectPath) + call := obj.Call(openFileCallName, 0, parentWindow, dbus.UnixFD(fd), data) + return call.Err +} diff --git a/vendor/github.com/rymdport/portal/openuri/openuri.go b/vendor/github.com/rymdport/portal/openuri/openuri.go index 815cc53d..fc4f4204 100644 --- a/vendor/github.com/rymdport/portal/openuri/openuri.go +++ b/vendor/github.com/rymdport/portal/openuri/openuri.go @@ -16,11 +16,13 @@ const ( // 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. + Writable 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. +// Note that file:// URIs are explicitly not supported by this method. +// To request opening local files, use [OpenFile]. func OpenURI(parentWindow, uri string, options *OpenURIOptions) error { conn, err := dbus.SessionBus() // Shared connection, don't close. if err != nil { @@ -31,7 +33,7 @@ func OpenURI(parentWindow, uri string, options *OpenURIOptions) error { if options != nil { data = map[string]dbus.Variant{ - "writable": convert.FromBool(options.Writeable), + "writable": convert.FromBool(options.Writable), "ask": convert.FromBool(options.Ask), } diff --git a/vendor/github.com/rymdport/portal/settings/appearance/color.go b/vendor/github.com/rymdport/portal/settings/appearance/color.go index 8a7cc6d2..c1ad865c 100644 --- a/vendor/github.com/rymdport/portal/settings/appearance/color.go +++ b/vendor/github.com/rymdport/portal/settings/appearance/color.go @@ -26,12 +26,7 @@ func GetColorScheme() (ColorScheme, error) { return NoPreference, err } - result := value.(uint32) - if result > 2 { - result = 0 // Unknown values should be treated as 0 (no preference). - } - - return ColorScheme(result), nil + return ValueToColorScheme(value) } // GetAccentColor returns the currently set accent color. @@ -42,7 +37,34 @@ func GetAccentColor() (*color.RGBA, error) { return nil, ErrNotSet } - result := value.([]float64) + return ValueToAccentColor(value) +} + +// ValueToColorScheme converts a read value to a ColorScheme type. +// This is useful when for example parsing a value from the callback +// in [settings.SignalOnSettingChanged] or a value from [settings.ReadOne]. +func ValueToColorScheme(value any) (ColorScheme, error) { + result, ok := value.(uint32) + if !ok { + return NoPreference, ErrNotSet + } + + if result > 2 { + return 0, nil // Unknown values should be treated as 0 (no preference). + } + + return ColorScheme(result), nil +} + +// ValueToAccentColor converts a read value to an accent color type. +// This is useful when for example parsing a value from the callback +// in [settings.SignalOnSettingChanged] or a value from [settings.ReadOne]. +func ValueToAccentColor(value any) (*color.RGBA, error) { + result, ok := value.([]float64) + if !ok { + return nil, ErrNotSet + } + if len(result) != 4 { return nil, ErrNotSet } diff --git a/vendor/github.com/rymdport/portal/settings/appearance/contrast.go b/vendor/github.com/rymdport/portal/settings/appearance/contrast.go index 0cf900ab..dc61d800 100644 --- a/vendor/github.com/rymdport/portal/settings/appearance/contrast.go +++ b/vendor/github.com/rymdport/portal/settings/appearance/contrast.go @@ -17,9 +17,20 @@ func GetContrast() (Contrast, error) { return NormalContrast, err } - result := value.(uint32) + return ValueToContrast(value) +} + +// ValueToContrast converts a read value to a Contrast type. +// This is useful when for example parsing a value from the callback +// in [settings.SignalOnSettingChanged] or a value from [settings.ReadOne]. +func ValueToContrast(value any) (Contrast, error) { + result, ok := value.(uint32) + if !ok { + return NormalContrast, ErrNotSet + } + if result > 1 { - result = 0 // Unknown values should be treated as 0 (no preference). + return 0, nil // Unknown values should be treated as 0 (no preference). } return Contrast(result), nil diff --git a/vendor/modules.txt b/vendor/modules.txt index 6bdf3c12..41575446 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -138,7 +138,7 @@ github.com/nicksnyder/go-i18n/v2/internal/plural # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/rymdport/portal v0.3.0 +# github.com/rymdport/portal v0.4.0 ## explicit; go 1.19 github.com/rymdport/portal github.com/rymdport/portal/internal/apis