@@ -27,7 +27,7 @@ defmodule Desktop.OS do
2727 if type ( ) == MacOS do
2828 name = System . get_env ( "EMU" , "beam.smp" )
2929
30- fn -> System . cmd ( "open" , [ "-a" , name ] , stderr_to_stdout: true ) end
30+ fn -> System . cmd ( "open" , [ "-a" , name ] , stderr_to_stdout: true , parallelism: true ) end
3131 |> spawn_link ( )
3232 else
3333 # Calling this on wxDirDialog segfaults on macos..
@@ -159,12 +159,78 @@ defmodule Desktop.OS do
159159 System . cmd ( "open" , [ file ] , stderr_to_stdout: true , parallelism: true )
160160
161161 Linux ->
162- System . cmd ( "xdg-open" , [ file ] , stderr_to_stdout: true , parallelism: true )
162+ System . cmd ( "xdg-open" , [ file ] ,
163+ stderr_to_stdout: true ,
164+ parallelism: true ,
165+ env: linux_env ( )
166+ )
163167
164168 _other ->
165169 Desktop.Env . wx_use_env ( )
166170 :wx_misc . launchDefaultBrowser ( file )
167171 end
168172 end )
169173 end
174+
175+ def open_url ( url ) , do: launch_default_browser ( url )
176+
177+ def open_path ( path ) do
178+ fn ->
179+ case type ( ) do
180+ MacOS ->
181+ System . cmd ( "open" , [ path ] , stderr_to_stdout: true , parallelism: true )
182+
183+ Linux ->
184+ System . cmd ( "xdg-open" , [ path ] ,
185+ stderr_to_stdout: true ,
186+ env: linux_env ( ) ,
187+ parallelism: true
188+ )
189+
190+ Windows ->
191+ # credo:disable-for-next-line Credo.Check.Warning.UnsafeExec
192+ :os . cmd ( ~c" explorer \" #{ String . replace ( path , "/" , "\\ " ) } \" " )
193+
194+ _other ->
195+ Desktop.OS . launch_default_browser ( "file://#{ path } " )
196+ end
197+ end
198+ |> spawn_link ( )
199+ end
200+
201+ def open_file_location ( file ) do
202+ fn ->
203+ case type ( ) do
204+ MacOS ->
205+ System . cmd ( "open" , [ "-R" , file ] , stderr_to_stdout: true , parallelism: true )
206+
207+ Linux ->
208+ case System . find_executable ( "nautilus" ) do
209+ nil ->
210+ open_path ( Path . dirname ( file ) )
211+
212+ nautilus ->
213+ System . cmd ( nautilus , [ file ] ,
214+ stderr_to_stdout: true ,
215+ env: linux_env ( ) ,
216+ parallelism: true
217+ )
218+ end
219+
220+ Windows ->
221+ # credo:disable-for-next-line Credo.Check.Warning.UnsafeExec
222+ :os . cmd ( ~c" explorer /select,\" #{ String . replace ( file , "/" , "\\ " ) } \" " )
223+
224+ _other ->
225+ Desktop.OS . launch_default_browser ( "file://#{ file } " )
226+ end
227+ end
228+ |> spawn_link ( )
229+ end
230+
231+ defp linux_env ( ) do
232+ # Unsetting env vars that might interfere with the desktop environment
233+ ~w( GDK_BACKEND LD_LIBRARY_PATH LD_PRELOAD GIO_MODULE_DIR GDK_PIXBUF_MODULE_FILE GST_PLUGIN_PATH GST_PLUGIN_SYSTEM_PATH GST_REGISTRY)
234+ |> Enum . map ( fn key -> { key , nil } end )
235+ end
170236end
0 commit comments