Skip to content

Commit

Permalink
Merge pull request #44 from infinum/feature/code-updates
Browse files Browse the repository at this point in the history
Feature/code updates
  • Loading branch information
ZvonimirMedak authored Jan 13, 2025
2 parents f8f1285 + 17b7612 commit 114b0f3
Show file tree
Hide file tree
Showing 37 changed files with 769 additions and 720 deletions.
869 changes: 439 additions & 430 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

68 changes: 12 additions & 56 deletions Sentinel/Classes/Core/CustomInfoTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@

import SwiftUI

@objcMembers
public class CustomInfoTool: NSObject, Tool {
/// Tool which gives the ability to show info + value pairs
public struct CustomInfoTool: Tool {

// MARK: - Public properties

public let name: String

@ViewBuilder
public var content: any View {
SentinelListView(title: name, items: createToolTable(with: info).sections)
}

// MARK: - Internal properties

let info: [Section]
Expand All @@ -31,7 +26,15 @@ public class CustomInfoTool: NSObject, Tool {
}
}

// MARK: - Extensions -
// MARK: - UI

public extension CustomInfoTool {

var content: any View {
SentinelListView(title: name, items: createToolTable(with: info).sections)
}

}

// MARK: - Helpers

Expand All @@ -48,50 +51,3 @@ extension CustomInfoTool {
}

}

extension CustomInfoTool {

public class Section {

// MARK: - Internal properties

let title: String?
let items: [Item]

// MARK: - Lifecycle

public init(title: String? = nil, items: [Item]) {
self.title = title
self.items = items
}
}

public class Item {

// MARK: - Internal properties

let title: String
let value: String

// MARK: - Lifecycle

public init(title: String, value: String) {
self.title = title
self.value = value
}
}

}

// MARK: - Equatable and Identifiable conformance

extension CustomInfoTool.Item: Equatable, Identifiable {

public var id: String {
title
}

public static func == (lhs: CustomInfoTool.Item, rhs: CustomInfoTool.Item) -> Bool {
lhs.title == rhs.title
}
}
62 changes: 62 additions & 0 deletions Sentinel/Classes/Core/CustomInfoToolSection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// CustomInfoToolSection.swift
// Sentinel
//
// Created by Zvonimir Medak on 18.12.2024..
//

import Foundation

public extension CustomInfoTool {

/// Section Item for the CustomInfoTool which expects CustomInfoTool.Item for its items
struct Section {

// MARK: - Internal properties

let title: String?
let items: [Item]

// MARK: - Lifecycle

public init(title: String? = nil, items: [Item]) {
self.title = title
self.items = items
}
}

/// Row Item for the CustomInfoTool which will show a title + value pair
struct Item {

// MARK: - Internal properties

let title: String
let value: String

// MARK: - Lifecycle

public init(title: String, value: String) {
self.title = title
self.value = value
}
}

}

// MARK: - Equatable conformance

extension CustomInfoTool.Item: Equatable {

public static func == (lhs: CustomInfoTool.Item, rhs: CustomInfoTool.Item) -> Bool {
lhs.title == rhs.title
}
}

// MARK: - Identifiable conformance

extension CustomInfoTool.Item: Identifiable {

public var id: String {
title
}
}
23 changes: 14 additions & 9 deletions Sentinel/Classes/Core/Internal/ApplicationTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation
import SwiftUI

