Skip to content

Commit b1d0470

Browse files
committed
fix the mac tray ask permission every time.
1 parent 1944aee commit b1d0470

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

code/default/launcher/mac_tray.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# coding:utf-8
33

44
import os
5+
import shutil
56
import sys
67

78
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')
910

1011
if __name__ == "__main__":
1112
default_path = os.path.abspath(os.path.join(current_path, os.pardir))
@@ -186,7 +187,7 @@ def windowWillClose_(self, notification):
186187
service) != 'disable'] # Remove disabled services and empty lines
187188

188189
if len(services) > 0:
189-
self.disableProxy_(services)
190+
self.disableProxy_(True)
190191

191192
module_init.stop_all()
192193
os._exit(0)
@@ -264,7 +265,7 @@ def enableGlobalSmartRouter_(self, _):
264265
config.save()
265266
self.updateStatusBarMenu()
266267

267-
def disableProxy_(self, _):
268+
def disableProxy_(self, is_quit=False):
268269
try:
269270
helperDisableAutoProxy(currentService)
270271
helperDisableGlobalProxy(currentService)
@@ -276,8 +277,11 @@ def disableProxy_(self, _):
276277

277278
xlog.info("try disable proxy:%s", executeCommand)
278279
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()
281285
self.updateStatusBarMenu()
282286

283287

@@ -286,12 +290,16 @@ def setupHelper():
286290
with open(os.devnull) as devnull:
287291
subprocess.check_call(helper_path, stderr=devnull)
288292
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+
291297
chownCommand = "chown root \\\"%s\\\"" % helper_path
292298
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+
)
295303

296304
xlog.info("try setup helper:%s", executeCommand)
297305
subprocess.call(['osascript', '-e', executeCommand])

0 commit comments

Comments
 (0)