-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Debugman Integration #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // | ||
| // ConnectionsManager.swift | ||
| // | ||
| // | ||
| // Created by Matus Klasovity on 21/05/2024. | ||
| // | ||
|
|
||
| import Foundation | ||
| import MultipeerConnectivity | ||
|
|
||
| final class ConnectionsManager: NSObject, ObservableObject { | ||
|
|
||
| let session: MCSession | ||
| let browser: MCNearbyServiceBrowser | ||
|
|
||
| @Published var connectedPeers: [MCPeerID] = [] | ||
|
|
||
| override init() { | ||
| let appName = Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String | ||
| let peer = MCPeerID( | ||
| displayName: UIDevice.current.name + " - " + (appName ?? "") | ||
| ) | ||
|
|
||
| browser = MCNearbyServiceBrowser( | ||
| peer: peer, | ||
| serviceType: "Debugman" | ||
| ) | ||
| session = MCSession( | ||
| peer: peer, | ||
| securityIdentity: nil, | ||
| encryptionPreference: .none | ||
| ) | ||
| super.init() | ||
|
|
||
| session.delegate = self | ||
| } | ||
|
|
||
| func cancelConnection(to peer: MCPeerID) { | ||
| session.cancelConnectPeer(peer) | ||
| } | ||
|
|
||
| func sendToAllPeers(message: String) { | ||
| guard !session.connectedPeers.isEmpty else { return } | ||
|
|
||
| let data = Data(message.utf8) | ||
| do { | ||
| try session.send(data, toPeers: session.connectedPeers, with: .reliable) | ||
| } catch { | ||
| print("error sending data to peers: \(error)") | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| extension ConnectionsManager: MCSessionDelegate { | ||
|
|
||
| func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) { | ||
| switch state { | ||
| case .notConnected: | ||
| print("not connected to peer: \(peerID.displayName)") | ||
|
|
||
| case .connecting: | ||
| print("connecting to peer: \(peerID.displayName)") | ||
|
|
||
| case .connected: | ||
| print("connected to peer: \(peerID.displayName)") | ||
|
|
||
| @unknown default: | ||
| print("unknown state: \(state)") | ||
| } | ||
|
|
||
| DispatchQueue.main.async { [weak self] in | ||
| self?.connectedPeers = session.connectedPeers | ||
| } | ||
| } | ||
|
|
||
| func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) { | ||
| print("received data from peer: \(peerID)") | ||
| } | ||
|
|
||
| func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) { | ||
| print("received stream from peer: \(peerID)") | ||
| } | ||
|
|
||
| func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) { | ||
| print("started receiving resource from peer: \(peerID)") | ||
| } | ||
|
|
||
| func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: (any Error)?) { | ||
| print("finished receiving resource from peer: \(peerID)") | ||
| } | ||
|
|
||
| } | ||
40 changes: 40 additions & 0 deletions
40
Sources/AppDebugMode/Providers/ProxySettingsProvider.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // | ||
| // ProxySettingsProvider.swift | ||
| // | ||
| // | ||
| // Created by Matus Klasovity on 28/05/2024. | ||
| // | ||
|
|
||
| import Foundation | ||
| import GoodPersistence | ||
|
|
||
| public final class ProxySettingsProvider { | ||
|
|
||
| @UserDefaultValue("proxyIpAdress", defaultValue: "") | ||
| var proxyIpAdress: String | ||
|
|
||
| @UserDefaultValue("proxyPort", defaultValue: 8080) | ||
| var proxyPort: Int | ||
|
|
||
| public static let shared = ProxySettingsProvider() | ||
|
|
||
| public var urlSessionConfiguration: URLSessionConfiguration { | ||
| let urlSessionConfig = URLSessionConfiguration.default | ||
| urlSessionConfig.connectionProxyDictionary = [AnyHashable: Any]() | ||
| urlSessionConfig.connectionProxyDictionary?[kCFNetworkProxiesHTTPEnable as String] = 1 | ||
| urlSessionConfig.connectionProxyDictionary?[kCFNetworkProxiesHTTPProxy as String] = proxyIpAdress | ||
| urlSessionConfig.connectionProxyDictionary?[kCFNetworkProxiesHTTPPort as String] = proxyPort | ||
| urlSessionConfig.connectionProxyDictionary?["HTTPSProxy"] = proxyIpAdress | ||
| urlSessionConfig.connectionProxyDictionary?["HTTPSPort"] = proxyPort | ||
|
|
||
| return urlSessionConfig | ||
| } | ||
|
|
||
| func updateProxySettings(ipAddress: String, port: Int) { | ||
| proxyIpAdress = ipAddress | ||
| proxyPort = port | ||
|
|
||
| exit(0) | ||
| } | ||
|
|
||
| } |
83 changes: 83 additions & 0 deletions
83
Sources/AppDebugMode/Screens/ConnectionsSettingsView/ConnectedPeers/ConnectedPeersView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // | ||
| // ConnectedPeersView.swift | ||
| // | ||
| // | ||
| // Created by Matus Klasovity on 28/05/2024. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import MultipeerConnectivity | ||
|
|
||
| struct ConnectedPeersView: View { | ||
|
|
||
| @State var isBrowserPresented: Bool = false | ||
| @EnvironmentObject var connectionsManager: ConnectionsManager | ||
|
|
||
| var body: some View { | ||
| Group { | ||
| if connectionsManager.connectedPeers.isEmpty { | ||
| Text("No connected peers") | ||
| .foregroundColor(AppDebugColors.textPrimary) | ||
| } | ||
|
|
||
| ForEach(connectionsManager.connectedPeers, id: \.displayName) { connectedPeer in | ||
| Text(connectedPeer.displayName) | ||
|
|
||
| .foregroundColor(AppDebugColors.textPrimary) | ||
| } | ||
| .onDelete { offset in | ||
| for index in offset { | ||
| connectionsManager.cancelConnection(to: connectionsManager.connectedPeers[index]) | ||
| } | ||
| } | ||
|
|
||
| ButtonFilled(text: "Open browser") { | ||
| isBrowserPresented = true | ||
| } | ||
| .sheet(isPresented: $isBrowserPresented) { | ||
| BrowserRepresentableViewController( | ||
| browser: connectionsManager.browser, | ||
| session: connectionsManager.session | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // MARK: - BrowserRepresentableViewController | ||
|
|
||
| private struct BrowserRepresentableViewController: UIViewControllerRepresentable { | ||
|
|
||
| let browser: MCNearbyServiceBrowser | ||
| let session: MCSession | ||
|
|
||
| func makeUIViewController(context: Context) -> UIViewController { | ||
| let viewController = MCBrowserViewController( | ||
| browser: browser, | ||
| session: session | ||
| ) | ||
| viewController.delegate = context.coordinator | ||
|
|
||
| return viewController | ||
| } | ||
|
|
||
| func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} | ||
|
|
||
| func makeCoordinator() -> Coordinator { | ||
| Coordinator() | ||
| } | ||
|
|
||
| final class Coordinator: NSObject, MCBrowserViewControllerDelegate { | ||
|
|
||
| func browserViewControllerDidFinish(_ browserViewController: MCBrowserViewController) { | ||
| browserViewController.dismiss(animated: true) | ||
| } | ||
|
|
||
| func browserViewControllerWasCancelled(_ browserViewController: MCBrowserViewController) { | ||
| browserViewController.dismiss(animated: true) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
50 changes: 50 additions & 0 deletions
50
Sources/AppDebugMode/Screens/ConnectionsSettingsView/ConnectionsSettingsView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // | ||
| // ConnectionsSettingsView.swift | ||
| // | ||
| // | ||
| // Created by Matus Klasovity on 21/05/2024. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| struct ConnectionsSettingsView: View { | ||
|
|
||
| var body: some View { | ||
| List { | ||
| connectedPeersSection() | ||
| proxySettingsSection() | ||
| } | ||
| .navigationTitle("Connections") | ||
| .listStyle(.insetGrouped) | ||
| .listBackgroundColor(AppDebugColors.backgroundPrimary, for: .insetGrouped) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // MARK: - Components | ||
|
|
||
| private extension ConnectionsSettingsView { | ||
|
|
||
| func connectedPeersSection() -> some View { | ||
| Section { | ||
| ConnectedPeersView() | ||
| .listRowSeparatorColor(AppDebugColors.primary, for: .insetGrouped) | ||
| .listRowBackground(AppDebugColors.backgroundSecondary) | ||
| } header: { | ||
| Text("Connected peers") | ||
| .foregroundColor(AppDebugColors.textSecondary) | ||
| } | ||
| } | ||
|
|
||
| func proxySettingsSection() -> some View { | ||
| Section { | ||
| ProxySettingsView() | ||
| .listRowBackground(AppDebugColors.backgroundSecondary) | ||
| .foregroundColor(AppDebugColors.textPrimary) | ||
| } header: { | ||
| Text("Proxy settings") | ||
| .foregroundColor(AppDebugColors.textSecondary) | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.