Skip to content

Commit

Permalink
ping
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Mar 2, 2020
1 parent 44688d8 commit d9cc86f
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 223 deletions.
Binary file added Build/V2rayUHelper
Binary file not shown.
Binary file removed Build/V2rayUPort
Binary file not shown.
2 changes: 0 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ target 'V2rayU' do
pod 'Preferences', :git => 'https://github.com/sindresorhus/Preferences.git'
pod 'Sparkle'
pod 'QRCoder'
pod "GCDWebServer"
pod 'SwiftSocket', :git => 'https://github.com/odariusgeorge/SwiftSocket.git', :branch => 'patch-1'
pod 'MASShortcut'
pod 'Swifter', '~> 1.4.7'

Expand Down
17 changes: 1 addition & 16 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
PODS:
- Alamofire (4.8.2)
- GCDWebServer (3.5.2):
- GCDWebServer/Core (= 3.5.2)
- GCDWebServer/Core (3.5.2)
- MASShortcut (2.3.6)
- Preferences (0.3.0)
- QRCoder (1.1.0)
- Sparkle (1.21.3)
- Swifter (1.4.7)
- SwiftSocket (2.0.2)
- SwiftyJSON (5.0.0)

DEPENDENCIES:
- Alamofire
- GCDWebServer
- MASShortcut
- Preferences (from `https://github.com/sindresorhus/Preferences.git`)
- QRCoder
- Sparkle
- Swifter (~> 1.4.7)
- SwiftSocket (from `https://github.com/odariusgeorge/SwiftSocket.git`, branch `patch-1`)
- SwiftyJSON

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- Alamofire
- GCDWebServer
- MASShortcut
- QRCoder
- Sparkle
Expand All @@ -35,29 +28,21 @@ SPEC REPOS:
EXTERNAL SOURCES:
Preferences:
:git: https://github.com/sindresorhus/Preferences.git
SwiftSocket:
:branch: patch-1
:git: https://github.com/odariusgeorge/SwiftSocket.git

CHECKOUT OPTIONS:
Preferences:
:commit: e2e2aaba41b531a642934a17c9b37149dd1c294c
:git: https://github.com/sindresorhus/Preferences.git
SwiftSocket:
:commit: fadd0e198d146f773fbe3b5a095cdadbd71c51c8
:git: https://github.com/odariusgeorge/SwiftSocket.git

SPEC CHECKSUMS:
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3
GCDWebServer: ead88cd14596dd4eae4f5830b8877c87c8728990
MASShortcut: 9c215e8a8a78f3d01ce56da48e2730ab66b538fa
Preferences: cfd4b0cbc5adfb5781b819ad3a000324d0fc9f48
QRCoder: cbd2bee531cc86d286df7942334cfed94c803ae4
Sparkle: 3f75576db8b0265adef36c43249d747f22d0b708
Swifter: 2327ef5d872c638aebab79646ce494af508b0c8f
SwiftSocket: 2f7a7e26a7489f5f33b69da914ec366368dfcbcc
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7

PODFILE CHECKSUM: 5f8ca0729788c399da041513b75057075032e5e1
PODFILE CHECKSUM: 054cde09fcbe129251cfb00081fde05a0c2668de

