feat: added OpenFile

This commit is contained in:
Lea Anthony
2019-06-19 20:49:39 +10:00
parent 5c8a4de446
commit abcc869537
5 changed files with 31 additions and 10 deletions
+15 -4
View File
@@ -28,7 +28,7 @@ func (i *internalMethods) processCall(callData *callData) (interface{}, error) {
group := splitCall[0]
switch group {
case "browser":
case "Browser":
return i.processBrowserCommand(splitCall[1], callData.Data)
default:
return nil, fmt.Errorf("Unknown internal command group '%s'", group)
@@ -37,7 +37,7 @@ func (i *internalMethods) processCall(callData *callData) (interface{}, error) {
func (i *internalMethods) processBrowserCommand(command string, data interface{}) (interface{}, error) {
switch command {
case "openURL":
case "OpenURL":
url := data.(string)
// Strip string quotes. Credit: https://stackoverflow.com/a/44222648
if url[0] == '"' {
@@ -46,9 +46,20 @@ func (i *internalMethods) processBrowserCommand(command string, data interface{}
if i := len(url)-1; url[i] == '"' {
url = url[:i]
}
i.log.Debugf("Calling browser.openURL with '%s'", url)
i.log.Debugf("Calling Browser.OpenURL with '%s'", url)
return nil, i.browser.OpenURL(url)
case "OpenFile":
filename := data.(string)
// Strip string quotes. Credit: https://stackoverflow.com/a/44222648
if filename[0] == '"' {
filename = filename[1:]
}
if i := len(filename)-1; filename[i] == '"' {
filename = filename[:i]
}
i.log.Debugf("Calling Browser.OpenFile with '%s'", filename)
return nil, i.browser.OpenFile(filename)
default:
return nil, fmt.Errorf("Unknown browser command '%s'", command)
return nil, fmt.Errorf("Unknown Browser command '%s'", command)
}
}
+5
View File
@@ -18,3 +18,8 @@ func newRuntimeBrowser() *RuntimeBrowser {
func (r *RuntimeBrowser) OpenURL(url string) error {
return browser.OpenURL(url)
}
// OpenFile opens the given file in the system's default browser
func (r *RuntimeBrowser) OpenFile(filePath string) error {
return browser.OpenFile(filePath)
}
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+9 -4
View File
@@ -293,12 +293,17 @@
/************************* Browser **************************/
function openURL(url) {
return systemCall("browser.openURL", url);
function OpenURL(url) {
return systemCall("Browser.OpenURL", url);
}
window.wails.browser = {
openURL
function OpenFile(filename) {
return systemCall("Browser.OpenFile", filename);
}
window.wails.Browser = {
OpenURL,
OpenFile,
}
/************************* Logging **************************/