@@ -164,9 +164,8 @@ namespace TeeJee.System{
164164
165165 // open -----------------------------
166166
167- public bool xdg_open (string file , string user = ""){
168- string path = get_cmd_path (" xdg-open" );
169- if ((path != null ) && (path != " " )){
167+ public static bool xdg_open (string file , string user = ""){
168+ if (cmd_exists(" xdg-open" )){
170169 string cmd = " xdg-open '%s '" . printf(escape_single_quote(file));
171170 if (user. length > 0 ){
172171 cmd = " pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " . printf(user) + cmd;
@@ -189,38 +188,36 @@ namespace TeeJee.System{
189188 We will first try using xdg-open and then check for specific file managers if it fails.
190189 */
191190
192- string path;
193- int status;
194-
195- if (xdg_open_try_first){
191+ bool xdgAvailable = cmd_exists(" xdg-open" );
192+ string escaped_dir_path = escape_single_quote(dir_path);
193+ int status = - 1 ;
194+
195+ if (xdg_open_try_first && xdgAvailable){
196196 // try using xdg-open
197- path = get_cmd_path (" xdg-open" );
198- if ((path != null )&& (path != " " )){
199- string cmd = " xdg-open '%s '" . printf(escape_single_quote(dir_path));
200- status = exec_script_async (cmd);
201- return (status == 0 );
202- }
197+ string cmd = " xdg-open '%s '" . printf(escaped_dir_path);
198+ status = exec_script_async (cmd);
199+ return (status == 0 );
203200 }
204201
205202 foreach (string app_name in
206203 new string []{ " nemo" , " nautilus" , " thunar" , " io.elementary.files" , " pantheon-files" , " marlin" , " dolphin" }){
207-
208- path = get_cmd_path (app_name);
209- if ((path != null )&& (path != " " )){
210- string cmd = " %s '%s '" . printf(app_name, escape_single_quote(dir_path));
211- status = exec_script_async (cmd);
212- return (status == 0 );
204+ if (! cmd_exists(app_name)) {
205+ continue ;
206+ }
207+
208+ string cmd = " %s '%s '" . printf(app_name, escaped_dir_path);
209+ status = exec_script_async (cmd);
210+
211+ if (status == 0 ) {
212+ return true ;
213213 }
214214 }
215215
216- if (xdg_open_try_first == false ){
216+ if (! xdg_open_try_first && xdgAvailable ){
217217 // try using xdg-open
218- path = get_cmd_path (" xdg-open" );
219- if ((path != null )&& (path != " " )){
220- string cmd = " xdg-open '%s '" . printf(escape_single_quote(dir_path));
221- status = exec_script_async (cmd);
222- return (status == 0 );
223- }
218+ string cmd = " xdg-open '%s '" . printf(escaped_dir_path);
219+ status = exec_script_async (cmd);
220+ return (status == 0 );
224221 }
225222
226223 return false ;
0 commit comments