Skip to content

Commit

Permalink
fix the mac tray ask permission every time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-X-Net committed Jan 14, 2023
1 parent 1944aee commit b1d0470
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions code/default/launcher/mac_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# coding:utf-8

import os
import shutil
import sys

current_path = os.path.dirname(os.path.abspath(__file__))
helper_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir, os.pardir, 'data', 'launcher', 'helper'))
helper_path = os.path.join('/tmp', 'helper')

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

if len(services) > 0:
self.disableProxy_(services)
self.disableProxy_(True)

module_init.stop_all()
os._exit(0)
Expand Down Expand Up @@ -264,7 +265,7 @@ def enableGlobalSmartRouter_(self, _):
config.save()
self.updateStatusBarMenu()

def disableProxy_(self, _):
def disableProxy_(self, is_quit=False):
try:
helperDisableAutoProxy(currentService)
helperDisableGlobalProxy(currentService)
Expand All @@ -276,8 +277,11 @@ def disableProxy_(self, _):

xlog.info("try disable proxy:%s", executeCommand)
subprocess.call(['osascript', '-e', executeCommand])
config.os_proxy_mode = "disable"
config.save()

if is_quit != True:
# in case "Disable proxy" trigger by menu, is_quit will be a {NSMenuItem}
config.os_proxy_mode = "disable"
config.save()
self.updateStatusBarMenu()


Expand All @@ -286,12 +290,16 @@ def setupHelper():
with open(os.devnull) as devnull:
subprocess.check_call(helper_path, stderr=devnull)
except:
rmCommand = "rm \\\"%s\\\"" % helper_path
cpCommand = "cp \\\"%s\\\" \\\"%s\\\"" % (os.path.join(current_path, 'mac_helper'), helper_path)
if os.path.exists(helper_path):
os.remove(helper_path)
shutil.copyfile(os.path.join(current_path, 'mac_helper'), helper_path)

chownCommand = "chown root \\\"%s\\\"" % helper_path
chmodCommand = "chmod 4755 \\\"%s\\\"" % helper_path
executeCommand = 'do shell script "%s;%s;%s;%s" with administrator privileges' % (
rmCommand, cpCommand, chownCommand, chmodCommand)
executeCommand = 'do shell script "%s;%s" with administrator privileges' % (
chownCommand,
chmodCommand
)

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

0 comments on commit b1d0470

Please sign in to comment.