-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync bookmarks between macOS and iOS #63: Add log. Refactoring.
- Loading branch information
Showing
24 changed files
with
414 additions
and
207 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
ReaderTranslator.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains 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 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 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 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 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,30 @@ | ||
// | ||
// Bundle.swift | ||
// ReaderTranslator | ||
// | ||
// Created by Viktor Kushnerov on 22/12/19. | ||
// Copyright © 2019 Viktor Kushnerov. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
final class Debug { | ||
static var appName: String { | ||
guard let dictionary = Bundle.main.infoDictionary else { | ||
return "" | ||
} | ||
if let version: String = dictionary["CFBundleName"] as? String { | ||
return version | ||
} else { | ||
return "" | ||
} | ||
} | ||
|
||
static func log(_ prefix: String, _ text: String, _ text2: String, _ text3: String = "", _ text4: String = "") { | ||
let format = DateFormatter() | ||
format.dateFormat = "HH:mm:ss.SSSS" | ||
let date = format.string(from: Date()) | ||
|
||
print("\(date) \(prefix)[\(Debug.appName)][\(text)][\(text2)][\(text3)]: \(text4)") | ||
} | ||
} |
This file contains 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,62 @@ | ||
// | ||
// Browser.swift | ||
// ReaderTranslatorPlayer | ||
// | ||
// Created by Viktor Kushnerov on 22/12/19. | ||
// Copyright © 2019 Viktor Kushnerov. All rights reserved. | ||
// | ||
import Network | ||
import SwiftUI | ||
|
||
class NetBrowser: ObservableObject { | ||
@Published var servers = [NWBrowser.Result]() | ||
@Published var status = ConnectionClientStatus.none | ||
@ObservedObject var store = Store.shared | ||
|
||
func hostInfo(_ server: NWBrowser.Result) -> String { | ||
if case let NWEndpoint.service(name: name, type: _, domain: _, interface: _) = server.endpoint { | ||
return name | ||
} else { | ||
return "empty" | ||
} | ||
} | ||
|
||
func connectToServer(server: NWBrowser.Result, passcode: String) { | ||
Debug.log("P2P", "\(Self.self)", "\(#function)") | ||
sharedConnection = PeerConnection( | ||
endpoint: server.endpoint, | ||
interface: server.interfaces.first, | ||
passcode: passcode | ||
) | ||
sharedConnection?.delegate = self | ||
sharedConnection?.startConnection() | ||
} | ||
} | ||
|
||
extension NetBrowser: PeerBrowserDelegate { | ||
func refreshResults(results: Set<NWBrowser.Result>) { | ||
Debug.log("P2P", "\(Self.self)", "PeerBrowserDelegate", "\(#function)") | ||
status = .none | ||
servers = results.map { $0 } | ||
} | ||
} | ||
|
||
extension NetBrowser: PeerConnectionDelegate { | ||
func connectionReady() { | ||
Debug.log("P2P", "\(Self.self)", "PeerBrowserDelegate", "\(#function)") | ||
status = .connected | ||
} | ||
|
||
func connectionFailed() { | ||
Debug.log("P2P", "\(Self.self)", "PeerBrowserDelegate", "\(#function)") | ||
status = .failed(error: "failed") | ||
} | ||
|
||
func receivedMessage(content: Data?, message: NWProtocolFramer.Message) { | ||
Debug.log("P2P", "\(Self.self)", "PeerBrowserDelegate", "\(#function)") | ||
// switch message.readerTranslatorMessageType { | ||
// case .invalid: print("Received invalid message") | ||
// case .send: store.bookmarks.merge(data: content) | ||
// } | ||
} | ||
} |
File renamed without changes.
This file contains 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 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 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 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
Oops, something went wrong.