feat: add port setting in setting
This commit is contained in:
parent
30f194e36e
commit
d3e0f349ff
@ -467,11 +467,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
setUIPath(uiPath.goStringBuffer())
|
||||
}
|
||||
|
||||
Logger.log("Trying start proxy")
|
||||
let string = run(ConfigManager.builtInApiMode.goObject(), ConfigManager.allowConnectFromLan.goObject())?.toString() ?? ""
|
||||
let jsonData = string.data(using: .utf8) ?? Data()
|
||||
Logger.log("Trying start proxy, build-in mode: \(ConfigManager.builtInApiMode), allow lan: \(ConfigManager.allowConnectFromLan) custom port: \(Settings.proxyPort)")
|
||||
|
||||
var apiAddr = ""
|
||||
if Settings.apiPort > 0 {
|
||||
if Settings.apiPortAllowLan {
|
||||
apiAddr = "0.0.0.0:\(Settings.apiPort)"
|
||||
} else {
|
||||
apiAddr = "127.0.0.1:\(Settings.apiPort)"
|
||||
}
|
||||
}
|
||||
let startRes = run(ConfigManager.builtInApiMode.goObject(),
|
||||
ConfigManager.allowConnectFromLan.goObject(),
|
||||
GoUint32(Settings.proxyPort),
|
||||
apiAddr.goStringBuffer())?
|
||||
.toString() ?? ""
|
||||
let jsonData = startRes.data(using: .utf8) ?? Data()
|
||||
if let res = try? JSONDecoder().decode(StartProxyResp.self, from: jsonData) {
|
||||
let port = res.externalController.components(separatedBy: ":").last ?? "9090"
|
||||
ConfigManager.shared.allowExternalControl = !res.externalController.contains("127.0.0.1") && !res.externalController.contains("localhost")
|
||||
ConfigManager.shared.apiPort = port
|
||||
ConfigManager.shared.apiSecret = res.secret
|
||||
ConfigManager.shared.isRunning = true
|
||||
@ -480,8 +494,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
} else {
|
||||
ConfigManager.shared.isRunning = false
|
||||
proxyModeMenuItem.isEnabled = false
|
||||
Logger.log(string, level: .error)
|
||||
NSUserNotificationCenter.default.postConfigErrorNotice(msg: string)
|
||||
Logger.log(startRes, level: .error)
|
||||
NSUserNotificationCenter.default.postConfigErrorNotice(msg: startRes)
|
||||
}
|
||||
Logger.log("Start proxy done")
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Settings-->
|
||||
<scene sceneID="7zJ-aQ-tNg">
|
||||
<objects>
|
||||
<tabViewController title="Settings" showSeguePresentationStyle="single" selectedTabViewItemIndex="0" id="LAj-p8-9gd" customClass="SettingTabViewController" customModule="ClashX_Pro" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tabViewController title="Settings" showSeguePresentationStyle="single" selectedTabViewItemIndex="0" id="LAj-p8-9gd" customClass="SettingTabViewController" customModule="ClashX" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tabViewItems>
|
||||
<tabViewItem label="General" identifier="general" image="gearshape" catalog="system" id="Ltt-Vq-Hh1"/>
|
||||
</tabViewItems>
|
||||
@ -33,38 +33,38 @@
|
||||
<!--General-->
|
||||
<scene sceneID="XxM-Ti-kkw">
|
||||
<objects>
|
||||
<viewController title="General" showSeguePresentationStyle="single" id="kma-mp-ncL" customClass="GeneralSettingViewController" customModule="ClashX_Pro" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="dpe-v8-fF7">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="299"/>
|
||||
<viewController title="General" showSeguePresentationStyle="single" id="kma-mp-ncL" customClass="GeneralSettingViewController" customModule="ClashX" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" misplaced="YES" id="dpe-v8-fF7">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="427"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VYa-DX-JOe">
|
||||
<rect key="frame" x="20" y="20" width="360" height="269"/>
|
||||
<rect key="frame" x="20" y="20" width="381" height="417"/>
|
||||
<subviews>
|
||||
<box borderType="line" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="Gnh-m8-PAz">
|
||||
<rect key="frame" x="-3" y="177" width="366" height="94"/>
|
||||
<rect key="frame" x="-3" y="323" width="387" height="96"/>
|
||||
<view key="contentView" id="Lai-8r-q7z">
|
||||
<rect key="frame" x="3" y="3" width="360" height="88"/>
|
||||
<rect key="frame" x="4" y="5" width="379" height="88"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="leading" spacing="10" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j6Y-mY-tCG">
|
||||
<rect key="frame" x="20" y="10" width="211" height="68"/>
|
||||
<rect key="frame" x="20" y="10" width="339" height="68"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jsq-3u-CRd">
|
||||
<button verticalHuggingPriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="jsq-3u-CRd">
|
||||
<rect key="frame" x="-2" y="51" width="119" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Launch at login" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="dV6-4Z-2SO">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UGu-wD-xUs">
|
||||
<button verticalHuggingPriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="UGu-wD-xUs">
|
||||
<rect key="frame" x="-2" y="25" width="213" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Use iCloud to store config files" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="p7q-KN-kIv">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6V3-wn-WSa">
|
||||
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="6V3-wn-WSa">
|
||||
<rect key="frame" x="-2" y="-1" width="150" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Reduce notifications" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="jsL-HC-6ne">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
@ -88,17 +88,130 @@
|
||||
<constraint firstAttribute="bottom" secondItem="j6Y-mY-tCG" secondAttribute="bottom" constant="10" id="FDC-NY-hZH"/>
|
||||
<constraint firstItem="j6Y-mY-tCG" firstAttribute="leading" secondItem="Lai-8r-q7z" secondAttribute="leading" constant="20" symbolic="YES" id="VQc-o1-puL"/>
|
||||
<constraint firstItem="j6Y-mY-tCG" firstAttribute="top" secondItem="Lai-8r-q7z" secondAttribute="top" constant="10" id="fwo-Oq-R72"/>
|
||||
<constraint firstAttribute="trailing" secondItem="j6Y-mY-tCG" secondAttribute="trailing" constant="20" symbolic="YES" id="xqH-sk-drO"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</box>
|
||||
<box title="Port Settings (restart app to take effect)" translatesAutoresizingMaskIntoConstraints="NO" id="bcR-rG-52F">
|
||||
<rect key="frame" x="-3" y="209" width="387" height="108"/>
|
||||
<view key="contentView" id="baR-Ra-RV2">
|
||||
<rect key="frame" x="4" y="5" width="379" height="88"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" verticalHuggingPriority="1000" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ito-5t-76A">
|
||||
<rect key="frame" x="20" y="20" width="339" height="48"/>
|
||||
<subviews>
|
||||
<customView focusRingType="none" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="1Qb-v8-TZs">
|
||||
<rect key="frame" x="0.0" y="28" width="175" height="20"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="IZE-SM-zRM">
|
||||
<rect key="frame" x="-2" y="2" width="71" height="16"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Proxy Port:" id="uUA-LS-Hu8">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mBx-6u-i5v">
|
||||
<rect key="frame" x="75" y="0.0" width="100" height="20"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="p2c-Ej-Ulq">
|
||||
<numberFormatter key="formatter" formatterBehavior="default10_4" localizesFormat="NO" usesGroupingSeparator="NO" formatWidth="-1" groupingSize="0" minimumIntegerDigits="1" maximumIntegerDigits="42" id="I5q-Bi-gdc">
|
||||
<real key="minimum" value="0.0"/>
|
||||
<real key="maximum" value="65533"/>
|
||||
</numberFormatter>
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="IZE-SM-zRM" firstAttribute="centerY" secondItem="1Qb-v8-TZs" secondAttribute="centerY" id="6nb-Wb-Xb5"/>
|
||||
<constraint firstItem="IZE-SM-zRM" firstAttribute="top" secondItem="1Qb-v8-TZs" secondAttribute="top" constant="2" id="OG0-Fw-2QJ"/>
|
||||
<constraint firstAttribute="trailing" secondItem="mBx-6u-i5v" secondAttribute="trailing" id="SMN-Zb-3IV"/>
|
||||
<constraint firstAttribute="bottom" secondItem="mBx-6u-i5v" secondAttribute="bottom" id="YQd-Qp-gmB"/>
|
||||
<constraint firstItem="IZE-SM-zRM" firstAttribute="leading" secondItem="1Qb-v8-TZs" secondAttribute="leading" id="aBJ-lp-4il"/>
|
||||
<constraint firstItem="mBx-6u-i5v" firstAttribute="top" secondItem="1Qb-v8-TZs" secondAttribute="top" id="e75-4a-nq1"/>
|
||||
<constraint firstItem="mBx-6u-i5v" firstAttribute="leading" secondItem="IZE-SM-zRM" secondAttribute="trailing" constant="8" symbolic="YES" id="pvN-SY-NJX"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="mmt-xm-hJE">
|
||||
<rect key="frame" x="0.0" y="0.0" width="339" height="20"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Ldb-qz-Xfv">
|
||||
<rect key="frame" x="-2" y="2" width="57" height="16"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Api Port:" id="mbn-tK-UQa">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xJH-gA-vcL">
|
||||
<rect key="frame" x="75" y="0.0" width="100" height="20"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" priority="999" constant="100" id="T6o-oS-nw8"/>
|
||||
</constraints>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="pP3-Y0-7lW">
|
||||
<numberFormatter key="formatter" formatterBehavior="default10_4" localizesFormat="NO" usesGroupingSeparator="NO" formatWidth="-1" groupingSize="0" minimumIntegerDigits="1" maximumIntegerDigits="42" id="8El-Kk-9qk">
|
||||
<real key="minimum" value="0.0"/>
|
||||
<real key="maximum" value="65533"/>
|
||||
</numberFormatter>
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="uj5-FG-2x5">
|
||||
<rect key="frame" x="181" y="1" width="158" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Allow control from lan" bezelStyle="regularSquare" imagePosition="left" inset="2" id="E8B-e5-K0A">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="xJH-gA-vcL" firstAttribute="top" secondItem="mmt-xm-hJE" secondAttribute="top" id="5iK-Hp-vxJ"/>
|
||||
<constraint firstItem="xJH-gA-vcL" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="Ldb-qz-Xfv" secondAttribute="trailing" constant="8" symbolic="YES" id="AcY-Zu-XgF"/>
|
||||
<constraint firstItem="uj5-FG-2x5" firstAttribute="centerY" secondItem="mmt-xm-hJE" secondAttribute="centerY" id="Fdt-7c-Dbs"/>
|
||||
<constraint firstAttribute="bottom" secondItem="xJH-gA-vcL" secondAttribute="bottom" id="Hf3-1g-PWM"/>
|
||||
<constraint firstItem="uj5-FG-2x5" firstAttribute="leading" secondItem="xJH-gA-vcL" secondAttribute="trailing" constant="8" symbolic="YES" id="P65-hw-ZMT"/>
|
||||
<constraint firstItem="Ldb-qz-Xfv" firstAttribute="top" secondItem="mmt-xm-hJE" secondAttribute="top" constant="2" id="XKY-eb-6G5"/>
|
||||
<constraint firstItem="Ldb-qz-Xfv" firstAttribute="centerY" secondItem="mmt-xm-hJE" secondAttribute="centerY" id="kWK-cy-Pnt"/>
|
||||
<constraint firstAttribute="trailing" secondItem="uj5-FG-2x5" secondAttribute="trailing" id="m5e-QK-DUa"/>
|
||||
<constraint firstItem="Ldb-qz-Xfv" firstAttribute="leading" secondItem="mmt-xm-hJE" secondAttribute="leading" id="rjS-rN-Auf"/>
|
||||
</constraints>
|
||||
</customView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="xJH-gA-vcL" firstAttribute="width" secondItem="mBx-6u-i5v" secondAttribute="width" id="cOy-tC-hkA"/>
|
||||
<constraint firstItem="mBx-6u-i5v" firstAttribute="leading" secondItem="xJH-gA-vcL" secondAttribute="leading" id="crq-Fg-oyJ"/>
|
||||
</constraints>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="Ito-5t-76A" secondAttribute="trailing" constant="20" symbolic="YES" id="1z8-mZ-h84"/>
|
||||
<constraint firstItem="Ito-5t-76A" firstAttribute="top" secondItem="baR-Ra-RV2" secondAttribute="top" constant="20" symbolic="YES" id="HrA-ZU-Vve"/>
|
||||
<constraint firstItem="Ito-5t-76A" firstAttribute="leading" secondItem="baR-Ra-RV2" secondAttribute="leading" constant="20" symbolic="YES" id="NKY-E1-twt"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Ito-5t-76A" secondAttribute="bottom" constant="20" symbolic="YES" id="pjo-8o-eCg"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</box>
|
||||
<box borderType="line" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="hnq-VC-kO5">
|
||||
<rect key="frame" x="-3" y="-4" width="366" height="177"/>
|
||||
<rect key="frame" x="-3" y="-4" width="387" height="209"/>
|
||||
<view key="contentView" id="Xgo-Uz-aYp">
|
||||
<rect key="frame" x="3" y="3" width="360" height="171"/>
|
||||
<rect key="frame" x="4" y="5" width="379" height="201"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="TVZ-xJ-zK0">
|
||||
<rect key="frame" x="18" y="145" width="324" height="16"/>
|
||||
<rect key="frame" x="18" y="175" width="343" height="16"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Bypass proxy settings for these Hosts & Domains" id="NPu-V9-f3r">
|
||||
<font key="font" usesAppearanceFont="YES"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
@ -106,7 +219,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="VvP-5I-QhW">
|
||||
<rect key="frame" x="18" y="128" width="324" height="13"/>
|
||||
<rect key="frame" x="18" y="158" width="343" height="13"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Separated by commas(,)" id="sfe-wu-UXp">
|
||||
<font key="font" textStyle="footnote" name=".SFNS-Regular"/>
|
||||
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
|
||||
@ -114,18 +227,18 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vfh-gi-qYe">
|
||||
<rect key="frame" x="20" y="20" width="320" height="100"/>
|
||||
<rect key="frame" x="20" y="50" width="339" height="100"/>
|
||||
<clipView key="contentView" drawsBackground="NO" id="bzV-Hc-3eJ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="305" height="100"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="339" height="100"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textView importsGraphics="NO" richText="NO" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="JDw-FW-A2o">
|
||||
<rect key="frame" x="0.0" y="0.0" width="305" height="100"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="339" height="100"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
<size key="minSize" width="305" height="100"/>
|
||||
<size key="maxSize" width="305" height="10000000"/>
|
||||
<size key="minSize" width="339" height="100"/>
|
||||
<size key="maxSize" width="339" height="10000000"/>
|
||||
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
</textView>
|
||||
</subviews>
|
||||
@ -133,15 +246,25 @@
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="100" id="hvM-QH-dDi"/>
|
||||
</constraints>
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="h2X-QK-tQu">
|
||||
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="h2X-QK-tQu">
|
||||
<rect key="frame" x="-100" y="-100" width="225" height="15"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="dbQ-aI-3eA">
|
||||
<rect key="frame" x="305" y="0.0" width="15" height="100"/>
|
||||
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="dbQ-aI-3eA">
|
||||
<rect key="frame" x="323" y="0.0" width="16" height="100"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
</scrollView>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="F3Y-d6-RGr">
|
||||
<rect key="frame" x="297" y="13" width="69" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Reset" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="yXh-2Y-aTS">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="actionResetIgnoreList:" target="kma-mp-ncL" id="xXk-FI-d2R"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="vfh-gi-qYe" firstAttribute="top" secondItem="VvP-5I-QhW" secondAttribute="bottom" constant="8" symbolic="YES" id="07R-Kd-qOd"/>
|
||||
@ -150,25 +273,31 @@
|
||||
<constraint firstItem="TVZ-xJ-zK0" firstAttribute="top" secondItem="Xgo-Uz-aYp" secondAttribute="top" constant="10" id="6Oi-bz-JJP"/>
|
||||
<constraint firstItem="TVZ-xJ-zK0" firstAttribute="leading" secondItem="Xgo-Uz-aYp" secondAttribute="leading" constant="20" symbolic="YES" id="7BO-WX-UxM"/>
|
||||
<constraint firstAttribute="trailing" secondItem="TVZ-xJ-zK0" secondAttribute="trailing" constant="20" symbolic="YES" id="7cE-3w-m7O"/>
|
||||
<constraint firstItem="F3Y-d6-RGr" firstAttribute="top" secondItem="vfh-gi-qYe" secondAttribute="bottom" constant="10" id="B1m-Nv-J0V"/>
|
||||
<constraint firstAttribute="trailing" secondItem="VvP-5I-QhW" secondAttribute="trailing" constant="20" symbolic="YES" id="qN5-ZB-oNC"/>
|
||||
<constraint firstAttribute="trailing" secondItem="F3Y-d6-RGr" secondAttribute="trailing" constant="20" symbolic="YES" id="qgc-wk-Aom"/>
|
||||
<constraint firstAttribute="trailing" secondItem="vfh-gi-qYe" secondAttribute="trailing" constant="20" symbolic="YES" id="siv-mY-uhW"/>
|
||||
<constraint firstItem="vfh-gi-qYe" firstAttribute="leading" secondItem="Xgo-Uz-aYp" secondAttribute="leading" constant="20" symbolic="YES" id="w76-ua-GEo"/>
|
||||
<constraint firstAttribute="bottom" secondItem="vfh-gi-qYe" secondAttribute="bottom" constant="20" symbolic="YES" id="yfQ-3s-Qdr"/>
|
||||
<constraint firstAttribute="bottom" secondItem="F3Y-d6-RGr" secondAttribute="bottom" constant="20" symbolic="YES" id="yKg-vb-iw4"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</box>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="Gnh-m8-PAz" firstAttribute="width" secondItem="VYa-DX-JOe" secondAttribute="width" id="FHq-ls-GZu"/>
|
||||
<constraint firstAttribute="trailing" secondItem="bcR-rG-52F" secondAttribute="trailing" id="ajU-hb-WNv"/>
|
||||
<constraint firstItem="hnq-VC-kO5" firstAttribute="width" secondItem="VYa-DX-JOe" secondAttribute="width" id="kL7-uE-2XA"/>
|
||||
<constraint firstItem="bcR-rG-52F" firstAttribute="leading" secondItem="VYa-DX-JOe" secondAttribute="leading" id="mWO-be-OEN"/>
|
||||
</constraints>
|
||||
<visibilityPriorities>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
<integer value="1000"/>
|
||||
</visibilityPriorities>
|
||||
<customSpacing>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
<real value="3.4028234663852886e+38"/>
|
||||
</customSpacing>
|
||||
</stackView>
|
||||
</subviews>
|
||||
@ -176,19 +305,21 @@
|
||||
<constraint firstItem="VYa-DX-JOe" firstAttribute="top" secondItem="dpe-v8-fF7" secondAttribute="top" constant="10" id="EUx-BN-eD8"/>
|
||||
<constraint firstAttribute="trailing" secondItem="VYa-DX-JOe" secondAttribute="trailing" constant="20" symbolic="YES" id="o5S-vk-NgG"/>
|
||||
<constraint firstItem="VYa-DX-JOe" firstAttribute="leading" secondItem="dpe-v8-fF7" secondAttribute="leading" constant="20" symbolic="YES" id="s6F-zq-Aoy"/>
|
||||
<constraint firstAttribute="bottom" secondItem="VYa-DX-JOe" secondAttribute="bottom" constant="20" symbolic="YES" id="yn9-zb-pHs"/>
|
||||
<constraint firstAttribute="bottom" secondItem="VYa-DX-JOe" secondAttribute="bottom" priority="999" constant="20" symbolic="YES" id="yn9-zb-pHs"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="apiPortTextField" destination="xJH-gA-vcL" id="L8f-GZ-BYW"/>
|
||||
<outlet property="ignoreListTextView" destination="JDw-FW-A2o" id="fhs-QW-Ug6"/>
|
||||
<outlet property="launchAtLoginButton" destination="jsq-3u-CRd" id="RnH-Va-nCX"/>
|
||||
<outlet property="proxyPortTextField" destination="mBx-6u-i5v" id="7Af-XU-9Xn"/>
|
||||
<outlet property="reduceNotificationsButton" destination="6V3-wn-WSa" id="VtV-aI-dQi"/>
|
||||
<outlet property="useiCloudButton" destination="UGu-wD-xUs" id="VSD-og-kEv"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<customObject id="Co2-xv-pHW" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1546" y="1029.5"/>
|
||||
<point key="canvasLocation" x="1546" y="1028.5"/>
|
||||
</scene>
|
||||
<!--Application-->
|
||||
<scene sceneID="JPo-4y-FX3">
|
||||
@ -1071,7 +1202,7 @@
|
||||
<objects>
|
||||
<viewController title="External Manager" identifier="ExternalControlViewController" storyboardIdentifier="ExternalControlViewController" showSeguePresentationStyle="single" id="s6y-wL-pnr" userLabel="External Control" customClass="ExternalControlViewController" customModule="ClashX" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" id="Gao-fa-Dwr">
|
||||
<rect key="frame" x="0.0" y="0.0" width="515" height="256"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="515" height="268"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<scrollView autohidesScrollers="YES" horizontalLineScroll="30" horizontalPageScroll="10" verticalLineScroll="30" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h2z-Vu-j5M">
|
||||
@ -1241,7 +1372,7 @@
|
||||
</tableHeaderView>
|
||||
</scrollView>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Apx-gL-RAm">
|
||||
<rect key="frame" x="18" y="220" width="108" height="16"/>
|
||||
<rect key="frame" x="18" y="232" width="108" height="16"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="External Controls" id="9gE-NX-2wJ">
|
||||
<font key="font" usesAppearanceFont="YES"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
|
@ -15,6 +15,7 @@ class ConfigManager {
|
||||
static let shared = ConfigManager()
|
||||
private let disposeBag = DisposeBag()
|
||||
var apiPort = "8080"
|
||||
var allowExternalControl = false
|
||||
var apiSecret: String = ""
|
||||
var overrideApiURL: URL?
|
||||
var overrideSecret: String?
|
||||
|
@ -23,17 +23,28 @@ enum Settings {
|
||||
@UserDefault("configAutoUpdateInterval", defaultValue: 48*60*60)
|
||||
static var configAutoUpdateInterval: TimeInterval
|
||||
|
||||
@UserDefault("proxyIgnoreList", defaultValue: ["192.168.0.0/16",
|
||||
"10.0.0.0/8",
|
||||
"172.16.0.0/12",
|
||||
"127.0.0.1",
|
||||
"localhost",
|
||||
"*.local",
|
||||
"timestamp.apple.com",
|
||||
"sequoia.apple.com",
|
||||
"seed-sequoia.siri.apple.com"])
|
||||
static let proxyIgnoreListDefaultValue = ["192.168.0.0/16",
|
||||
"10.0.0.0/8",
|
||||
"172.16.0.0/12",
|
||||
"127.0.0.1",
|
||||
"localhost",
|
||||
"*.local",
|
||||
"timestamp.apple.com",
|
||||
"sequoia.apple.com",
|
||||
"seed-sequoia.siri.apple.com"]
|
||||
@UserDefault("proxyIgnoreList", defaultValue: proxyIgnoreListDefaultValue)
|
||||
static var proxyIgnoreList: [String]
|
||||
|
||||
@UserDefault("disableMenubarNotice", defaultValue: false)
|
||||
static var disableMenubarNotice: Bool
|
||||
|
||||
@UserDefault("proxyPort", defaultValue: 0)
|
||||
static var proxyPort: Int
|
||||
|
||||
@UserDefault("apiPort", defaultValue: 0)
|
||||
static var apiPort: Int
|
||||
|
||||
@UserDefault("apiPortAllowLan", defaultValue: false)
|
||||
static var apiPortAllowLan: Bool
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ class GeneralSettingViewController: NSViewController {
|
||||
@IBOutlet weak var reduceNotificationsButton: NSButton!
|
||||
@IBOutlet weak var useiCloudButton: NSButton!
|
||||
|
||||
@IBOutlet weak var proxyPortTextField: NSTextField!
|
||||
@IBOutlet weak var apiPortTextField: NSTextField!
|
||||
|
||||
var disposeBag = DisposeBag()
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@ -24,7 +27,6 @@ class GeneralSettingViewController: NSViewController {
|
||||
.string.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
|
||||
.map { $0.components(separatedBy: ",").filter {!$0.isEmpty} }
|
||||
.subscribe { arr in
|
||||
print(arr)
|
||||
Settings.proxyIgnoreList = arr
|
||||
}.disposed(by: disposeBag)
|
||||
|
||||
@ -48,6 +50,40 @@ class GeneralSettingViewController: NSViewController {
|
||||
reduceNotificationsButton.rx.state.map {$0 == .on }.subscribe {
|
||||
Settings.disableNoti = $0
|
||||
}.disposed(by: disposeBag)
|
||||
|
||||
if Settings.proxyPort > 0 {
|
||||
proxyPortTextField.stringValue = "\(Settings.proxyPort)"
|
||||
} else {
|
||||
proxyPortTextField.stringValue = "\(ConfigManager.shared.currentConfig?.mixedPort ?? 0)"
|
||||
}
|
||||
if Settings.apiPort > 0 {
|
||||
apiPortTextField.stringValue = "\(Settings.apiPort)"
|
||||
} else {
|
||||
apiPortTextField.stringValue = ConfigManager.shared.apiPort
|
||||
}
|
||||
|
||||
proxyPortTextField.rx.text
|
||||
.compactMap {$0}
|
||||
.compactMap {Int($0)}
|
||||
.bind {
|
||||
Settings.proxyPort = $0
|
||||
}.disposed(by: disposeBag)
|
||||
|
||||
apiPortTextField.rx.text
|
||||
.compactMap {$0}
|
||||
.compactMap {Int($0)}
|
||||
.bind {
|
||||
Settings.apiPort = $0
|
||||
}.disposed(by: disposeBag)
|
||||
}
|
||||
|
||||
override func viewDidAppear() {
|
||||
super.viewDidAppear()
|
||||
view.window?.makeFirstResponder(nil)
|
||||
}
|
||||
|
||||
@IBAction func actionResetIgnoreList(_ sender: Any) {
|
||||
ignoreListTextView.string = Settings.proxyIgnoreListDefaultValue.joined(separator: ",")
|
||||
Settings.proxyIgnoreList = Settings.proxyIgnoreListDefaultValue
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
rm -f *.h *.a
|
||||
python3 build_clash.py
|
||||
python3 build_clash_universal.py
|
||||
|
@ -1,55 +0,0 @@
|
||||
import subprocess
|
||||
import datetime
|
||||
import plistlib
|
||||
import os
|
||||
|
||||
def get_version():
|
||||
with open('./go.mod') as file:
|
||||
for line in file.readlines():
|
||||
if "clash" in line and "ClashX" not in line:
|
||||
return line.split("-")[-1].strip()[:6]
|
||||
return "unknown"
|
||||
|
||||
def get_full_version():
|
||||
with open('./go.mod') as file:
|
||||
for line in file.readlines():
|
||||
if "clash" in line and "ClashX" not in line:
|
||||
return line.split(" ")[-1].strip()
|
||||
|
||||
def build_clash(version):
|
||||
build_time = datetime.datetime.now().strftime("%Y-%m-%d-%H%M")
|
||||
command = f"""CGO_CFLAGS=-mmacosx-version-min=10.12 \
|
||||
CGO_LDFLAGS=-mmacosx-version-min=10.12 \
|
||||
go build -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version={version}" \
|
||||
-X "github.com/Dreamacro/clash/constant.BuildTime={build_time}"' \
|
||||
-buildmode=c-archive -o goClash.a """
|
||||
subprocess.check_output(command, shell=True)
|
||||
|
||||
|
||||
def write_to_info(version):
|
||||
path = "../info.plist"
|
||||
|
||||
with open(path, 'rb') as f:
|
||||
contents = plistlib.load(f)
|
||||
|
||||
if not contents:
|
||||
exit(-1)
|
||||
|
||||
contents["coreVersion"] = version
|
||||
with open(path, 'wb') as f:
|
||||
plistlib.dump(contents, f, sort_keys=False)
|
||||
|
||||
|
||||
def run():
|
||||
version = get_version()
|
||||
print("current clash version:", version)
|
||||
build_clash(version)
|
||||
print("build static library complete!")
|
||||
if os.environ.get("CI", False) or os.environ.get("GITHUB_ACTIONS", False):
|
||||
print("writing info.plist")
|
||||
write_to_info(version)
|
||||
print("done")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
@ -77,7 +77,7 @@ func readConfig(path string) ([]byte, error) {
|
||||
return data, err
|
||||
}
|
||||
|
||||
func parseDefaultConfigThenStart(checkPort, allowLan bool) (*config.Config, error) {
|
||||
func parseDefaultConfigThenStart(checkPort, allowLan bool, proxyPort uint32, externalController string) (*config.Config, error) {
|
||||
buf, err := readConfig(constant.Path.Config())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -88,29 +88,37 @@ func parseDefaultConfigThenStart(checkPort, allowLan bool) (*config.Config, erro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if rawCfg.MixedPort == 0 {
|
||||
if rawCfg.Port > 0 {
|
||||
rawCfg.MixedPort = rawCfg.Port
|
||||
rawCfg.Port = 0
|
||||
} else if rawCfg.SocksPort > 0 {
|
||||
rawCfg.MixedPort = rawCfg.SocksPort
|
||||
rawCfg.SocksPort = 0
|
||||
} else {
|
||||
rawCfg.MixedPort = 7890
|
||||
}
|
||||
if proxyPort > 0 {
|
||||
rawCfg.MixedPort = int(proxyPort)
|
||||
rawCfg.SocksPort = 0
|
||||
rawCfg.Port = 0
|
||||
} else {
|
||||
if rawCfg.MixedPort == 0 {
|
||||
if rawCfg.Port > 0 {
|
||||
rawCfg.MixedPort = rawCfg.Port
|
||||
rawCfg.Port = 0
|
||||
} else if rawCfg.SocksPort > 0 {
|
||||
rawCfg.MixedPort = rawCfg.SocksPort
|
||||
rawCfg.SocksPort = 0
|
||||
} else {
|
||||
rawCfg.MixedPort = 7890
|
||||
}
|
||||
|
||||
if rawCfg.SocksPort == rawCfg.MixedPort {
|
||||
rawCfg.SocksPort = 0
|
||||
}
|
||||
if rawCfg.SocksPort == rawCfg.MixedPort {
|
||||
rawCfg.SocksPort = 0
|
||||
}
|
||||
|
||||
if rawCfg.Port == rawCfg.MixedPort {
|
||||
rawCfg.Port = 0
|
||||
if rawCfg.Port == rawCfg.MixedPort {
|
||||
rawCfg.Port = 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rawCfg.ExternalUI = ""
|
||||
rawCfg.Profile.StoreSelected = false
|
||||
if len(externalController) > 0 {
|
||||
rawCfg.ExternalController = externalController
|
||||
}
|
||||
if checkPort {
|
||||
if !isAddrValid(rawCfg.ExternalController) {
|
||||
port, err := freeport.GetFreePort()
|
||||
@ -154,8 +162,8 @@ func verifyClashConfig(content *C.char) *C.char {
|
||||
}
|
||||
|
||||
//export run
|
||||
func run(checkConfig, allowLan bool) *C.char {
|
||||
cfg, err := parseDefaultConfigThenStart(checkConfig, allowLan)
|
||||
func run(checkConfig, allowLan bool, portOverride uint32, externalController *C.char) *C.char {
|
||||
cfg, err := parseDefaultConfigThenStart(checkConfig, allowLan, portOverride, C.GoString(externalController))
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
|
@ -193,9 +193,6 @@
|
||||
/* Class = "NSMenuItem"; title = "Set update interval"; ObjectID = "h1H-7k-9HS"; */
|
||||
"h1H-7k-9HS.title" = "设置更新间隔";
|
||||
|
||||
/* Class = "NSBox"; title = "Box"; ObjectID = "Gnh-m8-PAz"; */
|
||||
"Gnh-m8-PAz.title" = "";
|
||||
|
||||
/* Class = "NSTabViewController"; title = "Settings"; ObjectID = "LAj-p8-9gd"; */
|
||||
"LAj-p8-9gd.title" = "ClashX 设置";
|
||||
|
||||
@ -209,7 +206,7 @@
|
||||
"dV6-4Z-2SO.title" = "开机启动";
|
||||
|
||||
/* Class = "NSViewController"; title = "General"; ObjectID = "kma-mp-ncL"; */
|
||||
"kma-mp-ncL.title" = "";
|
||||
"kma-mp-ncL.title" = "通用";
|
||||
|
||||
/* Class = "NSMenuItem"; title = "Settings"; ObjectID = "krh-QF-pqZ"; */
|
||||
"krh-QF-pqZ.title" = "更多设置";
|
||||
@ -222,3 +219,21 @@
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "Separated by commas(,)"; ObjectID = "sfe-wu-UXp"; */
|
||||
"sfe-wu-UXp.title" = "使用英文逗号(,)分隔";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Allow control from lan"; ObjectID = "E8B-e5-K0A"; */
|
||||
"E8B-e5-K0A.title" = "允许局域网控制(不推荐)";
|
||||
|
||||
/* Class = "NSBox"; title = "Port Settings (restart app to take effect)"; ObjectID = "bcR-rG-52F"; */
|
||||
"bcR-rG-52F.title" = "端口设置(重启应用生效)";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "Api Port:"; ObjectID = "mbn-tK-UQa"; */
|
||||
"mbn-tK-UQa.title" = "Api 端口";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "Proxy Port:"; ObjectID = "uUA-LS-Hu8"; */
|
||||
"uUA-LS-Hu8.title" = "代理端口";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Reset"; ObjectID = "yXh-2Y-aTS"; */
|
||||
"yXh-2Y-aTS.title" = "重置";
|
||||
|
||||
/* Class = "NSBox"; title = "Box"; ObjectID = "Gnh-m8-PAz"; */
|
||||
"Gnh-m8-PAz.title" = "Box";
|
||||
|
Loading…
Reference in New Issue
Block a user