Skip to content

Commit c920588

Browse files
committed
chore: update example app
Signed-off-by: Denis Dobanda <[email protected]>
1 parent 410d40e commit c920588

File tree

7 files changed

+103
-52
lines changed

7 files changed

+103
-52
lines changed

SecurityToolkitExample/SecurityToolkitExample.xcodeproj/project.pbxproj

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
42B973FC2C57C4380040D9BC /* ThreatList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42B973FB2C57C4380040D9BC /* ThreatList.swift */; };
1313
42B973FE2C57C4390040D9BC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 42B973FD2C57C4390040D9BC /* Assets.xcassets */; };
1414
42C3DCE12C5A877B00973681 /* ThreatRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C3DCE02C5A877B00973681 /* ThreatRow.swift */; };
15-
42C3DCE32C5A87B200973681 /* ThreatStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C3DCE22C5A87B200973681 /* ThreatStatus.swift */; };
15+
42C3DCE32C5A87B200973681 /* ThreatOverview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C3DCE22C5A87B200973681 /* ThreatOverview.swift */; };
1616
42C3DCE52C5A892D00973681 /* Dimens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C3DCE42C5A892D00973681 /* Dimens.swift */; };
1717
42C3DCE82C5CE54B00973681 /* RswiftLibrary in Frameworks */ = {isa = PBXBuildFile; productRef = 42C3DCE72C5CE54B00973681 /* RswiftLibrary */; };
1818
42C3DCED2C5CE6F500973681 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 42C3DCEB2C5CE6F500973681 /* Localizable.strings */; };
1919
42C3DCF52C5CEFE200973681 /* SystemImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C3DCF42C5CEFE200973681 /* SystemImage.swift */; };
20+
882CEB5F2D536FF0005D7171 /* ThreatViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 882CEB5D2D536FE8005D7171 /* ThreatViewModel.swift */; };
2021
/* End PBXBuildFile section */
2122

2223
/* Begin PBXFileReference section */
@@ -25,10 +26,11 @@
2526
42B973FB2C57C4380040D9BC /* ThreatList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreatList.swift; sourceTree = "<group>"; };
2627
42B973FD2C57C4390040D9BC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2728
42C3DCE02C5A877B00973681 /* ThreatRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreatRow.swift; sourceTree = "<group>"; };
28-
42C3DCE22C5A87B200973681 /* ThreatStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreatStatus.swift; sourceTree = "<group>"; };
29+
42C3DCE22C5A87B200973681 /* ThreatOverview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreatOverview.swift; sourceTree = "<group>"; };
2930
42C3DCE42C5A892D00973681 /* Dimens.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dimens.swift; sourceTree = "<group>"; };
3031
42C3DCEC2C5CE6F500973681 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
3132
42C3DCF42C5CEFE200973681 /* SystemImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemImage.swift; sourceTree = "<group>"; };
33+
882CEB5D2D536FE8005D7171 /* ThreatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreatViewModel.swift; sourceTree = "<group>"; };
3234
/* End PBXFileReference section */
3335

3436
/* Begin PBXFrameworksBuildPhase section */
@@ -89,10 +91,11 @@
8991
42C3DCEA2C5CE64300973681 /* Sources */ = {
9092
isa = PBXGroup;
9193
children = (
94+
882CEB5D2D536FE8005D7171 /* ThreatViewModel.swift */,
9295
42B973F92C57C4380040D9BC /* SecurityToolkitExampleApp.swift */,
9396
42B973FB2C57C4380040D9BC /* ThreatList.swift */,
9497
42C3DCE02C5A877B00973681 /* ThreatRow.swift */,
95-
42C3DCE22C5A87B200973681 /* ThreatStatus.swift */,
98+
42C3DCE22C5A87B200973681 /* ThreatOverview.swift */,
9699
42C3DCE42C5A892D00973681 /* Dimens.swift */,
97100
42C3DCF42C5CEFE200973681 /* SystemImage.swift */,
98101
);
@@ -178,10 +181,11 @@
178181
files = (
179182
42B973FC2C57C4380040D9BC /* ThreatList.swift in Sources */,
180183
42C3DCF52C5CEFE200973681 /* SystemImage.swift in Sources */,
181-
42C3DCE32C5A87B200973681 /* ThreatStatus.swift in Sources */,
184+
42C3DCE32C5A87B200973681 /* ThreatOverview.swift in Sources */,
182185
42C3DCE12C5A877B00973681 /* ThreatRow.swift in Sources */,
183186
42C3DCE52C5A892D00973681 /* Dimens.swift in Sources */,
184187
42B973FA2C57C4380040D9BC /* SecurityToolkitExampleApp.swift in Sources */,
188+
882CEB5F2D536FF0005D7171 /* ThreatViewModel.swift in Sources */,
185189
);
186190
runOnlyForDeploymentPostprocessing = 0;
187191
};
@@ -344,7 +348,7 @@
344348
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
345349
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
346350
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
347-
IPHONEOS_DEPLOYMENT_TARGET = 17.5;
351+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
348352
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
349353
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
350354
MACOSX_DEPLOYMENT_TARGET = 14.5;

