Updates GO (Desktop) to support multiple extension filters

This commit is contained in:
Miguel Ruivo 2020-04-08 12:45:06 +01:00
parent 8fdecd6b8b
commit d67b369715
5 changed files with 44 additions and 27 deletions

View File

@ -1,3 +1,7 @@
## 1.6.2
* Updates GO (Desktop) to support multiple extension filters.
## 1.6.1
* Addresses an issue that could result in permission handler resolving requests from other activities.

View File

@ -9,21 +9,27 @@ import (
"github.com/pkg/errors"
)
func fileFilter(method string) (string, error) {
func fileFilter(method string, extensions []string, size int) (string, error) {
switch method {
case "ANY":
case "any":
return `"public.item"`, nil
case "IMAGE":
case "image":
return `"public.image"`, nil
case "AUDIO":
case "audio":
return `"public.audio"`, nil
case "VIDEO":
case "video":
return `"public.movie"`, nil
default:
if strings.HasPrefix(method, "__CUSTOM_") {
resolveType := strings.Split(method, "__CUSTOM_")
return `"` + resolveType[1] + `"`, nil
case "custom":
var i int
var filters = ""
for i = 0 ; i<size ; i++ {
filters += `"` + extensions[i] + `"`
if i < size - 1 {
filters += `,`
}
}
return filters, nil
default:
return "", errors.New("unknown method")
}

View File

@ -7,21 +7,24 @@ import (
"github.com/pkg/errors"
)
func fileFilter(method string) (string, error) {
func fileFilter(method string, extensions []string, size int) (string, error) {
switch method {
case "ANY":
case "any":
return `*.*`, nil
case "IMAGE":
case "image":
return `*.png *.jpg *.jpeg`, nil
case "AUDIO":
case "audio":
return `*.mp3`, nil
case "VIDEO":
case "video":
return `*.webm *.mpeg *.mkv *.mp4 *.avi *.mov *.flv`, nil
default:
if strings.HasPrefix(method, "__CUSTOM_") {
resolveType := strings.Split(method, "__CUSTOM_")
return `*.` + resolveType[1], nil
case "custom":
var i int
var filters = ""
for i = 0 ; i<size ; i++ {
filters += `*.` + extensions[i] + ` `
}
return filters, nil
default:
return "", errors.New("unknown method")
}

View File

@ -9,19 +9,23 @@ import (
func fileFilter(method string) (string, error) {
switch method {
case "ANY":
case "any":
return "*", nil
case "IMAGE":
case "image":
return "Images (*.jpeg,*.png,*.gif)\x00*.jpg;*.jpeg;*.png;*.gif\x00All Files (*.*)\x00*.*\x00\x00", nil
case "AUDIO":
case "audio":
return "Audios (*.mp3)\x00*.mp3\x00All Files (*.*)\x00*.*\x00\x00", nil
case "VIDEO":
case "video":
return "Videos (*.webm,*.wmv,*.mpeg,*.mkv,*.mp4,*.avi,*.mov,*.flv)\x00*.webm;*.wmv;*.mpeg;*.mkv;*mp4;*.avi;*.mov;*.flv\x00All Files (*.*)\x00*.*\x00\x00", nil
default:
if strings.HasPrefix(method, "__CUSTOM_") {
resolveType := strings.Split(method, "__CUSTOM_")
return "Files (*." + resolveType[1] + ")\x00*." + resolveType[1] + "\x00All Files (*.*)\x00*.*\x00\x00", nil
case "custom":
var i int
var filters = "Files ("
for i = 0 ; i<size ; i++ {
filters += `*.` extensions[i] + `,`
}
filters += ")\x00*." + resolveType[1] + "\x00All Files (*.*)\x00*.*\x00\x00"
return filters, nil
default:
return "", errors.New("unknown method")
}
}

View File

@ -1,7 +1,7 @@
name: file_picker
description: A package that allows you to use a native file explorer to pick single or multiple absolute file paths, with extension filtering support.
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
version: 1.6.1
version: 1.6.2
dependencies:
flutter: