-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build systray && !darwin && !windows | ||
|
||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
func filePathToURL(name string) (string, error) { | ||
path, err := filepath.Abs(name) | ||
if err != nil { // can't pwd if name was relative, probably impossible | ||
return "", err | ||
} | ||
return "file://" + path, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//go:build systray && darwin | ||
|
||
package main | ||
|
||
import ( | ||
"net/url" | ||
"path/filepath" | ||
) | ||
|
||
// Darwin appears to need paths pre-escaped. | ||
|
||
func filePathToURL(name string) (string, error) { | ||
path, err := filepath.Abs(name) | ||
if err != nil { // can't pwd if name was relative, probably impossible | ||
return "", err | ||
} | ||
fileURL, err := url.Parse("file://" + path) | ||
if err != nil { | ||
return "", err | ||
} | ||
// url.Parse can be touchy, so consider replacing only spaces, manually: | ||
// path = strings.ReplaceAll(path, " ", "%20") | ||
return fileURL.String(), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build systray && windows | ||
|
||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
// Windows requires a leading "/" before the "C:" of an absolute path, and | ||
// slashes converted to forward slashes. | ||
// https://en.wikipedia.org/wiki/File_URI_scheme#Windows | ||
|
||
func filePathToURL(name string) (string, error) { | ||
path, err := filepath.Abs(name) | ||
if err != nil { // can't pwd if name was relative, probably impossible | ||
return "", err | ||
} | ||
path = filepath.ToSlash(path) | ||
return "file:///" + path, 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