Skip to content

Commit

Permalink
misc: add ipv6 enable button
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Sep 5, 2023
1 parent 38341d7 commit 3d210e3
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 29 deletions.
1 change: 1 addition & 0 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
let startRes = run(Settings.builtInApiMode.goObject(),
ConfigManager.allowConnectFromLan.goObject(),
Settings.enableIPV6.goObject(),
GoUint32(Settings.proxyPort),
apiAddr.goStringBuffer())?
.toString() ?? ""
Expand Down
38 changes: 24 additions & 14 deletions ClashX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<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="432" height="610"/>
<rect key="frame" x="20" y="20" width="432" height="634"/>
<subviews>
<box borderType="line" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="Gnh-m8-PAz">
<rect key="frame" x="-3" y="516" width="438" height="96"/>
<rect key="frame" x="-3" y="540" width="438" height="96"/>
<view key="contentView" id="Lai-8r-q7z">
<rect key="frame" x="4" y="5" width="430" height="88"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -96,15 +96,22 @@
</constraints>
</view>
</box>
<box title="Port Settings (restart app to take effect)" translatesAutoresizingMaskIntoConstraints="NO" id="bcR-rG-52F">
<rect key="frame" x="-3" y="374" width="438" height="136"/>
<box title="Clash Settings (restart app to take effect)" translatesAutoresizingMaskIntoConstraints="NO" id="bcR-rG-52F">
<rect key="frame" x="-3" y="374" width="438" height="160"/>
<view key="contentView" id="baR-Ra-RV2">
<rect key="frame" x="4" y="5" width="430" height="116"/>
<rect key="frame" x="4" y="5" width="430" height="140"/>
<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="390" height="76"/>
<rect key="frame" x="20" y="20" width="390" height="100"/>
<subviews>
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="buf-aL-Tkl">
<rect key="frame" x="-2" y="83" width="98" height="18"/>
<buttonCell key="cell" type="check" title="Enable IPv6" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="KRm-2U-T4s">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<customView focusRingType="none" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="1Qb-v8-TZs">
<rect key="frame" x="0.0" y="56" width="175" height="20"/>
<subviews>
Expand Down Expand Up @@ -237,11 +244,13 @@
<integer value="1000"/>
<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"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
Expand Down Expand Up @@ -278,15 +287,15 @@
<scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="plI-7S-yCW">
<rect key="frame" x="20" y="10" width="390" height="20"/>
<clipView key="contentView" drawsBackground="NO" id="HHy-NP-pH6">
<rect key="frame" x="0.0" y="0.0" width="375" height="20"/>
<rect key="frame" x="0.0" y="0.0" width="390" height="20"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" richText="NO" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="sjz-uN-XpL">
<rect key="frame" x="0.0" y="0.0" width="375" height="20"/>
<rect key="frame" x="0.0" y="0.0" width="390" height="20"/>
<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="375" height="20"/>
<size key="minSize" width="390" height="20"/>
<size key="maxSize" width="450" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
</textView>
Expand All @@ -300,7 +309,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="OaY-Eu-ksx">
<rect key="frame" x="375" y="0.0" width="15" height="20"/>
<rect key="frame" x="374" y="0.0" width="16" height="20"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -407,15 +416,15 @@
<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="50" width="390" height="100"/>
<clipView key="contentView" drawsBackground="NO" id="bzV-Hc-3eJ">
<rect key="frame" x="0.0" y="0.0" width="375" height="100"/>
<rect key="frame" x="0.0" y="0.0" width="390" 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="375" height="100"/>
<rect key="frame" x="0.0" y="0.0" width="390" 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="375" height="100"/>
<size key="minSize" width="390" height="100"/>
<size key="maxSize" width="450" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
</textView>
Expand All @@ -429,7 +438,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="dbQ-aI-3eA">
<rect key="frame" x="375" y="0.0" width="15" height="100"/>
<rect key="frame" x="374" y="0.0" width="16" height="100"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -498,6 +507,7 @@
<outlet property="apiSecretOverrideButton" destination="N0V-ac-Acm" id="n9x-y4-XsR"/>
<outlet property="apiSecretTextField" destination="CE4-Aa-FiI" id="po3-LI-T3l"/>
<outlet property="ignoreListTextView" destination="JDw-FW-A2o" id="fhs-QW-Ug6"/>
<outlet property="ipv6Button" destination="buf-aL-Tkl" id="s3h-2l-ik5"/>
<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"/>
Expand Down
4 changes: 2 additions & 2 deletions ClashX/General/Managers/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ enum Settings {
@UserDefault("disableSSIDList", defaultValue: [])
static var disableSSIDList: [String]

@UserDefault("useSwiftUiMenuBar", defaultValue: true)
static var useSwiftUiMenuBar: Bool
@UserDefault("enableIPV6", defaultValue: false)
static var enableIPV6: Bool

static let apiSecretKey = "api-secret"

Expand Down
3 changes: 3 additions & 0 deletions ClashX/Support Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
/* No comment provided by engineer. */
"Rule Mode" = "Rule Mode";

/* No comment provided by engineer. */
"Script" = "Script";

/* No comment provided by engineer. */
"Should be a least 1 hour" = "Should be a least 1 hour";

Expand Down
3 changes: 3 additions & 0 deletions ClashX/Support Files/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
/* No comment provided by engineer. */
"Rule Mode" = "规则判断";

/* No comment provided by engineer. */
"Script" = "脚本";

/* No comment provided by engineer. */
"Should be a least 1 hour" = "至少需要1小时间隔";

Expand Down
3 changes: 3 additions & 0 deletions ClashX/Support Files/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
/* No comment provided by engineer. */
"Rule Mode" = "規則模式";

/* No comment provided by engineer. */
"Script" = "腳本";

/* No comment provided by engineer. */
"Should be a least 1 hour" = "應該至少 1 小時";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class GeneralSettingViewController: NSViewController {

@IBOutlet var apiSecretOverrideButton: NSButton!

@IBOutlet var ipv6Button: NSButton!
@IBOutlet var speedTestUrlField: NSTextField!

var disposeBag = DisposeBag()
Expand Down Expand Up @@ -70,6 +71,11 @@ class GeneralSettingViewController: NSViewController {
Settings.disableNoti = $0
}.disposed(by: disposeBag)

ipv6Button.state = Settings.enableIPV6 ? .on : .off
ipv6Button.rx.state.map { $0 == .on }.subscribe {
Settings.enableIPV6 = $0
}.disposed(by: disposeBag)

if Settings.proxyPort > 0 {
proxyPortTextField.stringValue = "\(Settings.proxyPort)"
} else {
Expand Down
10 changes: 7 additions & 3 deletions ClashX/goClash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
)

var secretOverride string = ""
var enableIPV6 bool = false

func isAddrValid(addr string) bool {
if addr != "" {
Expand Down Expand Up @@ -99,7 +100,7 @@ func getRawCfg() (*config.RawConfig, error) {
return config.UnmarshalRawConfig(buf)
}

func parseDefaultConfigThenStart(checkPort, allowLan bool, proxyPort uint32, externalController string) (*config.Config, error) {
func parseDefaultConfigThenStart(checkPort, allowLan, ipv6 bool, proxyPort uint32, externalController string) (*config.Config, error) {
rawCfg, err := getRawCfg()
if err != nil {
return nil, err
Expand Down Expand Up @@ -139,6 +140,8 @@ func parseDefaultConfigThenStart(checkPort, allowLan bool, proxyPort uint32, ext
}
rawCfg.ExternalUI = ""
rawCfg.Profile.StoreSelected = false
enableIPV6 = ipv6
rawCfg.IPv6 = ipv6
if len(externalController) > 0 {
rawCfg.ExternalController = externalController
}
Expand Down Expand Up @@ -232,8 +235,8 @@ func clash_setSecret(secret *C.char) {
}

//export run
func run(checkConfig, allowLan bool, portOverride uint32, externalController *C.char) *C.char {
cfg, err := parseDefaultConfigThenStart(checkConfig, allowLan, portOverride, C.GoString(externalController))
func run(checkConfig, allowLan, ipv6 bool, portOverride uint32, externalController *C.char) *C.char {
cfg, err := parseDefaultConfigThenStart(checkConfig, allowLan, ipv6, portOverride, C.GoString(externalController))
if err != nil {
return C.CString(err.Error())
}
Expand Down Expand Up @@ -262,6 +265,7 @@ func clashUpdateConfig(path *C.char) *C.char {
if err != nil {
return C.CString(err.Error())
}
cfg.General.IPv6 = enableIPV6
executor.ApplyConfig(cfg, false)
return C.CString("success")
}
Expand Down
10 changes: 5 additions & 5 deletions ClashX/zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@
/* 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 = "NSBox"; title = "Clash Settings (restart app to take effect)"; ObjectID = "bcR-rG-52F"; */
"bcR-rG-52F.title" = "Clash设置(重启应用生效)";

/* Class = "NSTextFieldCell"; title = "Api Port:"; ObjectID = "mbn-tK-UQa"; */
"mbn-tK-UQa.title" = "Api 端口";
Expand All @@ -235,9 +235,6 @@
/* Class = "NSBox"; title = "Debug Setting"; ObjectID = "NLT-FZ-48V"; */
"NLT-FZ-48V.title" = "调试设置";

/* Class = "NSButtonCell"; title = "Use SwiftUI to render status bar icon. (MacOS 13+)"; ObjectID = "eY9-1i-i7P"; */
"eY9-1i-i7P.title" = "使用 SwiftUI 进行菜单栏图标渲染 (MacOS 13+)";

/* Class = "NSViewController"; title = "Debug"; ObjectID = "kdV-Em-qBi"; */
"kdV-Em-qBi.title" = "调试";

Expand Down Expand Up @@ -312,3 +309,6 @@

/* Class = "NSMenuItem"; title = "Update external resources"; ObjectID = "9g1-lW-mA8"; */
"9g1-lW-mA8.title" = "更新外部资源";

/* Class = "NSButtonCell"; title = "Enable IPv6"; ObjectID = "KRm-2U-T4s"; */
"KRm-2U-T4s.title" = "启用IPv6";
10 changes: 5 additions & 5 deletions ClashX/zh-Hant.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,15 @@
/* Class = "NSButtonCell"; title = "Open Log Folder"; ObjectID = "afj-4G-usr"; */
"afj-4G-usr.title" = "打開日誌文件夾";

/* Class = "NSBox"; title = "Port Settings (restart app to take effect)"; ObjectID = "bcR-rG-52F"; */
"bcR-rG-52F.title" = "端口設定";
/* Class = "NSBox"; title = "Clash Settings (restart app to take effect)"; ObjectID = "bcR-rG-52F"; */
"bcR-rG-52F.title" = "Clash設定";

/* Class = "NSTextFieldCell"; title = "Log"; ObjectID = "c01-0L-1SQ"; */
"c01-0L-1SQ.title" = "日誌";

/* Class = "NSButtonCell"; title = "Launch at login"; ObjectID = "dV6-4Z-2SO"; */
"dV6-4Z-2SO.title" = "登錄時啟動";

/* Class = "NSButtonCell"; title = "Use SwiftUI to render status bar icon. (MacOS 13+)"; ObjectID = "eY9-1i-i7P"; */
"eY9-1i-i7P.title" = "使用 SwiftUI 渲染狀態欄圖標";

/* Class = "NSMenuItem"; title = "Set update interval"; ObjectID = "h1H-7k-9HS"; */
"h1H-7k-9HS.title" = "設定更新間隔";

Expand Down Expand Up @@ -312,3 +309,6 @@

/* Class = "NSMenuItem"; title = "Update external resources"; ObjectID = "9g1-lW-mA8"; */
"9g1-lW-mA8.title" = "更新外部資源";

/* Class = "NSButtonCell"; title = "Enable IPv6"; ObjectID = "KRm-2U-T4s"; */
"KRm-2U-T4s.title" = "啟用IPv6";

0 comments on commit 3d210e3

Please sign in to comment.