-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugScreenPresenterService.swift
More file actions
100 lines (76 loc) · 2.72 KB
/
DebugScreenPresenterService.swift
File metadata and controls
100 lines (76 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// DebugScreenPresenterService.swift
// DebugScreen
//
// Created by Anton Shelar on 02.11.2020.
//
import UIKit
/// Provides functionality for open DebugScreen, logs file, show custom screens and simple alerts with messages.
public final class DebugScreenPresenterService {
// MARK: - Static Properties
/// Singleton that provides access to all presenter functions.
public static let shared = DebugScreenPresenterService()
// MARK: - Private Properties
private var coordinator: DebugScreenCoordinator?
// MARK: - Initialization
private init() { }
// MARK: - Public Methods
/// Open Debug screen menu.
public func showDebugScreen() {
guard coordinator == nil else {
return
}
configureCoordinator()
coordinator?.start()
}
/// Show alert with title and message.
/// Can be showed only when debug screen is open.
/// - Parameters:
/// - title: Alert title.
/// - message: Alert message.
public func showAlert(title: String? = nil, message: String) {
let model = AlertModel(title: title, message: message)
openModule(.alert(model: model))
}
/// Show custom view controller modally.
/// Can be showed only when debug screen is open.
/// - Parameter view: Screen to display.
public func presentCustomScreen(_ view: UIViewController) {
openModule(.customScreen(view, method: .present))
}
/// Push custom view controller onto the debug screen navigation stack.
/// Provides a standard back button to return to the debug menu.
/// Can be used only when debug screen is open.
/// - Parameter view: Screen to display.
public func pushCustomScreen(_ view: UIViewController) {
openModule(.customScreen(view, method: .push))
}
/// Open log file.
/// Can be showed only when debug screen is open.
public func openLogFile() {
let model = FileViewerModel(filePath: DebugScreenConfiguration.shared.logCatcherService.logFilePath)
openModule(.fileViewer(model: model))
}
}
// MARK: - Private Methods
private extension DebugScreenPresenterService {
func configureCoordinator() {
coordinator = DebugScreenCoordinator()
coordinator?.completionHandler = { [weak self] in
self?.coordinator = nil
}
}
func isDebugScreenAvailable() -> Bool {
guard coordinator != nil else {
debugPrint("ℹ️ Modules presentation available only from Debug Screen menu!")
return false
}
return true
}
func openModule(_ module: ModuleType) {
guard isDebugScreenAvailable() else {
return
}
coordinator?.open(module: module)
}
}