1919# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
2020
2121import os
22- import shlex
23- import subprocess
22+
23+ from gi . repository import Gdk , Gtk , Gio
2424
2525def RemoveArgs (Execline ):
2626 NewExecline = []
@@ -33,21 +33,34 @@ def RemoveArgs(Execline):
3333 NewExecline .append (elem )
3434 return NewExecline
3535
36- # Actually execute the command
37- def ExecuteCommand (cmd , commandCwd = None ):
38- if not commandCwd :
39- cwd = os .path .expanduser ( "~" );
40- else :
36+ # Actually launch the application
37+ def Launch (cmd , cwd = None ):
38+ if cwd :
39+ cmd = cwd + ' ' + cmd
40+
41+ app_info = Gio .AppInfo .create_from_commandline (cmd ,
42+ None ,
43+ Gio .AppInfoCreateFlags .SUPPORTS_STARTUP_NOTIFICATION )
44+
45+ display = Gdk .Display .get_default ()
46+ context = display .get_app_launch_context ()
47+ context .set_desktop (- 1 ) # use default screen & desktop
48+ context .set_timestamp (Gtk .get_current_event_time ())
49+
50+ app_info .launch (None , context )
51+
52+ def Execute (cmd , commandCwd = None ):
53+ if commandCwd :
4154 tmpCwd = os .path .expanduser ( commandCwd );
4255 if (os .path .exists (tmpCwd )):
4356 cwd = tmpCwd
57+ else :
58+ cwd = None
4459
4560 if isinstance ( cmd , str ):
4661 if (cmd .find ("/home/" ) >= 0 ) or (cmd .find ("xdg-su" ) >= 0 ) or (cmd .find ("\" " ) >= 0 ):
47- print ("running manually..." )
4862 try :
49- os .chdir (cwd )
50- subprocess .Popen (shlex .split (cmd ))
63+ Launch (cmd , cwd )
5164 return True
5265 except Exception as detail :
5366 print (detail )
@@ -56,19 +69,9 @@ def ExecuteCommand(cmd , commandCwd=None):
5669 cmd = RemoveArgs (cmd )
5770
5871 try :
59- os .chdir ( cwd )
6072 string = ' ' .join (cmd )
61- subprocess . Popen ( shlex . split ( string ) )
73+ Launch ( string , cwd )
6274 return True
6375 except Exception as detail :
6476 print (detail )
6577 return False
66-
67- # Execute cmd using the double fork method
68- def Execute (cmd , commandCwd = None ):
69- child_pid = os .fork ()
70- if child_pid == 0 :
71- ExecuteCommand (cmd , commandCwd )
72- os ._exit (0 )
73- else :
74- os .wait ()
0 commit comments