Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for non-english languages in favorites
- Loading branch information
Showing
7 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dialog | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func getFavoriteLocations() (map[string]string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return map[string]string{ | ||
"Home": homeDir, | ||
"Documents": filepath.Join(homeDir, "Documents"), | ||
"Downloads": filepath.Join(homeDir, "Downloads"), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// +build linux openbsd freebsd netbsd | ||
// +build !android | ||
|
||
package dialog | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
func getFavoriteLocation(homeDir, name string) (string, error) { | ||
cmdName := "xdg-user-dir" | ||
fallback := filepath.Join(homeDir, name) | ||
|
||
if _, err := exec.LookPath(cmdName); err != nil { | ||
return fallback, fmt.Errorf("%s not found in PATH. using fallback paths", cmdName) | ||
} | ||
|
||
cmd := exec.Command(cmdName, name) | ||
stdout := bytes.NewBufferString("") | ||
|
||
cmd.Stdout = stdout | ||
err := cmd.Run() | ||
if err != nil { | ||
return fallback, err | ||
} | ||
|
||
loc := stdout.String() | ||
// Remove \n at the end | ||
loc = loc[:len(loc)-1] | ||
|
||
if loc == homeDir { | ||
return fallback, fmt.Errorf("this computer does not have a %s folder", name) | ||
} | ||
|
||
return stdout.String(), nil | ||
} | ||
|
||
func getFavoriteLocations() (map[string]string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rv := map[string]string{ | ||
"Home": homeDir, | ||
} | ||
documentsDir, err1 := getFavoriteLocation(homeDir, "DOCUMENTS") | ||
if err == nil { | ||
rv["Documents"] = documentsDir | ||
} else { | ||
rv["Documents"] = filepath.Join(homeDir, "Documents") | ||
err = err1 | ||
} | ||
downloadsDir, err1 := getFavoriteLocation(homeDir, "DOWNLOADS") | ||
if err == nil { | ||
rv["Downloads"] = downloadsDir | ||
} else { | ||
rv["Downloads"] = filepath.Join(homeDir, "Downloads") | ||
err = err1 | ||
} | ||
|
||
return rv, err | ||
} |