From f5739d083a37eb36d5f9e77f7dd56e9a7d0454a2 Mon Sep 17 00:00:00 2001 From: Rasmus Lindroth Date: Wed, 4 Jan 2023 19:34:06 +0100 Subject: [PATCH] don't assume xdg-open, use open on iOS and start on Windows --- config/config.go | 7 ++++++- config/toml_default.go | 10 +++++----- util/xdg.go | 23 +++++++++++++++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 5846408..60df1dd 100644 --- a/config/config.go +++ b/config/config.go @@ -809,6 +809,11 @@ func getViewer(v *ViewerTOML, def *ViewerTOML) (program, args string, terminal, if v.Reverse != nil { reverse = *v.Reverse } + if *v.Program == "TUT_OS_DEFAULT" { + var argsSlice []string + program, argsSlice = util.GetDefaultForOS() + args = strings.Join(argsSlice, " ") + } return } @@ -851,7 +856,7 @@ func parseGeneral(cfg GeneralTOML) General { def := ConfigDefault.General general.Editor = NilDefaultString(cfg.Editor, def.Editor) - if general.Editor == "USE_TUT_INTERNAL" { + if general.Editor == "TUT_USE_INTERNAL" { general.UseInternalEditor = true } general.Confirmation = NilDefaultBool(cfg.Confirmation, def.Confirmation) diff --git a/config/toml_default.go b/config/toml_default.go index 108b4d3..64c77dd 100644 --- a/config/toml_default.go +++ b/config/toml_default.go @@ -19,7 +19,7 @@ func ip64(i int64) *int64 { var ConfigDefault = ConfigTOML{ General: GeneralTOML{ - Editor: sp("USE_TUT_INTERNAL"), + Editor: sp("TUT_USE_INTERNAL"), Confirmation: bt, MouseSupport: bf, DateFormat: sp("2006-01-02 15:04"), @@ -89,28 +89,28 @@ var ConfigDefault = ConfigTOML{ }, Media: MediaTOML{ Image: &ViewerTOML{ - Program: sp("xdg-open"), + Program: sp("TUT_OS_DEFAULT"), Args: sp(""), Terminal: bf, Single: bt, Reverse: bf, }, Video: &ViewerTOML{ - Program: sp("xdg-open"), + Program: sp("TUT_OS_DEFAULT"), Args: sp(""), Terminal: bf, Single: bt, Reverse: bf, }, Audio: &ViewerTOML{ - Program: sp("xdg-open"), + Program: sp("TUT_OS_DEFAULT"), Args: sp(""), Terminal: bf, Single: bt, Reverse: bf, }, Link: &ViewerTOML{ - Program: sp("xdg-open"), + Program: sp("TUT_OS_DEFAULT"), Args: sp(""), Terminal: bf, Single: bt, diff --git a/util/xdg.go b/util/xdg.go index e38da9b..1e3449c 100644 --- a/util/xdg.go +++ b/util/xdg.go @@ -1,7 +1,26 @@ package util -import "os/exec" +import ( + "os/exec" + "runtime" +) + +func GetDefaultForOS() (program string, args []string) { + switch runtime.GOOS { + case "windows": + program = "start" + args = []string{"/wait"} + case "darwin": + program = "open" + args = []string{"-W"} + default: + program = "xdg-open" + } + return program, args +} func OpenURL(url string) { - exec.Command("xdg-open", url).Start() + program, args := GetDefaultForOS() + args = append(args, url) + exec.Command(program, args...).Start() }