Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Mar 1, 2020
1 parent 7eb04df commit 1593ceb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 66 deletions.
13 changes: 9 additions & 4 deletions V2rayU/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {


func applicationDidFinishLaunching(_ aNotification: Notification) {
// default settings
self.checkDefault()

// auto launch
if UserDefaults.getBool(forKey: .autoLaunch) {
Expand All @@ -35,8 +37,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

self.checkDefault()

// auto Clear Logs
if UserDefaults.getBool(forKey: .autoClearLog) {
print("ClearLogs")
Expand Down Expand Up @@ -97,12 +97,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if UserDefaults.get(forKey: .autoCheckVersion) == nil {
UserDefaults.setBool(forKey: .autoCheckVersion, value: true)
}
if UserDefaults.get(forKey: .autoUpdateServers) == nil {
UserDefaults.setBool(forKey: .autoUpdateServers, value: true)
}
if UserDefaults.get(forKey: .autoLaunch) == nil {
SMLoginItemSetEnabled(launcherAppIdentifier as CFString, true)
UserDefaults.setBool(forKey: .autoLaunch, value: true)
}
if UserDefaults.get(forKey: .runMode) == nil {
UserDefaults.set(forKey: .runMode, value: RunMode.manual.rawValue)
UserDefaults.set(forKey: .runMode, value: RunMode.pac.rawValue)
}
if V2rayServer.count() == 0 {
// add default
Expand Down Expand Up @@ -136,7 +139,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
V2rayUpdater.checkForUpdatesInBackground()
}
// auto update subscribe servers
V2raySubSync().sync()
if UserDefaults.getBool(forKey: .autoUpdateServers) {
V2raySubSync().sync()
}
// ping
menuController.pingAtLaunch()
}
Expand Down
110 changes: 49 additions & 61 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="autoUpdateServers" destination="1FR-Yu-tqb" id="5TK-uS-ear"/>
<outlet property="view" destination="bXz-rK-jao" id="xYY-dt-fo2"/>
</connections>
</customObject>
Expand All @@ -20,8 +21,41 @@
<rect key="frame" x="0.0" y="0.0" width="460" height="360"/>
<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"/>
<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"/>
<font key="font" metaFont="system"/>
<connections>
<action selector="SetAutoUpdateServers:" target="-2" id="ygn-My-97v"/>
</connections>
</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"/>
<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"/>
<font key="font" metaFont="system"/>
<connections>
<action selector="SetAutoCheckVersion:" target="-2" id="4Ig-pP-her"/>
</connections>
</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"/>
<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"/>
<font key="font" metaFont="system"/>
<connections>
<action selector="SetAutoClearLogs:" target="-2" id="gGD-G8-Feq"/>
</connections>
</buttonCell>
</button>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="87d-wY-Ocw">
<rect key="frame" x="64" y="305" width="163" height="18"/>
<rect key="frame" x="62" y="313" width="163" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Launch V2rayU at login" bezelStyle="regularSquare" imagePosition="left" inset="2" id="NZE-cI-j04">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -31,52 +65,6 @@
</connections>
</buttonCell>
</button>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" fixedFrame="YES" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UJB-Wh-dgF">
<rect key="frame" x="66" y="279" width="214" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="tgw-Vy-D08" userLabel="Check for Updates automutically">
<rect key="frame" x="-2" y="-2" width="218" height="18"/>
<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"/>
<font key="font" metaFont="system"/>
<connections>
<action selector="SetAutoCheckVersion:" target="-2" id="4Ig-pP-her"/>
</connections>
</buttonCell>
</button>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" fixedFrame="YES" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="WJk-22-Sun">
<rect key="frame" x="66" y="236" width="257" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="59o-dL-xSh" userLabel="Check for Updates automutically">
<rect key="frame" x="-2" y="-2" width="261" height="34"/>
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" inset="2" id="hIN-yp-Qul">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<string key="title">Automatically clear logs after launching
</string>
<font key="font" metaFont="system"/>
<connections>
<action selector="SetAutoClearLogs:" target="-2" id="gGD-G8-Feq"/>
</connections>
</buttonCell>
</button>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Elj-N8-4IK" customClass="MASShortcutView">
<rect key="frame" x="247" y="183" width="139" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand All @@ -85,7 +73,7 @@
</userDefinedRuntimeAttributes>
</customView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ti4-xg-ncf" customClass="MASShortcutView">
<rect key="frame" x="247" y="210" width="139" height="19"/>
<rect key="frame" x="247" y="206" width="139" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="associatedUserDefaultsKey" value="ToggleRunning"/>
Expand All @@ -101,27 +89,16 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vtN-0c-sip">
<rect key="frame" x="64" y="211" width="174" height="17"/>
<rect key="frame" x="64" y="207" 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"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button horizontalHuggingPriority="500" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cPC-Na-pRr">
<rect key="frame" x="60" y="21" width="182" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Check for Updates..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="2p9-GL-XZ9">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="checkVersion:" target="-2" id="4u0-Zb-Xfz"/>
</connections>
</button>
<button horizontalHuggingPriority="500" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="liJ-Uu-8HQ">
<rect key="frame" x="265" y="21" width="127" height="32"/>
<rect key="frame" x="267" y="21" width="127" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Feedback..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="QjX-NH-23u">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -153,6 +130,17 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button horizontalHuggingPriority="500" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cPC-Na-pRr">
<rect key="frame" x="58" y="21" width="182" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Check for Updates..." bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="2p9-GL-XZ9">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="checkVersion:" target="-2" id="4u0-Zb-Xfz"/>
</connections>
</button>
</subviews>
<point key="canvasLocation" x="-144" y="-243"/>
</view>
Expand Down
4 changes: 3 additions & 1 deletion V2rayU/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ class MenuController: NSObject, NSMenuDelegate {
}

// auto update subscribe servers
V2raySubSync().sync()
if UserDefaults.getBool(forKey: .autoUpdateServers) {
V2raySubSync().sync()
}

// ping
self.pingAtLaunch()
Expand Down
9 changes: 9 additions & 0 deletions V2rayU/Preference/PreferenceGeneral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
@IBOutlet weak var autoLaunch: NSButtonCell!
@IBOutlet weak var autoCheckVersion: NSButtonCell!
@IBOutlet weak var autoClearLog: NSButtonCell!
@IBOutlet weak var autoUpdateServers: NSButtonCell!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -31,6 +32,7 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
let autoLaunchState = UserDefaults.getBool(forKey: .autoLaunch)
let autoCheckVersionState = UserDefaults.getBool(forKey: .autoCheckVersion)
let autoClearLogState = UserDefaults.getBool(forKey: .autoClearLog)
let autoCheckServerState = UserDefaults.getBool(forKey: .autoUpdateServers)
if autoLaunchState {
autoLaunch.state = .on
}
Expand All @@ -40,6 +42,9 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
if autoClearLogState {
autoClearLog.state = .on
}
if autoCheckServerState {
autoUpdateServers.state = .on
}
}

@IBAction func SetAutoLogin(_ sender: NSButtonCell) {
Expand All @@ -54,6 +59,10 @@ final class PreferenceGeneralViewController: NSViewController, PreferencePane {
@IBAction func SetAutoClearLogs(_ sender: NSButtonCell) {
UserDefaults.setBool(forKey: .autoClearLog, value: sender.state == .on)
}

@IBAction func SetAutoUpdateServers(_ sender: NSButtonCell) {
UserDefaults.setBool(forKey: .autoUpdateServers, value: sender.state == .on)
}

@IBAction func goFeedback(_ sender: NSButton) {
guard let url = URL(string: "https://github.com/yanue/v2rayu/issues") else {
Expand Down
2 changes: 2 additions & 0 deletions V2rayU/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ extension UserDefaults {
case autoLaunch
// auto clear logs
case autoClearLog
// auto update servers
case autoUpdateServers
// pac|manual|global
case runMode
// use rules
Expand Down
1 change: 1 addition & 0 deletions V2rayU/v2ray/V2rayConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class V2rayConfig: NSObject {
inType = V2rayProtocolInbound.http
}
if self.v2ray.inbound!.protocol == V2rayProtocolInbound.socks {

self.v2ray.inbound!.port = self.socksPort
self.v2ray.inbound!.listen = self.socksHost
self.v2ray.inbound!.settingSocks.udp = self.enableUdp
Expand Down
2 changes: 2 additions & 0 deletions V2rayU/zh-Hans.lproj/PreferenceGeneral.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@

/* Class = "NSTextFieldCell"; title = "Toggle V2ray On/Off:"; ObjectID = "0rn-re-Wn3"; */
"0rn-re-Wn3.title" = "打开关闭代理:";
/* Class = "NSButtonCell"; title = "Automatically update servers from subscriptions"; ObjectID = "1FR-Yu-tqb"; */
"1FR-Yu-tqb.title" = "启动或唤醒时自动从订阅中更新";

0 comments on commit 1593ceb

Please sign in to comment.