From 6e66c63c108333ce259fed6ee5ed9eee1dc5526b Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Thu, 2 Nov 2023 16:06:11 +0800 Subject: [PATCH] misc: merge --- ClashX.xcodeproj/project.pbxproj | 9 +-- ClashX/General/Utils/JSBridge.swift | 81 ---------------------- ClashX/General/Utils/SSIDSuspendTool.swift | 1 + 3 files changed, 3 insertions(+), 88 deletions(-) delete mode 100644 ClashX/General/Utils/JSBridge.swift diff --git a/ClashX.xcodeproj/project.pbxproj b/ClashX.xcodeproj/project.pbxproj index e4c592ed8..89f0631ac 100644 --- a/ClashX.xcodeproj/project.pbxproj +++ b/ClashX.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0106179F2AF38EFA005C7877 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49FEC6682AD9369C00BAD9F5 /* Command.swift */; }; 015B976A2A4F2F4500F9FA4D /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 015B97692A4F2F4500F9FA4D /* Alamofire */; }; 015B976D2A4F2F6C00F9FA4D /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 015B976C2A4F2F6C00F9FA4D /* RxCocoa */; }; 015B976F2A4F2F6C00F9FA4D /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 015B976E2A4F2F6C00F9FA4D /* RxSwift */; }; @@ -156,7 +157,6 @@ 4905A2C82A2058D400AEDA2E /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = 4905A2C72A2058D400AEDA2E /* KeyboardShortcuts */; }; 4905A2CA2A20841B00AEDA2E /* NSView+Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4905A2C92A20841B00AEDA2E /* NSView+Layout.swift */; }; 4908087B29F8F405007A4944 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 4908087A29F8F3FF007A4944 /* libresolv.tbd */; }; - 490C8A102AC26E67007140F2 /* JSBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 490C8A0F2AC26E67007140F2 /* JSBridge.swift */; }; 4913C82321157D0200F6B87C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4913C82221157D0200F6B87C /* Notification.swift */; }; 491E6203258A424D00313AEF /* CommonUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 491E61FD258A424500313AEF /* CommonUtils.m */; }; 49228457270AADE20027A4B6 /* RemoteConfigUpdateIntervalSettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49228456270AADE20027A4B6 /* RemoteConfigUpdateIntervalSettingView.swift */; }; @@ -222,9 +222,6 @@ 49D223392A1DA5F10002FFCB /* SSIDSuspendTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D223382A1DA5F10002FFCB /* SSIDSuspendTool.swift */; }; 49D6A45229AEEC15006487EF /* StatusItemTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D6A45129AEEC15006487EF /* StatusItemTool.swift */; }; 49D6A45629AEEC55006487EF /* StatusItemViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D6A45529AEEC55006487EF /* StatusItemViewProtocol.swift */; }; - 49D767742A6195C800830333 /* ConnectionsReq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D767732A6195C800830333 /* ConnectionsReq.swift */; }; - 49D767762A6195E600830333 /* StructedLogReq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D767752A6195E600830333 /* StructedLogReq.swift */; }; - 49D84AD32A56E9760074CCDB /* ConnectionStatusIconCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D84AD22A56E9760074CCDB /* ConnectionStatusIconCellView.swift */; }; 49FEC6692AD9369C00BAD9F5 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49FEC6682AD9369C00BAD9F5 /* Command.swift */; }; 8A2BBEA727A03ACB0081EBEF /* ProxySetting.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 8A2BBEA627A03ACB0081EBEF /* ProxySetting.sdef */; }; 8ACD21BB27A04C7800BC4632 /* ProxySettingCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8ACD21BA27A04C7800BC4632 /* ProxySettingCommand.swift */; }; @@ -327,7 +324,6 @@ 4905A2C42A2058B000AEDA2E /* GlobalShortCutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalShortCutViewController.swift; sourceTree = ""; }; 4905A2C92A20841B00AEDA2E /* NSView+Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSView+Layout.swift"; sourceTree = ""; }; 4908087A29F8F3FF007A4944 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; }; - 490C8A0F2AC26E67007140F2 /* JSBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSBridge.swift; sourceTree = ""; }; 4913C82221157D0200F6B87C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = ""; }; 491E61FC258A424500313AEF /* CommonUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonUtils.h; sourceTree = ""; }; 491E61FD258A424500313AEF /* CommonUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUtils.m; sourceTree = ""; }; @@ -405,7 +401,6 @@ 49D6A45529AEEC55006487EF /* StatusItemViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemViewProtocol.swift; sourceTree = ""; }; 49D8276627E9B01700159D93 /* LoginKitWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginKitWrapper.h; sourceTree = ""; }; 49D8276727E9B01700159D93 /* LoginKitWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginKitWrapper.m; sourceTree = ""; }; - 49D84AD22A56E9760074CCDB /* ConnectionStatusIconCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionStatusIconCellView.swift; sourceTree = ""; }; 49FEC6682AD9369C00BAD9F5 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = ""; }; 8A2BBEA627A03ACB0081EBEF /* ProxySetting.sdef */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = ProxySetting.sdef; sourceTree = ""; }; 8ACD21BA27A04C7800BC4632 /* ProxySettingCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxySettingCommand.swift; sourceTree = ""; }; @@ -1028,6 +1023,7 @@ 01F335E82AD10D0B0048AF77 /* AlphaMetaDownloader.swift in Sources */, 01F335E92AD10D0B0048AF77 /* NetworkChangeNotifier.swift in Sources */, 01F335EA2AD10D0B0048AF77 /* GlobalShortCutViewController.swift in Sources */, + 0106179F2AF38EFA005C7877 /* Command.swift in Sources */, 01F335EB2AD10D0B0048AF77 /* Notification.swift in Sources */, 01F335EC2AD10D0B0048AF77 /* ClashMetaConfig.swift in Sources */, 01F335ED2AD10D0B0048AF77 /* ProxyModeChangeCommand.swift in Sources */, @@ -1107,7 +1103,6 @@ 495340B320DE68C300B0D3FF /* StatusItemView.swift in Sources */, F935B2FC23085515009E4D33 /* SystemProxyManager.swift in Sources */, 495A44D320D267D000888A0A /* LaunchAtLogin.swift in Sources */, - 490C8A102AC26E67007140F2 /* JSBridge.swift in Sources */, 4991D2322A565E6A00978143 /* Combine+Ext.swift in Sources */, 49281C802A1F01FA00F60935 /* DebugSettingViewController.swift in Sources */, 49CCDA2A2A54F9AC00FF1E13 /* ClashWindowController.swift in Sources */, diff --git a/ClashX/General/Utils/JSBridge.swift b/ClashX/General/Utils/JSBridge.swift deleted file mode 100644 index 6daf29662..000000000 --- a/ClashX/General/Utils/JSBridge.swift +++ /dev/null @@ -1,81 +0,0 @@ -// -// JSBridge.swift -// ClashX -// -// Created by yicheng on 2023/9/26. -// Copyright © 2023 west2online. All rights reserved. -// - -import Foundation -import WebKit - -class JSBridge: NSObject { - typealias ResponseCallback = (Any?) -> Void - typealias BridgeHandler = (Any?, @escaping ResponseCallback) -> Void - - private weak var webView: WKWebView? - private var handlers = [String: BridgeHandler]() - init(_ webView: WKWebView) { - self.webView = webView - super.init() - setup() - } - - deinit { - webView?.configuration.userContentController.removeAllUserScripts() - webView?.configuration.userContentController.removeScriptMessageHandler(forName: "jsBridge") - } - - private func setup() { - addScriptMessageHandler() - } - - private func addScriptMessageHandler() { - let scriptMessageHandler = ClashScriptMessageHandler(delegate: self) - webView?.configuration.userContentController.add(scriptMessageHandler, name: "jsBridge") - } - - private func sendBackMessage(data: Any?, eventID: String) { - let data = ["id": eventID, "data": data, "type": "jsBridge"] as [String: Any?] - do { - let jsonData = try JSONSerialization.data(withJSONObject: data, options: []) - let jsonString = String(data: jsonData, encoding: .utf8)! - let str = "window.postMessage(\(jsonString), window.origin);" - webView?.evaluateJavaScript(str) - } catch let err { - Logger.log(err.localizedDescription, level: .warning) - } - } - - func registerHandler(_ name: String, handler: @escaping BridgeHandler) { - handlers[name] = handler - } -} - -extension JSBridge: WKScriptMessageHandler { - func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { - if - let body = message.body as? [String: Any], - let handlerName = body["name"] as? String, - let handler = handlers[handlerName], - let eventID = body["id"] as? String { - let data = body["data"] - handler(data) { [weak self] res in - self?.sendBackMessage(data: res, eventID: eventID) - } - } - } -} - -private class ClashScriptMessageHandler: NSObject, WKScriptMessageHandler { - weak var delegate: WKScriptMessageHandler? - - public init(delegate: WKScriptMessageHandler) { - self.delegate = delegate - super.init() - } - - public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { - delegate?.userContentController(userContentController, didReceive: message) - } -} diff --git a/ClashX/General/Utils/SSIDSuspendTool.swift b/ClashX/General/Utils/SSIDSuspendTool.swift index 7e9ff48e7..0c88dba22 100644 --- a/ClashX/General/Utils/SSIDSuspendTool.swift +++ b/ClashX/General/Utils/SSIDSuspendTool.swift @@ -11,6 +11,7 @@ import CoreWLAN import Foundation import RxCocoa import RxSwift +import AppKit class SSIDSuspendTool: NSObject { static let shared = SSIDSuspendTool()