diff --git a/launcher/mac_tray.py b/launcher/mac_tray.py index a4498b5a34..4728064f89 100644 --- a/launcher/mac_tray.py +++ b/launcher/mac_tray.py @@ -54,10 +54,13 @@ def setupUI(self): menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Config', 'config:', '') self.menu.addItem_(menuitem) - menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Enable Global Goagent Proxy', 'enableProxy:', '') + menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Enable Auto Goagent Proxy', 'enableAutoProxy:', '') self.menu.addItem_(menuitem) - menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Disable Global Goagent Proxy', 'disableProxy:', '') + menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Enable Global Goagent Proxy', 'enableGlobalProxy:', '') + self.menu.addItem_(menuitem) + + menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Disable Goagent Proxy', 'disableProxy:', '') self.menu.addItem_(menuitem) # Rest Menu Item @@ -92,16 +95,24 @@ def resetGoagent_(self, _): module_init.stop("gae_proxy") module_init.start("gae_proxy") - def enableProxy_(self, _): + def enableAutoProxy_(self, _): + cmd1 = "networksetup -setautoproxyurl Ethernet \\\"http://127.0.0.1:8086/proxy.pac\\\"" + cmd2 = "networksetup -setautoproxyurl \\\"Thunderbolt Ethernet\\\" \\\"http://127.0.0.1:8086/proxy.pac\\\"" + cmd3 = "networksetup -setautoproxyurl Wi-Fi \\\"http://127.0.0.1:8086/proxy.pac\\\"" + exec_command = "%s;%s;%s" % (cmd1, cmd2, cmd3) + admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command + cmd = admin_command.encode('utf-8') + xlog.info("try enable proxy:%s", cmd) + os.system(cmd) + + def enableGlobalProxy_(self, _): cmd1 = "networksetup -setwebproxy Ethernet 127.0.0.1 8087" - cmd2 = "networksetup -setwebproxy Wi-Fi 127.0.0.1 8087" - cmd3 = "networksetup -setwebproxystate Ethernet on" - cmd4 = "networksetup -setwebproxystate Wi-Fi on" - cmd5 = "networksetup -setsecurewebproxy Ethernet 127.0.0.1 8087" + cmd2 = "networksetup -setwebproxy \\\"Thunderbolt Ethernet\\\" 127.0.0.1 8087" + cmd3 = "networksetup -setwebproxy Wi-Fi 127.0.0.1 8087" + cmd4 = "networksetup -setsecurewebproxy Ethernet 127.0.0.1 8087" + cmd5 = "networksetup -setsecurewebproxy \\\"Thunderbolt Ethernet\\\" 127.0.0.1 8087" cmd6 = "networksetup -setsecurewebproxy Wi-Fi 127.0.0.1 8087" - cmd7 = "networksetup -setsecurewebproxystate Ethernet on" - cmd8 = "networksetup -setsecurewebproxystate Wi-Fi on" - exec_command = "%s;%s;%s;%s;%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8) + exec_command = "%s;%s;%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4, cmd5, cmd6) admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command cmd = admin_command.encode('utf-8') xlog.info("try enable proxy:%s", cmd) @@ -109,10 +120,15 @@ def enableProxy_(self, _): def disableProxy_(self, _): cmd1 = "networksetup -setwebproxystate Ethernet off" - cmd2 = "networksetup -setwebproxystate Wi-Fi off" - cmd3 = "networksetup -setsecurewebproxystate Ethernet off" - cmd4 = "networksetup -setsecurewebproxystate Wi-Fi off" - exec_command = "%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4) + cmd2 = "networksetup -setwebproxystate \\\"Thunderbolt Ethernet\\\" off" + cmd3 = "networksetup -setwebproxystate Wi-Fi off" + cmd4 = "networksetup -setsecurewebproxystate Ethernet off" + cmd5 = "networksetup -setsecurewebproxystate \\\"Thunderbolt Ethernet\\\" off" + cmd6 = "networksetup -setsecurewebproxystate Wi-Fi off" + cmd7 = "networksetup -setautoproxystate Ethernet off" + cmd8 = "networksetup -setautoproxystate \\\"Thunderbolt Ethernet\\\" off" + cmd9 = "networksetup -setautoproxystate Wi-Fi off" + exec_command = "%s;%s;%s;%s;%s;%s;%s;%s;%s" % (cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8, cmd9) admin_command = """osascript -e 'do shell script "%s" with administrator privileges' """ % exec_command cmd = admin_command.encode('utf-8') xlog.info("try disable proxy:%s", cmd) @@ -159,4 +175,3 @@ def main(): if __name__ == '__main__': main() #sys_tray.dialog_yes_no("test", "test message") -