Skip to content

Commit

Permalink
Merge branch 'main' into feature/print-macros
Browse files Browse the repository at this point in the history
# Conflicts:
#	Package.swift
#	Sources/UBFoundation/Globals/GlobalLogging.swift
#	Sources/UBFoundation/Logging/Logger+Error.swift
#	Sources/UBFoundation/Logging/Logger.swift
#	Sources/UBFoundation/Logging/LoggerGroup.swift
  • Loading branch information
ubfelix committed Oct 4, 2024
2 parents 197fb98 + d5f5b10 commit 21254b1
Show file tree
Hide file tree
Showing 120 changed files with 729 additions and 2,704 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build & Test

env:
XCODE_VERSION: "Xcode_15.3"
XCODE_VERSION: "Xcode_16.0"

on:
push:
Expand All @@ -21,4 +21,3 @@ jobs:

- name: Fastlane
run: fastlane tests

26 changes: 26 additions & 0 deletions .github/workflows/swiftformat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run SwiftFormat
on:
workflow_dispatch:
push:
branches:
- main

jobs:
swiftformat:
name: swiftformat
runs-on: ["self-hosted", "macOS"]
steps:
- name: Install Swiftformat
run: brew install swiftformat
- name: Run Swiftformat
run: swiftformat .
- name: Create pull request
uses: peter-evans/create-pull-request@v5
with:
commit-message: "[Generated] SwiftFormat"
add-paths: |
*.swift
branch: "generated/swiftformat"
delete-branch: true
title: "[Generated] SwiftFormat"
body: "This action automatically runs [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) on the project. Check the changes and merge them!"
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
--indentcase true
--ifdef outdent
--disable preferForLoop
--disable preferKeyPath