final class ApplicationTool: Tool {
/// Tool which shows Plist information about the App
struct ApplicationTool: Tool {

// MARK: - Public properties

Expand All @@ -20,7 +21,7 @@ final class ApplicationTool: Tool {

// MARK: - Private properties

private lazy var tool = CustomInfoTool(
private let tool = CustomInfoTool(
name: "Application",
info: [
CustomInfoTool.Section(
Expand All @@ -42,8 +43,13 @@ final class ApplicationTool: Tool {
)
]
)

// MARK: - Internal properties
}

// MARK: - Extensions

// MARK: - UI

extension ApplicationTool {

var toolTable: ToolTable {
tool.createToolTable(with: tool.info)
Expand All @@ -52,22 +58,21 @@ final class ApplicationTool: Tool {
var content: any View {
SentinelListView(title: name, items: toolTable.sections)
}

}

// MARK: - Internal extension
// MARK: - Info helpers

extension ApplicationTool {

func stringFromPlist(for key: CFString) -> String {
static func stringFromPlist(for key: CFString) -> String {
stringFromPlist(for: key as String)
}

func stringFromPlist(for key: String) -> String {
static func stringFromPlist(for key: String) -> String {
Bundle.main.object(forInfoDictionaryKey: key).map { String(describing: $0) } ?? ""
}

var bundleAllInfos: [CustomInfoTool.Item] {
static var bundleAllInfos: [CustomInfoTool.Item] {
Bundle.main.infoDictionary?
.map { CustomInfoTool.Item(title: $0.key, value: String(describing: $0.value)) }
?? []
Expand Down
36 changes: 19 additions & 17 deletions Sentinel/Classes/Core/Internal/DeviceTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import SwiftUI

final class DeviceTool: Tool {
/// Tool which shows current device information
struct DeviceTool: Tool {

// MARK: - Public properties

Expand All @@ -17,19 +18,9 @@ final class DeviceTool: Tool {

public init() {}

// MARK: - Internal properties

var toolTable: ToolTable {
tool.createToolTable(with: tool.info)
}

var content: any View {
SentinelListView(title: name, items: toolTable.sections)
}

// MARK: - Private properties

private lazy var tool = CustomInfoTool(
private let tool = CustomInfoTool(
name: "Device",
info: [
CustomInfoTool.Section(title: "Device", items: [
Expand All @@ -44,17 +35,28 @@ final class DeviceTool: Tool {

}

// MARK: - Extensions -
// MARK: - UI

extension DeviceTool {

var toolTable: ToolTable {
tool.createToolTable(with: tool.info)
}

var content: any View {
SentinelListView(title: name, items: toolTable.sections)
}
}

// MARK: - Helpers
// MARK: - Info helpers

private extension DeviceTool {

var systemVersion: String {
static var systemVersion: String {
"\(UIDevice.current.systemName) \(UIDevice.current.systemVersion)"
}

var batteryState: String {
static var batteryState: String {
switch UIDevice.current.batteryState {
case .charging:
"Charging at: \(calculateBatteryPercentage(with: UIDevice.current.batteryLevel.description))%"
Expand All @@ -67,7 +69,7 @@ private extension DeviceTool {
}
}

func calculateBatteryPercentage(with amount: String) -> String {
static func calculateBatteryPercentage(with amount: String) -> String {
guard let batteryLevel = Double(amount) else { return "Unknown" }
return "\(batteryLevel * 100.0)"
}
Expand Down
8 changes: 3 additions & 5 deletions Sentinel/Classes/Core/Internal/SentinelInternal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ extension Sentinel {
) {
let tabItems = createTabItems(
with: tools,
preferences: preferences,
viewController: viewController
preferences: preferences
)

let tabBarController = UIHostingController(rootView: SentinelTabBarView(tabs: tabItems))
viewController.present(tabBarController, animated: true)
}
}

// MARK: - Private extension
// MARK: - Helpers

private extension Sentinel {

func createTabItems(
with tools: [Tool],
preferences: [ToolTableSection],
viewController: UIViewController
preferences: [ToolTableSection]
) -> [SentinelTabItem] {
[
SentinelTabItem(tab: .device),
Expand Down
7 changes: 7 additions & 0 deletions Sentinel/Classes/Core/Internal/SentinelTabItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ struct SentinelTabItem {
init(tab: SentinelTab) {
self.tab = tab
}
}

// MARK: - Helpers

extension SentinelTabItem {

var barItemTitle: String {
switch tab {
Expand Down Expand Up @@ -45,6 +50,8 @@ struct SentinelTabItem {
}
}

// MARK: - Private helpers

private extension SentinelTabItem {

var toolTable: ToolTable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

import Foundation

class CPUInfoProvider {

struct CPUInfoProvider {

/// Fetches the number of cores the devices has
var numberOfCores: Int {
return ProcessInfo().processorCount
ProcessInfo().processorCount
}


/// Fetches the percentage of the CPU currently being used by the App
var currentUsage: Double {
var totalUsageOfCPU: Double = 0.0
var threadsList: thread_act_array_t?
var threadsCount = mach_msg_type_number_t(0)
let threadsResult = withUnsafeMutablePointer(to: &threadsList) {
return $0.withMemoryRebound(to: thread_act_array_t?.self, capacity: 1) {
$0.withMemoryRebound(to: thread_act_array_t?.self, capacity: 1) {
task_threads(mach_task_self_, $0, &threadsCount)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ struct MemoryUsage {
let total: Int64
}

class MemoryInfoProvider {

struct MemoryInfoProvider {

/// Fetches the current memory usage of the App
var currentUsage: MemoryUsage {
var taskInfo = task_vm_info_data_t()
var count = mach_msg_type_number_t(MemoryLayout<task_vm_info>.size) / 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import Foundation

class SystemInfoProvider {
struct SystemInfoProvider {

/// Fetches the active time of the app
var uptime: String {
secondsToHoursMinutesSeconds(interval: ProcessInfo().systemUptime)
}
Expand All @@ -30,6 +31,6 @@ private extension SystemInfoProvider {
}

func formattedTime(from value: Int) -> String {
return value < 10 ? "0\(value)" : "\(value)"
value < 10 ? "0\(value)" : "\(value)"
}
}
Loading

0 comments on commit 114b0f3

Please sign in to comment.