Skip to content

Commit

Permalink
feat: show notice when proxy setting changed by other process
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Feb 15, 2020
1 parent 728788c commit c36b597
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
with:
files: ClashX.dmg
# draft: true
prerelease: true
# prerelease: true

- name: update gitpage
if: startsWith(github.ref, 'refs/tags/')
Expand Down
11 changes: 11 additions & 0 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self, selector: #selector(resetProxySettingOnWakeupFromSleep),
name: NSWorkspace.didWakeNotification, object: nil
)

ConfigManager.shared
.isProxySetByOtherVariable
.asObservable()
.filter { _ in ConfigManager.shared.proxyPortAutoSet }
.distinctUntilChanged()
.filter { $0 }.bind { _ in
let rawProxy = NetworkChangeNotifier.getRawProxySetting()
Logger.log("proxy changed to no clashX setting: \(rawProxy)", level: .warning)
NSUserNotificationCenter.default.postProxyChangeByOtherAppNotice()
}.disposed(by: disposeBag)
}

func updateProxyList() {
Expand Down
5 changes: 5 additions & 0 deletions ClashX/Extensions/NSUserNotificationCenter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ extension NSUserNotificationCenter {
post(title: NSLocalizedString("Benchmark", comment: ""),
info: NSLocalizedString("Benchmark Finished!", comment: ""))
}

func postProxyChangeByOtherAppNotice() {
post(title: NSLocalizedString("System Proxy Changed", comment: ""),
info: NSLocalizedString("Proxy settings are changed by another process. ClashX is no longer the default system proxy.", comment: ""))
}
}

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

/* No comment provided by engineer. */
"Proxy settings are changed by another process. ClashX is no longer the default system proxy." = "Proxy settings are changed by another process. ClashX is no longer the default system proxy.";

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

Expand Down Expand Up @@ -110,6 +113,9 @@
/* No comment provided by engineer. */
"Success!" = "Success!";

/* No comment provided by engineer. */
"System Proxy Changed" = "System Proxy Changed";

/* No comment provided by engineer. */
"Tap to reload config" = "Tap to reload config";

Expand Down
6 changes: 6 additions & 0 deletions ClashX/Support Files/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
/* No comment provided by engineer. */
"Proxy Mode" = "出站模式";

/* No comment provided by engineer. */
"Proxy settings are changed by another process. ClashX is no longer the default system proxy." = "系统代理设置已被另一个进程修改,ClashX不再是系统默认代理";

/* No comment provided by engineer. */
"Quit" = "退出";

Expand Down Expand Up @@ -110,6 +113,9 @@
/* No comment provided by engineer. */
"Success!" = "成功!";

/* No comment provided by engineer. */
"System Proxy Changed" = "系统代理设置已修改";

/* No comment provided by engineer. */
"Tap to reload config" = "点击重载配置文件";

Expand Down

0 comments on commit c36b597

Please sign in to comment.