|
| 1 | +// Copyright © 2025 Booket. All rights reserved |
| 2 | + |
| 3 | +import BKCore |
| 4 | +import BKData |
| 5 | +import BKDesign |
| 6 | +import BKDomain |
| 7 | +import BKNetwork |
| 8 | +import BKPresentation |
| 9 | +import BKStorage |
| 10 | +import KakaoSDKAuth |
| 11 | +#if DEBUG |
| 12 | +import Pulse |
| 13 | +import PulseUI |
| 14 | +#endif |
| 15 | +import SwiftUI |
| 16 | +import UIKit |
| 17 | + |
| 18 | +import UIKit |
| 19 | + |
| 20 | +public final class DebugOptionViewController: UIViewController { |
| 21 | + |
| 22 | + private struct DebugSection { |
| 23 | + let title: String |
| 24 | + let options: [DebugOption] |
| 25 | + } |
| 26 | + |
| 27 | + private enum DebugOption: String, CaseIterable { |
| 28 | + case showNetworkLog = "네트워크 로그 확인" |
| 29 | + case resetOnboardingSeen = "온보딩 화면 보기" |
| 30 | + |
| 31 | + // 각 옵션에 따라 실행할 함수를 연결 |
| 32 | + func performAction(on viewController: UIViewController) { |
| 33 | + guard let vc = viewController as? DebugOptionViewController else { return } |
| 34 | + switch self { |
| 35 | + case .showNetworkLog: |
| 36 | + vc.openPulseLog() |
| 37 | + case .resetOnboardingSeen: |
| 38 | + vc.resetOnboardingSeen() |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + private let tableView = UITableView(frame: .zero, style: .insetGrouped) |
| 44 | + private var sections: [DebugSection] = [] |
| 45 | + |
| 46 | + @Autowired var markOnboardingSeenUseCase: MarkOnboardingSeenUseCase |
| 47 | + |
| 48 | + override public func viewDidLoad() { |
| 49 | + super.viewDidLoad() |
| 50 | + setupData() |
| 51 | + setupUI() |
| 52 | + setupTableView() |
| 53 | + } |
| 54 | + |
| 55 | + private func setupData() { |
| 56 | + self.sections = [ |
| 57 | + DebugSection(title: "Log", options: [ |
| 58 | + .showNetworkLog |
| 59 | + ]), |
| 60 | + DebugSection(title: "플래그 초기화", options: [ |
| 61 | + .resetOnboardingSeen |
| 62 | + ]) |
| 63 | + ] |
| 64 | + } |
| 65 | + |
| 66 | + // UI 설정은 동일 |
| 67 | + private func setupUI() { |
| 68 | + self.title = "디버그 메뉴" |
| 69 | + view.backgroundColor = .systemGroupedBackground |
| 70 | + view.addSubview(tableView) |
| 71 | + |
| 72 | + tableView.translatesAutoresizingMaskIntoConstraints = false |
| 73 | + NSLayoutConstraint.activate([ |
| 74 | + tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), |
| 75 | + tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), |
| 76 | + tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), |
| 77 | + tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor) |
| 78 | + ]) |
| 79 | + } |
| 80 | + |
| 81 | + // 테이블뷰 설정은 동일 |
| 82 | + private func setupTableView() { |
| 83 | + tableView.delegate = self |
| 84 | + tableView.dataSource = self |
| 85 | + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "DebugCell") |
| 86 | + } |
| 87 | + |
| 88 | + // 각 셀 선택 시 호출될 함수들 |
| 89 | + private func openPulseLog() { |
| 90 | + DispatchQueue.main.async { [weak self] in |
| 91 | + let viewController = MainViewController() |
| 92 | + self?.navigationController?.present(viewController, animated: true) |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + private func resetOnboardingSeen() { |
| 97 | + markOnboardingSeenUseCase.reset() |
| 98 | + forceQuitApplication() |
| 99 | + } |
| 100 | + |
| 101 | + private func forceQuitApplication() { |
| 102 | + UIApplication.shared.perform(#selector(NSXPCConnection.suspend)) |
| 103 | + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { |
| 104 | + exit(0) |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +extension DebugOptionViewController: UITableViewDelegate, UITableViewDataSource { |
| 110 | + |
| 111 | + public func numberOfSections(in tableView: UITableView) -> Int { |
| 112 | + return sections.count |
| 113 | + } |
| 114 | + |
| 115 | + public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { |
| 116 | + return sections[section].title |
| 117 | + } |
| 118 | + |
| 119 | + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| 120 | + return sections[section].options.count |
| 121 | + } |
| 122 | + |
| 123 | + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| 124 | + let cell = tableView.dequeueReusableCell(withIdentifier: "DebugCell", for: indexPath) |
| 125 | + let option = sections[indexPath.section].options[indexPath.row] |
| 126 | + |
| 127 | + var content = cell.defaultContentConfiguration() |
| 128 | + content.text = option.rawValue |
| 129 | + cell.contentConfiguration = content |
| 130 | + cell.accessoryType = .none |
| 131 | + |
| 132 | + return cell |
| 133 | + } |
| 134 | + |
| 135 | + public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
| 136 | + tableView.deselectRow(at: indexPath, animated: true) |
| 137 | + let selectedOption = sections[indexPath.section].options[indexPath.row] |
| 138 | + selectedOption.performAction(on: self) |
| 139 | + } |
| 140 | +} |
0 commit comments