SecurityToolkitExample/SecurityToolkitExample/Resources/en.lproj/Localizable.strings

+2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
"threat.list.description" = "Here is a list of the threats that could put you at risk";
1818

1919
// MARK: Threat Row
20+
"threat.row.state.initial" = "INITIAL";
2021
"threat.row.state.detected" = "DETECTED";
2122
"threat.row.state.safe" = "SAFE";
23+
"threat.row.state.exception" = "EXCEPTION";

SecurityToolkitExample/SecurityToolkitExample/Sources/ThreatList.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import SwiftUI
2+
import SecurityToolkit
23

34
struct ThreatList: View {
45

6+
@ObservedObject private var vm = ThreatViewModel.shared
7+
58
var body: some View {
69
List {
710
Section {
8-
ForEach(ThreatStatus.threats, id: \.self) {
11+
ForEach(vm.threatOverview, id: \.self) {
912
ThreatRow(threat: $0)
1013
}
1114
} header: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Foundation
2+
import SecurityToolkit
3+
4+
struct ThreatOverview: Hashable {
5+
let title: String
6+
let description: String
7+
let status: ThreatStatus
8+
var isOk: Bool {
9+
get { status == .notChecked || status == .notPresent }
10+
}
11+
12+
static func threats(threatsReport: ThreatReport) -> [ThreatOverview] {
13+
[
14+
ThreatOverview(
15+
title: R.string.localizable.threatJailbreakTitle(),
16+
description: R.string.localizable.threatJailbreakDescription(),
17+
status: threatsReport.rootPrivileges
18+
),
19+
ThreatOverview(
20+
title: R.string.localizable.threatHooksTitle(),
21+
description: R.string.localizable.threatHooksDescription(),
22+
status: threatsReport.hooks
23+
),
24+
ThreatOverview(
25+
title: R.string.localizable.threatSimulatorTitle(),
26+
description: R.string.localizable.threatSimulatorDescription(),
27+
status: threatsReport.simulator
28+
),
29+
ThreatOverview(
30+
title: R.string.localizable.threatDebuggerTitle(),
31+
description: R.string.localizable.threatDebuggerDescription(),
32+
status: threatsReport.debugger
33+
),
34+
ThreatOverview(
35+
title: R.string.localizable.threatPasscodeUnprotectedDeviceTitle(),
36+
description: R.string.localizable.threatPasscodeUnprotectedDeviceDescription(),
37+
status: threatsReport.devicePasscode
38+
),
39+
ThreatOverview(
40+
title: R.string.localizable.threatHardwareTitle(),
41+
description: R.string.localizable.threatHardwareDescription(),
42+
status: threatsReport.hardwareCryptography
43+
),
44+
]
45+
}
46+
}
47+
48+

SecurityToolkitExample/SecurityToolkitExample/Sources/ThreatRow.swift

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@ import SwiftUI
22

33
struct ThreatRow: View {
44

5-
let threat: ThreatStatus
5+
let threat: ThreatOverview
6+
7+
var threatText: String {
8+
get {
9+
switch threat.status {
10+
case .notChecked: return R.string.localizable.threatRowStateInitial()
11+
case .notPresent: return R.string.localizable.threatRowStateSafe()
12+
case .present: return R.string.localizable.threatRowStateDetected()
13+
case .exception: return R.string.localizable.threatRowStateException()
14+
}
15+
}
16+
}
617

718
var body: some View {
819
VStack(alignment: .leading) {
920
HStack {
1021
Text(threat.title)
1122
Spacer()
12-
Text(threat.isDetected ? R.string.localizable.threatRowStateDetected() : R.string.localizable.threatRowStateSafe())
23+
Text(threatText)
1324
.font(.caption2)
1425
.foregroundColor(.white)
1526
.padding(.horizontal, Dimens.unit8)
1627
.padding(.vertical, Dimens.unit2)
1728
.background {
1829
RoundedRectangle(cornerRadius: Dimens.unit4)
19-
.fill(threat.isDetected ? .red : .green)
30+
.fill(threat.isOk ? .green : .red)
2031
}
2132
}
2233
Text(threat.description)

SecurityToolkitExample/SecurityToolkitExample/Sources/ThreatStatus.swift

-43
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// ThreatViewModel.swift
3+
// SecurityToolkitExample
4+
//
5+
// Created by Dobanda, Denis on 05.02.25.
6+
//
7+
import Foundation
8+
import SecurityToolkit
9+
import Combine
10+
11+
class ThreatViewModel: ObservableObject {
12+
static let shared: ThreatViewModel = ThreatViewModel()
13+
14+
@Published var threatOverview = [ThreatOverview]()
15+
16+
private var subscribtions = Set<AnyCancellable>()
17+
18+
private init() {
19+
ThreatDetectionCenter
20+
.threatReports
21+
.receive(on: DispatchQueue.main)
22+
.map(ThreatOverview.threats(threatsReport:))
23+
.sink { self.threatOverview = $0 }
24+
.store(in: &subscribtions)
25+
}
26+
}

0 commit comments

Comments
 (0)