COCOAPODS: 1.8.4
8 changes: 4 additions & 4 deletions V2rayU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
66973EB721797719001FEA1E /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66973EB621797719001FEA1E /* ServiceManagement.framework */; };
66ACB1A021757D5B005B5881 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66ACB19F21757D5B005B5881 /* MainMenu.swift */; };
66BC2B89228C589E00FBB716 /* V2raySubscribe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66BC2B88228C589E00FBB716 /* V2raySubscribe.swift */; };
66C5B199240C1EF7008A22CA /* V2rayUPort in CopyFiles */ = {isa = PBXBuildFile; fileRef = 66C5B198240C1EEE008A22CA /* V2rayUPort */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
66C5B19B240D3483008A22CA /* V2rayUHelper in CopyFiles */ = {isa = PBXBuildFile; fileRef = 66C5B19A240D3476008A22CA /* V2rayUHelper */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
66F07CF9236D79540088A4AE /* ping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66F07CF8236D79540088A4AE /* ping.swift */; };
66F302A522AAA1D400FCA4E2 /* V2rayUTool in CopyFiles */ = {isa = PBXBuildFile; fileRef = 66F3029922AA9C0900FCA4E2 /* V2rayUTool */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
66F411B121CA49EE007AAC10 /* pac in Copy Files */ = {isa = PBXBuildFile; fileRef = 6683B1EA21C2AD1A004A1C5F /* pac */; };
Expand Down Expand Up @@ -88,7 +88,7 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
66C5B199240C1EF7008A22CA /* V2rayUPort in CopyFiles */,
66C5B19B240D3483008A22CA /* V2rayUHelper in CopyFiles */,
66F302A522AAA1D400FCA4E2 /* V2rayUTool in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -179,7 +179,7 @@
66BC2B88228C589E00FBB716 /* V2raySubscribe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = V2raySubscribe.swift; sourceTree = "<group>"; };
66C5B194240B58B8008A22CA /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = ../en.lproj/PreferenceAdvance.strings; sourceTree = "<group>"; };
66C5B197240C17F2008A22CA /* main.go */ = {isa = PBXFileReference; lastKnownFileType = text; path = main.go; sourceTree = "<group>"; };
66C5B198240C1EEE008A22CA /* V2rayUPort */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = V2rayUPort; sourceTree = "<group>"; };
66C5B19A240D3476008A22CA /* V2rayUHelper */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = V2rayUHelper; sourceTree = "<group>"; };
66F07CF8236D79540088A4AE /* ping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ping.swift; sourceTree = "<group>"; };
66F3029922AA9C0900FCA4E2 /* V2rayUTool */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = V2rayUTool; sourceTree = "<group>"; };
66F3029C22AAA0A600FCA4E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -357,7 +357,7 @@
66FEAD44217D75D7009DECF9 /* Build */ = {
isa = PBXGroup;
children = (
66C5B198240C1EEE008A22CA /* V2rayUPort */,
66C5B19A240D3476008A22CA /* V2rayUHelper */,
66F3029922AA9C0900FCA4E2 /* V2rayUTool */,
664FC05321A70C4300048FE3 /* build.plist */,
66FEAD45217D75FC009DECF9 /* release.sh */,
Expand Down
5 changes: 4 additions & 1 deletion V2rayU/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if UserDefaults.get(forKey: .autoUpdateServers) == nil {
UserDefaults.setBool(forKey: .autoUpdateServers, value: true)
}
if UserDefaults.get(forKey: .autoSelectFastestServer) == nil {
UserDefaults.setBool(forKey: .autoSelectFastestServer, value: false)
}
if UserDefaults.get(forKey: .autoLaunch) == nil {
SMLoginItemSetEnabled(launcherAppIdentifier as CFString, true)
UserDefaults.setBool(forKey: .autoLaunch, value: true)
Expand Down Expand Up @@ -141,7 +144,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
V2raySubSync().sync()
}
// ping
menuController.pingAtLaunch()
PingSpeed().pingAll()
}

@objc func onSleepNote(note: NSNotification) {
Expand Down
2 changes: 1 addition & 1 deletion V2rayU/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<action selector="openPreferencePac:" target="hcZ-V7-Dui" id="q2a-9U-SCe"/>
</connections>
</menuItem>
<menuItem title="Ping Speed..." id="Ow7-xo-xhV">
<menuItem title="Ping Speed..." tag="1" id="Ow7-xo-xhV">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="pingSpeed:" target="hcZ-V7-Dui" id="S0e-Q3-a8R"/>
Expand Down
30 changes: 21 additions & 9 deletions V2rayU/Base.lproj/PreferenceGeneral.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<outlet property="autoCheckVersion" destination="m2S-Mu-rFM" id="GQD-EA-vJj"/>
<outlet property="autoClearLog" destination="hIN-yp-Qul" id="Iib-Re-pDz"/>
<outlet property="autoLaunch" destination="NZE-cI-j04" id="ktV-ps-tl4"/>
<outlet property="autoSelectFastestServer" destination="Kbp-GI-fkh" id="9YM-i1-pvY"/>
<outlet property="autoUpdateServers" destination="1FR-Yu-tqb" id="5TK-uS-ear"/>
<outlet property="view" destination="bXz-rK-jao" id="xYY-dt-fo2"/>
</connections>
Expand All @@ -22,7 +23,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VO1-gl-rxy" userLabel="update servers">
<rect key="frame" x="62" y="241" width="315" height="18"/>
<rect key="frame" x="62" y="245" width="315" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Automatically update servers from subscriptions" bezelStyle="regularSquare" imagePosition="left" inset="2" id="1FR-Yu-tqb">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -33,7 +34,7 @@
</buttonCell>
</button>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tgw-Vy-D08" userLabel="check version">
<rect key="frame" x="62" y="288" width="218" height="18"/>
<rect key="frame" x="62" y="291" width="218" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Check for updates automutically" bezelStyle="regularSquare" imagePosition="left" inset="2" id="m2S-Mu-rFM">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -44,7 +45,7 @@
</buttonCell>
</button>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="59o-dL-xSh" userLabel="clear log">
<rect key="frame" x="62" y="264" width="261" height="18"/>
<rect key="frame" x="62" y="268" width="261" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Automatically clear logs after launching" bezelStyle="regularSquare" imagePosition="left" inset="2" id="hIN-yp-Qul">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -66,21 +67,21 @@
</buttonCell>
</button>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Elj-N8-4IK" customClass="MASShortcutView">
<rect key="frame" x="247" y="183" width="139" height="19"/>
<rect key="frame" x="247" y="169" width="139" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="associatedUserDefaultsKey" value="SwitchProxyMode"/>
</userDefinedRuntimeAttributes>
</customView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ti4-xg-ncf" customClass="MASShortcutView">
<rect key="frame" x="247" y="206" width="139" height="19"/>
<rect key="frame" x="247" y="192" width="139" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="associatedUserDefaultsKey" value="ToggleRunning"/>
</userDefinedRuntimeAttributes>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UhI-5l-Ytp">
<rect key="frame" x="64" y="184" width="174" height="17"/>
<rect key="frame" x="64" y="170" width="174" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Switch Proxy Mode:" id="Eu4-bo-oYs">
<font key="font" metaFont="system"/>
Expand All @@ -89,7 +90,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vtN-0c-sip">
<rect key="frame" x="64" y="207" width="174" height="17"/>
<rect key="frame" x="64" y="193" width="174" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Toggle V2ray On/Off:" id="0rn-re-Wn3">
<font key="font" metaFont="system"/>
Expand All @@ -109,7 +110,7 @@
</connections>
</button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2M9-7e-aJI">
<rect key="frame" x="64" y="66" width="324" height="78"/>
<rect key="frame" x="64" y="59" width="324" height="78"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" selectable="YES" borderStyle="border" drawsBackground="YES" id="vHZ-BS-uFb">
<font key="font" size="12" name="HelveticaNeue"/>
Expand All @@ -122,7 +123,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IRP-lJ-E8h">
<rect key="frame" x="64" y="148" width="174" height="17"/>
<rect key="frame" x="64" y="141" width="174" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Related file locations:" id="Oke-cL-DfS">
<font key="font" metaFont="system"/>
Expand All @@ -141,6 +142,17 @@
<action selector="checkVersion:" target="-2" id="4u0-Zb-Xfz"/>
</connections>
</button>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="oUQ-Ax-ZJE" userLabel="update servers">
<rect key="frame" x="62" y="222" width="341" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Automatically select the fastest server by ping" bezelStyle="regularSquare" imagePosition="left" inset="2" id="Kbp-GI-fkh">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="SetAutoSelectFastestServer:" target="-2" id="W5l-s1-mLF"/>
</connections>
</button>
</subviews>
<point key="canvasLocation" x="-144" y="-243"/>
</view>
Expand Down
56 changes: 3 additions & 53 deletions V2rayU/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class MenuController: NSObject, NSMenuDelegate {
}

// ping
self.pingAtLaunch()
PingSpeed().pingAll()
}

@IBAction func openLogs(_ sender: NSMenuItem) {
Expand Down Expand Up @@ -400,7 +400,7 @@ class MenuController: NSObject, NSMenuDelegate {
}

let menuItem: NSMenuItem = NSMenuItem()
menuItem.title = String(item.speed) + "ms\t " + item.remark
menuItem.title = (item.speed.count > 0 ? item.speed : "-1ms") + "\t " + item.remark
menuItem.action = #selector(self.switchServer(_:))
menuItem.representedObject = item
menuItem.target = self
Expand Down Expand Up @@ -551,32 +551,7 @@ class MenuController: NSObject, NSMenuDelegate {
}

@IBAction func pingSpeed(_ sender: NSMenuItem) {
let normalTitle = sender.title
sender.title = "\(normalTitle) - In Testing"

let itemList = V2rayServer.list()
if itemList.count == 0 {
return
}

let queue = DispatchQueue.global()
queue.async {
for item in itemList {
if !item.isValid {
continue
}

let ping = Ping(item: item)
ping.pingProxySpeed()
}
V2rayServer.saveItemList()

DispatchQueue.main.async {
sender.title = normalTitle
// refresh server
self.showServers()
}
}
PingSpeed().pingAll()
}

@IBAction func viewConfig(_ sender: Any) {
Expand All @@ -588,31 +563,6 @@ class MenuController: NSObject, NSMenuDelegate {
NSWorkspace.shared.open(url)
}

func pingAtLaunch() {
let itemList = V2rayServer.list()
if itemList.count == 0 {
return
}

let queue = DispatchQueue.global()
queue.async {
for item in itemList {
if !item.isValid {
continue
}

let ping = Ping(item: item)
ping.pingProxySpeed()
}
V2rayServer.saveItemList()

DispatchQueue.main.async {
// refresh server
self.showServers()
}
}
}

func importUri(url: String) {
let urls = url.split(separator: "\n")

Expand Down
14 changes: 6 additions & 8 deletions V2rayU/Preference/PreferenceGeneral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
@IBOutlet weak var autoCheckVersion: NSButtonCell!
@IBOutlet weak var autoClearLog: NSButtonCell!
@IBOutlet weak var autoUpdateServers: NSButtonCell!
@IBOutlet weak var autoSelectFastestServer: NSButtonCell!

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -64,6 +65,10 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
UserDefaults.setBool(forKey: .autoUpdateServers, value: sender.state == .on)
}

@IBAction func SetAutoSelectFastestServer(_ sender: NSButton) {
UserDefaults.setBool(forKey: .autoSelectFastestServer, value: sender.state == .on)
}

@IBAction func goFeedback(_ sender: NSButton) {
guard let url = URL(string: "https://github.com/yanue/v2rayu/issues") else {
return
Expand All @@ -75,12 +80,5 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
// need set SUFeedURL into plist
V2rayUpdater.checkForUpdates(sender)
}

@IBAction func openLogs(_ sender: NSButton) {
V2rayLaunch.OpenLogs()
}

@IBAction func clearLogs(_ sender: NSButton) {
V2rayLaunch.ClearLogs()
}

}
Loading

0 comments on commit d9cc86f

Please sign in to comment.