# Don't format generated files
--exclude **/*Generated.swift
59 changes: 46 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
Expand All @@ -8,9 +8,9 @@ let package = Package(
name: "UBKit",
defaultLocalization: "en",
platforms: [
.iOS(.v13),
.watchOS(.v5),
.macOS(.v10_15),
.iOS(.v14),
.watchOS(.v7),
.macOS(.v10_15),
],
products: [
.library(name: "UBFoundation", targets: ["UBFoundation"]),
Expand All @@ -25,18 +25,51 @@ let package = Package(
.package(url: "https://github.com/apple/swift-syntax", .upToNextMajor(from: "509.0.0")),
],
targets: [
.target(name: "UBFoundation", dependencies: ["UBMacros"]),
.target(name: "UBUserInterface", dependencies: ["UBFoundation"]),
.target(name: "UBLocation", dependencies: ["UBFoundation"]),
.target(name: "UBPush", dependencies: ["UBFoundation"]),
.target(name: "UBQRScanner"),
.target(name: "UBDevTools", dependencies: ["UBFoundation"]),

.macro(name: "UBMacros", dependencies: [
.target(
name: "UBFoundation",
dependencies: ["UBMacros"],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.target(
name: "UBUserInterface",
dependencies: ["UBFoundation"],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.target(
name: "UBLocation",
dependencies: ["UBFoundation"],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.target(
name: "UBPush",
dependencies: ["UBFoundation"],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.target(
name: "UBQRScanner",
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.target(
name: "UBDevTools",
dependencies: ["UBFoundation"],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.macro(name: "UBMacros", dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]),

.testTarget(name: "UBFoundationTests",
dependencies: ["UBFoundation", .product(name: "UBLocalNetworking", package: "ios-local-networking")],
resources: [
Expand Down
13 changes: 8 additions & 5 deletions Sources/UBDevTools/BackendDevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import SwiftUI

@available(iOS 13.0, *)
@MainActor
public class BaseUrl: ObservableObject {
let title: String
let url: String
Expand All @@ -21,12 +21,11 @@ public class BaseUrl: ObservableObject {
}
}

@available(iOS 13.0, *)
class BackendDevTools: DevTool {
public class BackendDevTools: DevTool {
private static var didSwizzle = false
public static var baseUrls: [BaseUrl] = []

class ViewModel: ObservableObject {
public class ViewModel: ObservableObject {
@Published var urls: [BaseUrl] = []
var appSpecificView: AnyView = AnyView(EmptyView())
}
Expand Down Expand Up @@ -92,10 +91,11 @@ class BackendDevTools: DevTool {
}
}

@available(iOS 13.0, *)
private extension NSURL {
@MainActor
private static var didSwizzle = false

@MainActor
static func initSwizzleWizzle() {
guard !self.didSwizzle else { return }

Expand All @@ -112,18 +112,21 @@ private extension NSURL {
Self.didSwizzle = true
}

@MainActor
@objc func swizzled_init(string: String, relativeTo: NSURL?) -> NSURL? {
let changed = changedUrl(string)
return self.swizzled_init(string: changed ?? string, relativeTo: relativeTo)
}

@MainActor
@objc func swizzled_init(string: String) -> NSURL? {
let changed = changedUrl(string)
return self.swizzled_init(string: changed ?? string)
}

// MARK: - Exchange implementations

@MainActor
private func changedUrl(_ string: String) -> String? {
for b in BackendDevTools.baseUrls {
let alternative = BackendDevTools.currentUrlString(url: b.url)
Expand Down
1 change: 0 additions & 1 deletion Sources/UBDevTools/BackendUrlEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import SwiftUI

@available(iOS 13.0, *)
struct BackendUrlEditor: View {
@ObservedObject var url: BaseUrl

Expand Down
1 change: 1 addition & 0 deletions Sources/UBDevTools/CacheDevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation

@MainActor
class CacheDevTools {
public static var caches: [(id: String, cache: URLCache)] {
[(id: "Shared", cache: URLCache.shared)] + additionalCaches
Expand Down
6 changes: 3 additions & 3 deletions Sources/UBDevTools/DevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import SwiftUI
import UBFoundation
import UIKit

@MainActor
protocol DevTool {
static func setup()
}

@available(iOS 14.0, *)
@MainActor
public enum UBDevTools {
static var isActivated: Bool = false

Expand Down Expand Up @@ -81,7 +82,6 @@ public enum UBDevTools {
}
}

@available(iOS 14.0, *)
extension UIWindow {
private static var initSwizzled = false

Expand Down Expand Up @@ -125,7 +125,7 @@ extension UIWindow {
return window
}

@objc private func openDevTools() {
@objc public func openDevTools() {
if let rootVC = rootViewController, let devToolsVC = DevToolsViewController() {
var vc = rootVC
while let presented = vc.presentedViewController {
Expand Down
3 changes: 2 additions & 1 deletion Sources/UBDevTools/DevToolsLogExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
// Created by Matthias Felix on 05.10.22.
//

import OSLog
@preconcurrency import OSLog
import SwiftUI

@available(iOS 15.0, *)
@MainActor
class DevToolsLogExtractor: ObservableObject {
private var store: OSLogStore?

Expand Down
2 changes: 0 additions & 2 deletions Sources/UBDevTools/DevToolsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SwiftUI
import UBFoundation
import UIKit

@available(iOS 14.0, *)
public class DevToolsViewController: UIHostingController<DevToolsView> {
// MARK: - Init

Expand All @@ -25,7 +24,6 @@ public class DevToolsViewController: UIHostingController<DevToolsView> {
}
}

@available(iOS 14.0, *)
public struct DevToolsView: View {
@State private var showingKeychainDeleteAlert = false
@State private var showingUserDefaultsDeleteAlert = false
Expand Down
8 changes: 3 additions & 5 deletions Sources/UBDevTools/FingerTipsDevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import UBFoundation
import UIKit

@available(iOS 14.0, *)
class FingerTipsDevTools: DevTool {
private static var overlayWindow: FingerTipsWindow?
private static var notificationHelper: NotificationHelper?
Expand Down Expand Up @@ -56,10 +55,9 @@ class FingerTipsDevTools: DevTool {
}

private class NotificationHelper {
@MainActor
@objc public func setupFingerTips() {
if #available(iOS 14.0, *) {
FingerTipsDevTools.setupFingerTips()
NotificationCenter.default.removeObserver(self)
}
FingerTipsDevTools.setupFingerTips()
NotificationCenter.default.removeObserver(self)
}
}
4 changes: 1 addition & 3 deletions Sources/UBDevTools/FingerTipsWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class FingerTipsWindow: UIWindow {
self.rootViewController = nil
self.isHidden = true

if #available(iOS 13, *) {
windowScene = nil
}
windowScene = nil
}

public func handleTouchEvent(_ event: UIEvent) {
Expand Down
7 changes: 2 additions & 5 deletions Sources/UBDevTools/KeychainEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SwiftUI
import UBFoundation

@available(iOS 13.0, *)
@MainActor
class ObservableKeychainEditor: ObservableObject {
var dictionary: [String: String] = [:]
var keys: [String] = []
Expand All @@ -22,9 +22,7 @@ class ObservableKeychainEditor: ObservableObject {
let temp = getAllKeyChainItems()
self.dictionary = temp
self.keys = Array(dictionary.keys).sorted()
DispatchQueue.main.async {
self.objectWillChange.send()
}
self.objectWillChange.send()
}

private func getAllKeyChainItems() -> [String: String] {
Expand Down Expand Up @@ -59,7 +57,6 @@ class ObservableKeychainEditor: ObservableObject {
}
}

@available(iOS 13.0, *)
public struct KeychainEditor: View {
@ObservedObject var store = ObservableKeychainEditor()

Expand Down
6 changes: 4 additions & 2 deletions Sources/UBDevTools/LocalizationDevTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import UBFoundation
import UIKit

@available(iOS 14.0, *)
class LocalizationDevTools: DevTool {
static func setup() {
if DevToolsView.showLocalizationKeys {
Expand All @@ -19,15 +18,18 @@ class LocalizationDevTools: DevTool {
}

public extension Bundle {
static var localizationKeySwizzled = false
@MainActor
private static var localizationKeySwizzled = false

@MainActor
static func localizationKeySwizzleWizzle() {
guard let originalMethod = class_getInstanceMethod(Bundle.self, #selector(localizedString(forKey:value:table:))), let swizzledMethod = class_getInstanceMethod(Bundle.self, #selector(specialLocalizedString(forKey:value:table:))), !Self.localizationKeySwizzled
else { return }
method_exchangeImplementations(originalMethod, swizzledMethod)
Self.localizationKeySwizzled = true
}

@MainActor
@objc func specialLocalizedString(forKey key: String, value: String?, table tableName: String?) -> String {
key
}
Expand Down
2 changes: 0 additions & 2 deletions Sources/UBDevTools/LogDevToolsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ struct LogDevToolsView: View {
}
}

@available(iOS 14.0, *)
private struct CustomLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
Expand All @@ -74,7 +73,6 @@ private struct CustomLabelStyle: LabelStyle {
}
}

@available(iOS 14.0, *)
private struct ShareView: UIViewControllerRepresentable {
let activityItems: [Any]

Expand Down
9 changes: 5 additions & 4 deletions Sources/UBDevTools/ProxyDevTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UBFoundation
import UIKit

@MainActor
class UBDevToolsProxyHelper {
static let shared = UBDevToolsProxyHelper()

Expand All @@ -25,17 +26,17 @@ class UBDevToolsProxyHelper {
}
}

public class UBFriendlyEvaluator: UBServerTrustEvaluator {
public final class UBFriendlyEvaluator: UBServerTrustEvaluator {
public func evaluate(_ trust: SecTrust, forHost host: String) throws {
// on purpose not throwing, we allow it all
}
}

@available(iOS 14.0, *)
public extension Networking {
public extension UBURLSession {
/// This is a copy of the sharedSession including the proxy and friendly trust settings
@MainActor
static let friendlySharedSession: UBURLSession = {
guard DevToolsView.enableNetworkingProxySettings else { return Networking.sharedSession }
guard DevToolsView.enableNetworkingProxySettings else { return UBURLSession.sharedSession }

let queue = OperationQueue()
queue.name = "Friendly UBURLSession Shared"
Expand Down
Loading

0 comments on commit 21254b1

Please sign in to comment.