2
2
# coding:utf-8
3
3
4
4
import os
5
+ import shutil
5
6
import sys
6
7
7
8
current_path = os .path .dirname (os .path .abspath (__file__ ))
8
- helper_path = os .path .abspath ( os . path . join (current_path , os . pardir , os . pardir , os . pardir , 'data ' , 'launcher' , ' helper') )
9
+ helper_path = os .path .join ('/tmp ' , 'helper' )
9
10
10
11
if __name__ == "__main__" :
11
12
default_path = os .path .abspath (os .path .join (current_path , os .pardir ))
@@ -186,7 +187,7 @@ def windowWillClose_(self, notification):
186
187
service ) != 'disable' ] # Remove disabled services and empty lines
187
188
188
189
if len (services ) > 0 :
189
- self .disableProxy_ (services )
190
+ self .disableProxy_ (True )
190
191
191
192
module_init .stop_all ()
192
193
os ._exit (0 )
@@ -264,7 +265,7 @@ def enableGlobalSmartRouter_(self, _):
264
265
config .save ()
265
266
self .updateStatusBarMenu ()
266
267
267
- def disableProxy_ (self , _ ):
268
+ def disableProxy_ (self , is_quit = False ):
268
269
try :
269
270
helperDisableAutoProxy (currentService )
270
271
helperDisableGlobalProxy (currentService )
@@ -276,8 +277,11 @@ def disableProxy_(self, _):
276
277
277
278
xlog .info ("try disable proxy:%s" , executeCommand )
278
279
subprocess .call (['osascript' , '-e' , executeCommand ])
279
- config .os_proxy_mode = "disable"
280
- config .save ()
280
+
281
+ if is_quit != True :
282
+ # in case "Disable proxy" trigger by menu, is_quit will be a {NSMenuItem}
283
+ config .os_proxy_mode = "disable"
284
+ config .save ()
281
285
self .updateStatusBarMenu ()
282
286
283
287
@@ -286,12 +290,16 @@ def setupHelper():
286
290
with open (os .devnull ) as devnull :
287
291
subprocess .check_call (helper_path , stderr = devnull )
288
292
except :
289
- rmCommand = "rm \\ \" %s\\ \" " % helper_path
290
- cpCommand = "cp \\ \" %s\\ \" \\ \" %s\\ \" " % (os .path .join (current_path , 'mac_helper' ), helper_path )
293
+ if os .path .exists (helper_path ):
294
+ os .remove (helper_path )
295
+ shutil .copyfile (os .path .join (current_path , 'mac_helper' ), helper_path )
296
+
291
297
chownCommand = "chown root \\ \" %s\\ \" " % helper_path
292
298
chmodCommand = "chmod 4755 \\ \" %s\\ \" " % helper_path
293
- executeCommand = 'do shell script "%s;%s;%s;%s" with administrator privileges' % (
294
- rmCommand , cpCommand , chownCommand , chmodCommand )
299
+ executeCommand = 'do shell script "%s;%s" with administrator privileges' % (
300
+ chownCommand ,
301
+ chmodCommand
302
+ )
295
303
296
304
xlog .info ("try setup helper:%s" , executeCommand )
297
305
subprocess .call (['osascript' , '-e' , executeCommand ])
0 commit comments