Skip to content

Commit

Permalink
Merge pull request XX-net#1730 from cc941201/master
Browse files Browse the repository at this point in the history
Mac状态栏图标:添加自动代理选项和Thunderbolt以太网卡的支持
  • Loading branch information
xxnet committed Dec 26, 2015
2 parents a6bd3c6 + d30a1f5 commit 3faa22a
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions launcher/mac_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,27 +95,40 @@ 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)
os.system(cmd)

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)
Expand Down Expand Up @@ -159,4 +175,3 @@ def main():
if __name__ == '__main__':
main()
#sys_tray.dialog_yes_no("test", "test message")

0 comments on commit 3faa22a

Please sign in to comment.