Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.9
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "DebugMenu",
defaultLocalization: "en",
platforms: [.iOS(.v14)],
platforms: [.iOS(.v16)],
products: [
.library(
name: "DebugMenu",
Expand Down
2 changes: 2 additions & 0 deletions Sources/DebugMenu/DebugMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import UIKit

@available(iOSApplicationExtension, unavailable)
public struct DebugMenu {

@MainActor
public static func install(
windowScene: UIWindowScene? = nil,
items: [DebugItem] = [],
Expand Down
2 changes: 1 addition & 1 deletion Sources/DebugMenu/Entity/Application.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public class Application {
public static var current: Application = .init()
public static var current: Application { Application() }

public var appName: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String
Expand Down
3 changes: 2 additions & 1 deletion Sources/DebugMenu/Entity/DashboardItem.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public protocol DashboardItem {
@MainActor
public protocol DashboardItem: Sendable {
var title: String { get }
func startMonitoring()
func stopMonitoring()
Expand Down
18 changes: 9 additions & 9 deletions Sources/DebugMenu/Entity/DebugItem.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import UIKit

public protocol DebugItem {
public protocol DebugItem: Sendable {
var debugItemTitle: String { get }
var action: DebugItemAction { get }
}

public enum DebugItemAction {
public enum DebugItemAction: Sendable {
case didSelect(
operation: (_ controller: UIViewController) async -> DebugMenuResult
operation: @Sendable @MainActor (_ controller: UIViewController) async -> DebugMenuResult
)
case execute(_ operation: () async -> DebugMenuResult)
case execute(_ operation: @Sendable () async -> DebugMenuResult)
case toggle(
current: () -> Bool,
operation: (_ isOn: Bool) async -> DebugMenuResult
current: @Sendable () -> Bool,
operation: @Sendable (_ isOn: Bool) async -> DebugMenuResult
)
case slider(
current: () -> Double,
valueLabelText: (Double) -> String,
current: @Sendable () -> Double,
valueLabelText: @Sendable (Double) -> String,
range: ClosedRange<Double>,
operation: (_ value: Double) async -> DebugMenuResult
operation: @Sendable (_ value: Double) async -> DebugMenuResult
)
}
5 changes: 3 additions & 2 deletions Sources/DebugMenu/Entity/Device.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UIKit

public class Device {
public static let current: Device = .init()
@MainActor
public final class Device {
public static var current: Device { Device() }

public var localizedModel: String {
UIDevice.current.localizedModel
Expand Down
4 changes: 2 additions & 2 deletions Sources/DebugMenu/Entity/Device/GPU.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import Metal

class GPU {
static var current: GPU = .init()
final class GPU {
static var current: GPU { GPU() }
let device: MTLDevice

init() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DebugMenu/Entity/Device/NetworkUsage.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct NetworkUsage {
public struct NetworkUsage: Sendable {
public let wifiDataSent: UInt64
public let wifiDataReceived: UInt64
public let wwanDataSent: UInt64
Expand Down
8 changes: 4 additions & 4 deletions Sources/DebugMenu/Entity/MetricsFetcher.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public enum MetricsFetcher {
case text(_ fetcher: () -> String)
case graph(_ fetcher: () -> [Double])
case interval(_ fetcher: () -> [TimeInterval])
public enum MetricsFetcher: Sendable {
case text(_ fetcher: @Sendable @MainActor () -> String)
case graph(_ fetcher: @Sendable @MainActor () -> [Double])
case interval(_ fetcher: @Sendable @MainActor () -> [TimeInterval])
}
6 changes: 3 additions & 3 deletions Sources/DebugMenu/Entity/Options.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Foundation
import UIKit

public enum Options {
public enum Options: Sendable {
case showsWidgetOnLaunch
case showsRecentItems
case launchIcon(LaunchIcon)

public struct LaunchIcon {
public struct LaunchIcon: Sendable {
public typealias Position = FloatingItemGestureRecognizer.Edge

let image: UIImage?
Expand All @@ -21,7 +21,7 @@ public enum Options {
}
}

public static var `default`: [Options] = [.showsRecentItems]
public static var `default`: [Options] { [.showsRecentItems] }

var isShowsWidgetOnLaunch: Bool {
if case .showsWidgetOnLaunch = self { return true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class FloatingItemGestureRecognizer: UIPanGestureRecognizer {
private weak var groundView: UIView?
private var gestureGap: CGPoint?
private let margin: CGFloat = 16
public enum Edge {
public enum Edge: Sendable {
case top
// case center
case bottom
Expand All @@ -26,7 +26,7 @@ public class FloatingItemGestureRecognizer: UIPanGestureRecognizer {

}

deinit {
@MainActor deinit {
self.removeTarget(self, action: #selector(pan(_:)))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public class CPUGraphDashboardItem: DashboardItem {
@MainActor
public final class CPUGraphDashboardItem: DashboardItem {
public init() {}
public let title: String = "CPU"
private var data: [Double] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public class CPUUsageDashboardItem: DashboardItem {
@MainActor
public final class CPUUsageDashboardItem: DashboardItem {
public init() {}
public let title: String = "CPU"
private var text: String = ""
Expand Down
3 changes: 2 additions & 1 deletion Sources/DebugMenu/Plugin/Dashboard/FPSDashboardItem.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation
import QuartzCore

public class FPSDashboardItem: DashboardItem {
@MainActor
public final class FPSDashboardItem: DashboardItem {
public let title: String = "FPS"
var displayLink: CADisplayLink?
var lastupdated: CFTimeInterval = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public class GPUMemoryUsageDashboardItem: DashboardItem {
@MainActor
public final class GPUMemoryUsageDashboardItem: DashboardItem {
public init() {}
public let title: String = "GPU MEM"
private var text: String = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Combine
import Foundation

public class IntervalDashboardItem: DashboardItem {
@MainActor
public final class IntervalDashboardItem: DashboardItem {
public init(title: String, name: String) {
self.title = title
self.name = Notification.Name(name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

public class MemoryUsageDashboardItem: DashboardItem {
@MainActor
public final class MemoryUsageDashboardItem: DashboardItem {
public init() {}
public let title: String = "MEM"
private var text: String = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Combine
import Foundation

public class NetworkUsageDashboardItem: DashboardItem {
@MainActor
public final class NetworkUsageDashboardItem: DashboardItem {
public init() {}
public let title: String = "Network"
var lastNetworkUsage: NetworkUsage? = nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Combine
import Foundation

public class ThermalStateDashboardItem: DashboardItem {
@MainActor
public final class ThermalStateDashboardItem: DashboardItem {
public init() {}
public let title: String = "Thermal"
var currentThermalState: ProcessInfo.ThermalState = .nominal
Expand Down
4 changes: 2 additions & 2 deletions Sources/DebugMenu/Plugin/DebugMenu/AppInfoDebugItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public struct AppInfoDebugItem: DebugItem {
public init() {}
public var debugItemTitle: String = "App Info"
public var action: DebugItemAction = .didSelect { parent in
let vc = await EnvelopePreviewTableViewController {
let vc = EnvelopePreviewTableViewController {
[
"App Name": Application.current.appName,
"Version": Application.current.version,
Expand All @@ -18,7 +18,7 @@ public struct AppInfoDebugItem: DebugItem {
.map({ Envelope.init(key: $0.key, value: $0.value) })
.sorted(by: { $0.key < $1.key })
}
await parent.navigationController?.pushViewController(vc, animated: true)
parent.navigationController?.pushViewController(vc, animated: true)
return .success()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import UIKit

public struct CaseSelectableDebugItem<T: CaseIterable & RawRepresentable>: DebugItem
public struct CaseSelectableDebugItem<T: CaseIterable & RawRepresentable & Sendable>: DebugItem
where T.RawValue: Equatable {
public init(currentValue: T, didSelected: @escaping (T) -> Void) {
public init(currentValue: T, didSelected: @escaping @Sendable @MainActor (T) -> Void) {
self.action = .didSelect { controller in
let vc = await CaseSelectableTableController<T>(
let vc = CaseSelectableTableController<T>(
currentValue: currentValue,
didSelected: didSelected
)
await controller.navigationController?.pushViewController(vc, animated: true)
controller.navigationController?.pushViewController(vc, animated: true)
return .success()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/DebugMenu/Plugin/DebugMenu/DeviceInfoDebugItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public struct DeviceInfoDebugItem: DebugItem {
public init() {}
public var debugItemTitle: String = "Device Info"
public var action: DebugItemAction = .didSelect { parent in
let vc = await EnvelopePreviewTableViewController {
let vc = EnvelopePreviewTableViewController {
[
"Name": Device.current.name,
"Battery level": Device.current.localizedBatteryLevel,
Expand All @@ -22,7 +22,7 @@ public struct DeviceInfoDebugItem: DebugItem {
]
.map({ Envelope(key: $0.key, value: $0.value) }).sorted(by: { $0.key < $1.key })
}
await parent.navigationController?.pushViewController(vc, animated: true)
parent.navigationController?.pushViewController(vc, animated: true)
return .success()
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/DebugMenu/Plugin/DebugMenu/GroupDebugItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public struct GroupDebugItem: DebugItem, HasDebugItems {
public var debugItemTitle: String
public var action: DebugItemAction {
.didSelect { controller in
let vc = await InAppDebuggerViewController(
let vc = InAppDebuggerViewController(
title: self.debugItemTitle,
debuggerItems: self.debugItems,
options: []
)
await controller.navigationController?.pushViewController(vc, animated: true)
controller.navigationController?.pushViewController(vc, animated: true)
return .success()
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/DebugMenu/Plugin/DebugMenu/KeyValueDebugItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Foundation
public struct KeyValueDebugItem: DebugItem {
public init(
title: String,
fetcher: @escaping () async -> [Envelope]
fetcher: @escaping @Sendable @MainActor () async -> [Envelope]
) {
self.title = title
self.action = .didSelect(operation: { parent in
let vc = await EnvelopePreviewTableViewController(fetcher: fetcher)
await parent.navigationController?.pushViewController(vc, animated: true)
let vc = EnvelopePreviewTableViewController(fetcher: fetcher)
parent.navigationController?.pushViewController(vc, animated: true)
return .success()
})
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/DebugMenu/Plugin/DebugMenu/SliderDebugItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Foundation
public struct SliderDebugItem: DebugItem {
public init(
title: String,
current: @escaping () -> Double,
valueLabelText: @escaping (Double) -> String = { String(format: "%.2f", $0) },
current: @escaping @Sendable () -> Double,
valueLabelText: @escaping @Sendable (Double) -> String = { String(format: "%.2f", $0) },
range: ClosedRange<Double> = 0.0...1.0,
onChange: @escaping (Double) -> Void
onChange: @escaping @Sendable (Double) -> Void
) {
self.title = title
self.action = .slider(
Expand Down
6 changes: 5 additions & 1 deletion Sources/DebugMenu/Plugin/DebugMenu/ToggleDebugItem.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Foundation

public struct ToggleDebugItem: DebugItem {
public init(title: String, current: @escaping () -> Bool, onChange: @escaping (Bool) -> Void) {
public init(
title: String,
current: @escaping @Sendable () -> Bool,
onChange: @escaping @Sendable (Bool) -> Void
) {
self.title = title
self.action = .toggle(
current: current,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation
import UIKit

public class CaseSelectableTableController<T: CaseIterable & RawRepresentable>:
public class CaseSelectableTableController<T: CaseIterable & RawRepresentable & Sendable>:
UITableViewController
where T.RawValue: Equatable {
public let currentValue: T
public let didSelected: (T) -> Void
private var selectedIndex: IndexPath? = nil

public init(currentValue: T, didSelected: @escaping (T) -> Void) {
public init(currentValue: T, didSelected: @escaping @Sendable @MainActor (T) -> Void) {
self.currentValue = currentValue
self.didSelected = didSelected
super.init(style: .grouped)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EnvelopePreviewTableViewController: UITableViewController {
var envelops: [Envelope] = []
var fetcher: () async -> [Envelope]

init(fetcher: @escaping () async -> [Envelope]) {
init(fetcher: @escaping @Sendable @MainActor () async -> [Envelope]) {
self.fetcher = fetcher
super.init(style: .plain)
}
Expand Down
Loading