代码拉取完成,页面将自动刷新
//go:build (linux || openbsd || freebsd || netbsd) && !android && !wasm && !js
// +build linux openbsd freebsd netbsd
// +build !android
// +build !wasm
// +build !js
package main
import (
"fmt"
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/storage"
"golang.org/x/sys/execabs"
)
func getFavoriteLocation(homeURI fyne.URI, name, fallbackName string) (fyne.URI, error) {
cmdName := "xdg-user-dir"
if _, err := execabs.LookPath(cmdName); err != nil {
return storage.Child(homeURI, fallbackName) // no lookup possible
}
cmd := execabs.Command(cmdName, name)
loc, err := cmd.Output()
if err != nil {
return storage.Child(homeURI, fallbackName)
}
// Remove \n at the end
loc = loc[:len(loc)-1]
locURI := storage.NewFileURI(string(loc))
if locURI.String() == homeURI.String() {
fallback, _ := storage.Child(homeURI, fallbackName)
return fallback, fmt.Errorf("this computer does not define a %s folder", name)
}
return locURI, nil
}
func getFavoriteLocations() (map[string]fyne.ListableURI, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, err
}
homeURI := storage.NewFileURI(homeDir)
favoriteNames := getFavoriteOrder()
arguments := map[string]string{
"Documents": "DOCUMENTS",
"Downloads": "DOWNLOAD",
"Music": "MUSIC",
"Pictures": "PICTURES",
"Videos": "VIDEOS",
}
home, _ := storage.ListerForURI(homeURI)
favoriteLocations := map[string]fyne.ListableURI{
"Home": home,
}
for _, favName := range favoriteNames {
var uri fyne.URI
uri, err = getFavoriteLocation(homeURI, arguments[favName], favName)
listURI, err1 := storage.ListerForURI(uri)
if err1 != nil {
err = err1
continue
}
favoriteLocations[favName] = listURI
}
return favoriteLocations, err
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。