mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
chore(apple): Resolve all Swift compile warnings (#7602)
Fixes various warnings Xcode that have cropped up in the 1.4.0 refactor and recent feature additions.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
import NetworkExtension
|
||||
|
||||
/// Make NEVPNStatus convertible to a string
|
||||
extension NEVPNStatus: CustomStringConvertible {
|
||||
extension NEVPNStatus: @retroactive CustomStringConvertible {
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .disconnected: return "Disconnected"
|
||||
|
||||
@@ -19,7 +19,6 @@ public enum KeychainError: Error {
|
||||
|
||||
public actor Keychain {
|
||||
public static let shared = Keychain()
|
||||
private let workQueue = DispatchQueue(label: "FirezoneKeychainWorkQueue")
|
||||
|
||||
public typealias PersistentRef = Data
|
||||
|
||||
@@ -43,19 +42,17 @@ public actor Keychain {
|
||||
public init() {}
|
||||
|
||||
public func add(query: [CFString: Any]) async throws {
|
||||
return try await withCheckedThrowingContinuation { [weak self] continuation in
|
||||
self?.workQueue.async {
|
||||
var ref: CFTypeRef?
|
||||
let ret = SecStatus(SecItemAdd(query as CFDictionary, &ref))
|
||||
guard ret.isSuccess else {
|
||||
continuation.resume(
|
||||
throwing: KeychainError.appleSecError(call: "SecItemAdd", status: ret))
|
||||
return
|
||||
}
|
||||
|
||||
continuation.resume()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
var ref: CFTypeRef?
|
||||
let ret = SecStatus(SecItemAdd(query as CFDictionary, &ref))
|
||||
guard ret.isSuccess else {
|
||||
continuation.resume(
|
||||
throwing: KeychainError.appleSecError(call: "SecItemAdd", status: ret))
|
||||
return
|
||||
}
|
||||
|
||||
continuation.resume()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,75 +60,66 @@ public actor Keychain {
|
||||
query: [CFString: Any],
|
||||
attributesToUpdate: [CFString: Any]
|
||||
) async throws {
|
||||
return try await withCheckedThrowingContinuation { [weak self] continuation in
|
||||
self?.workQueue.async {
|
||||
let ret = SecStatus(
|
||||
SecItemUpdate(query as CFDictionary, attributesToUpdate as CFDictionary))
|
||||
guard ret.isSuccess else {
|
||||
continuation.resume(
|
||||
throwing: KeychainError.appleSecError(call: "SecItemUpdate", status: ret))
|
||||
return
|
||||
}
|
||||
continuation.resume()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
let ret = SecStatus(
|
||||
SecItemUpdate(query as CFDictionary, attributesToUpdate as CFDictionary))
|
||||
guard ret.isSuccess else {
|
||||
continuation.resume(
|
||||
throwing: KeychainError.appleSecError(call: "SecItemUpdate", status: ret))
|
||||
return
|
||||
}
|
||||
continuation.resume()
|
||||
}
|
||||
}
|
||||
|
||||
public func load(persistentRef: PersistentRef) async -> Data? {
|
||||
return await withCheckedContinuation { [weak self] continuation in
|
||||
self?.workQueue.async {
|
||||
let query =
|
||||
[
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecValuePersistentRef: persistentRef,
|
||||
kSecReturnData: true,
|
||||
] as [CFString: Any]
|
||||
var result: CFTypeRef?
|
||||
let ret = SecStatus(SecItemCopyMatching(query as CFDictionary, &result))
|
||||
if ret.isSuccess,
|
||||
let resultData = result as? Data
|
||||
{
|
||||
continuation.resume(returning: resultData)
|
||||
} else {
|
||||
continuation.resume(returning: nil)
|
||||
}
|
||||
return await withCheckedContinuation { continuation in
|
||||
let query =
|
||||
[
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecValuePersistentRef: persistentRef,
|
||||
kSecReturnData: true,
|
||||
] as [CFString: Any]
|
||||
var result: CFTypeRef?
|
||||
let ret = SecStatus(SecItemCopyMatching(query as CFDictionary, &result))
|
||||
if ret.isSuccess,
|
||||
let resultData = result as? Data
|
||||
{
|
||||
continuation.resume(returning: resultData)
|
||||
} else {
|
||||
continuation.resume(returning: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func search(query: [CFString: Any]) async -> PersistentRef? {
|
||||
return await withCheckedContinuation { [weak self] continuation in
|
||||
guard let self = self else { return }
|
||||
self.workQueue.async {
|
||||
let query = query.merging([
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecReturnPersistentRef: true,
|
||||
]) { (current, new) in new }
|
||||
return await withCheckedContinuation { continuation in
|
||||
let query = query.merging([
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecReturnPersistentRef: true,
|
||||
]) { (current, new) in new }
|
||||
|
||||
var result: CFTypeRef?
|
||||
let ret = SecStatus(SecItemCopyMatching(query as CFDictionary, &result))
|
||||
var result: CFTypeRef?
|
||||
let ret = SecStatus(SecItemCopyMatching(query as CFDictionary, &result))
|
||||
|
||||
if ret.isSuccess, let persistentRef = result as? Data {
|
||||
continuation.resume(returning: persistentRef)
|
||||
} else {
|
||||
continuation.resume(returning: nil)
|
||||
}
|
||||
if ret.isSuccess, let persistentRef = result as? Data {
|
||||
continuation.resume(returning: persistentRef)
|
||||
} else {
|
||||
continuation.resume(returning: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func delete(persistentRef: PersistentRef) async throws {
|
||||
return try await withCheckedThrowingContinuation { [weak self] continuation in
|
||||
self?.workQueue.async {
|
||||
let query = [kSecValuePersistentRef: persistentRef] as [CFString: Any]
|
||||
let ret = SecStatus(SecItemDelete(query as CFDictionary))
|
||||
guard ret.isSuccess || ret == .status(.itemNotFound) else {
|
||||
continuation.resume(
|
||||
throwing: KeychainError.appleSecError(call: "SecItemDelete", status: ret))
|
||||
return
|
||||
}
|
||||
continuation.resume(returning: ())
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
let query = [kSecValuePersistentRef: persistentRef] as [CFString: Any]
|
||||
let ret = SecStatus(SecItemDelete(query as CFDictionary))
|
||||
guard ret.isSuccess || ret == .status(.itemNotFound) else {
|
||||
continuation.resume(
|
||||
throwing: KeychainError.appleSecError(call: "SecItemDelete", status: ret))
|
||||
return
|
||||
}
|
||||
continuation.resume(returning: ())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ public final class Store: ObservableObject {
|
||||
TunnelManager.shared.fetchResources(callback: callback)
|
||||
let intervalInSeconds: TimeInterval = 1
|
||||
let timer = Timer(timeInterval: intervalInSeconds, repeats: true) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
guard self != nil else { return }
|
||||
TunnelManager.shared.fetchResources(callback: callback)
|
||||
}
|
||||
RunLoop.main.add(timer, forMode: .common)
|
||||
|
||||
@@ -116,7 +116,7 @@ public extension AppViewModel {
|
||||
public var externalEventMatchString: String { rawValue }
|
||||
public var externalEventOpenURL: URL { URL(string: "firezone://\(rawValue)")! }
|
||||
|
||||
public func openWindow() {
|
||||
@MainActor public func openWindow() {
|
||||
if let window = NSApp.windows.first(where: {
|
||||
$0.identifier?.rawValue.hasPrefix(identifier) ?? false
|
||||
}) {
|
||||
@@ -129,7 +129,7 @@ public extension AppViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
public func window() -> NSWindow? {
|
||||
@MainActor public func window() -> NSWindow? {
|
||||
NSApp.windows.first { window in
|
||||
if let windowId = window.identifier?.rawValue {
|
||||
return windowId.hasPrefix(self.identifier)
|
||||
|
||||
@@ -2,13 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.networkextension.packet-tunnel</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).PacketTunnelProvider</string>
|
||||
</dict>
|
||||
<key>AppGroupIdentifier</key>
|
||||
<string>$(APP_GROUP_ID)</string>
|
||||
<key>NetworkExtension</key>
|
||||
|
||||
@@ -40,8 +40,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
// initialize the id here too.
|
||||
try await FirezoneId.createIfMissing()
|
||||
|
||||
var passedToken = options?["token"] as? String
|
||||
var keychainToken = try await Token.load()
|
||||
let passedToken = options?["token"] as? String
|
||||
let keychainToken = try await Token.load()
|
||||
|
||||
// Use the provided token or try loading one from the Keychain
|
||||
guard let token = Token(passedToken) ?? keychainToken
|
||||
@@ -275,7 +275,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
extension NEProviderStopReason: CustomStringConvertible {
|
||||
extension NEProviderStopReason: @retroactive CustomStringConvertible {
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .none: return "None"
|
||||
@@ -295,6 +295,7 @@ extension NEProviderStopReason: CustomStringConvertible {
|
||||
case .connectionFailed: return "Connection failed"
|
||||
case .sleep: return "Sleep"
|
||||
case .appUpdate: return "App update"
|
||||
case .internalError: return "Internal error"
|
||||
@unknown default: return "Unknown"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user