Compare commits
No commits in common. "9f30f9f68690a2e5bfa4c9eb24db2c307a96831a" and "47d9723919e625f273593fd1e758c9c8c787d92f" have entirely different histories.
9f30f9f686
...
47d9723919
2 changed files with 16 additions and 75 deletions
54
.gitignore
vendored
54
.gitignore
vendored
|
|
@ -1,54 +0,0 @@
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/xcode,macos
|
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,macos
|
|
||||||
|
|
||||||
### macOS ###
|
|
||||||
# General
|
|
||||||
.DS_Store
|
|
||||||
.AppleDouble
|
|
||||||
.LSOverride
|
|
||||||
|
|
||||||
# Icon must end with two \r
|
|
||||||
Icon
|
|
||||||
|
|
||||||
|
|
||||||
# Thumbnails
|
|
||||||
._*
|
|
||||||
|
|
||||||
# Files that might appear in the root of a volume
|
|
||||||
.DocumentRevisions-V100
|
|
||||||
.fseventsd
|
|
||||||
.Spotlight-V100
|
|
||||||
.TemporaryItems
|
|
||||||
.Trashes
|
|
||||||
.VolumeIcon.icns
|
|
||||||
.com.apple.timemachine.donotpresent
|
|
||||||
|
|
||||||
# Directories potentially created on remote AFP share
|
|
||||||
.AppleDB
|
|
||||||
.AppleDesktop
|
|
||||||
Network Trash Folder
|
|
||||||
Temporary Items
|
|
||||||
.apdisk
|
|
||||||
|
|
||||||
### macOS Patch ###
|
|
||||||
# iCloud generated files
|
|
||||||
*.icloud
|
|
||||||
|
|
||||||
### Xcode ###
|
|
||||||
## User settings
|
|
||||||
xcuserdata/
|
|
||||||
|
|
||||||
## Xcode 8 and earlier
|
|
||||||
*.xcscmblueprint
|
|
||||||
*.xccheckout
|
|
||||||
|
|
||||||
### Xcode Patch ###
|
|
||||||
*.xcodeproj/*
|
|
||||||
!*.xcodeproj/project.pbxproj
|
|
||||||
!*.xcodeproj/xcshareddata/
|
|
||||||
!*.xcodeproj/project.xcworkspace/
|
|
||||||
!*.xcworkspace/contents.xcworkspacedata
|
|
||||||
/*.gcno
|
|
||||||
**/xcshareddata/WorkspaceSettings.xcsettings
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/xcode,macos
|
|
||||||
|
|
@ -3,18 +3,8 @@ import SwiftUI
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct BlockedCount: View {
|
struct BlockedCount: View {
|
||||||
|
|
||||||
@State private var txtRecord: String = "..."
|
@State private var txtRecord: String = "..."
|
||||||
|
|
||||||
private static let startIndex = 44
|
|
||||||
|
|
||||||
private static let formatter: NumberFormatter = {
|
|
||||||
let formatter = NumberFormatter()
|
|
||||||
formatter.numberStyle = .decimal
|
|
||||||
|
|
||||||
return formatter
|
|
||||||
}()
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text(txtRecord)
|
Text(txtRecord)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
@ -26,21 +16,26 @@ struct BlockedCount: View {
|
||||||
// This is a DNS wire format response and we make a lot of assumptions
|
// This is a DNS wire format response and we make a lot of assumptions
|
||||||
// It is not critical functionality so just let it fail if it fails
|
// It is not critical functionality so just let it fail if it fails
|
||||||
|
|
||||||
guard data.count > Self.startIndex else {
|
guard data.count > 44 else { return nil }
|
||||||
return nil
|
|
||||||
|
let startIndex = 44
|
||||||
|
let subData = data.suffix(from: startIndex)
|
||||||
|
|
||||||
|
// Find the first space character (ASCII 32)
|
||||||
|
var endIndex: Int?
|
||||||
|
for (offset, byte) in subData.enumerated() {
|
||||||
|
if byte == 32 { // Space character
|
||||||
|
endIndex = offset
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the first space character (ASCII 32).
|
guard let foundEndIndex = endIndex else { return nil }
|
||||||
guard let endIndex = data.suffix(from: Self.startIndex).firstIndex(of: 32) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let numberString = String(data: data[Self.startIndex ..< endIndex], encoding: .utf8)
|
// Extract bytes between start and space
|
||||||
else {
|
let numberData = subData.prefix(foundEndIndex)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return Self.formatter.string(for: Int(numberString))
|
return String(decoding: numberData, as: UTF8.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchTXTRecord() {
|
func fetchTXTRecord() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue