Skip to content

Add font style #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 16, 2025
1,260 changes: 633 additions & 627 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sentinel/Classes/Core/CustomInfoTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension CustomInfoTool {
items: section.items.map { .customInfo($0) }
)
}
return ToolTable(name: name, sections: sections)
return ToolTable(name: "Information", sections: sections)
}

}
29 changes: 29 additions & 0 deletions Sentinel/Classes/Core/Internal/Font+Size.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Font+Size.swift
// Pods
//
// Created by Zvonimir Medak on 17.03.2025..
//

import Foundation
import SwiftUI

enum FontSize: CGFloat {
case title1 = 24
case subtitle1 = 16
case body1 = 13
case caption1 = 11
}

extension Font {

static let title1Bold = system(fontSize: .title1, weight: .bold)
static let subtitle1Bold = system(fontSize: .subtitle1, weight: .bold)
static let body1Bold = system(fontSize: .body1, weight: .bold)
static let body1Regular = system(fontSize: .body1, weight: .regular)
static let caption1Regular = system(fontSize: .caption1, weight: .regular)

private static func system(fontSize: FontSize, weight: Font.Weight) -> Font {
system(size: fontSize.rawValue).weight(weight)
}
}
2 changes: 1 addition & 1 deletion Sentinel/Classes/Core/Internal/SentinelListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private struct ContentView: View {
Section {
if let title = currentSection.title {
Text(title)
.font(.headline)
.font(.title1Bold)
}

ForEach(currentSection.items) { item in
Expand Down
2 changes: 1 addition & 1 deletion Sentinel/Classes/Core/Internal/SentinelTabItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private extension SentinelTabItem {
ToolTableItem.navigation(NavigationToolItem(title: tool.name, didSelect: { tool.content }))
#endif
}
let section = ToolTableSection(title: barItemTitle, items: navigationItems)
let section = ToolTableSection(title: "Custom Tools", items: navigationItems)
let toolTable = ToolTable(name: barItemTitle, sections: [section])
return toolTable
case .preferences(let items):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ struct PerformanceToolView: View {
var body: some View {
HStack(spacing: 10) {
Text(viewModel.item.title)
.font(.system(size: 13, weight: .bold))
.font(.body1Bold)

Text(viewModel.value)
.font(.system(size: 13, weight: .regular))
.font(.body1Regular)
.frame(maxWidth: .infinity, alignment: .trailing)
}
.onAppear { viewModel.startTimer() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct OptionToggleView: View {
var body: some View {
Toggle(isOn: $value) {
Text(title)
.font(.system(size: 13, weight: .bold))
.font(.body1Bold)
.frame(maxWidth: .infinity, alignment: .leading)
}
.onChange(of: value) { onValueChanged($0) }
Expand Down
4 changes: 4 additions & 0 deletions Sentinel/Classes/Core/Sentinel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public final class Sentinel {
public func setup(with configuration: Configuration) {
self.configuration = configuration
configuration.trigger?.subscribe {
guard !configuration.sourceScreenProvider.isShown() else {
configuration.sourceScreenProvider.dismiss()
return
}
configuration.sourceScreenProvider.showTools(for: Self.createSentinelView(with: configuration))
}
}
Expand Down
22 changes: 22 additions & 0 deletions Sentinel/Classes/Core/SourceScreenProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public protocol SourceScreenProvider {

/// The view controller used for presenting the Sentinel.
func showTools(for view: some View)

/// Checks if Sentinel is already shown
func isShown() -> Bool

/// Dismisses Sentinel, used if the user triggers the showing of Sentinel but it is already shown
func dismiss()
}

/// Provides possible source screens used for presenting the Sentinel.
Expand All @@ -36,12 +42,28 @@ public struct DefaultSourceScreenProvider: SourceScreenProvider {
controller.view.frame = NSRect(x: 0, y: 0, width: 1200, height: 800)
keyWindow?.contentViewController?.presentAsModalWindow(controller)
}

public func isShown() -> Bool {
NSApplication.shared.windows.compactMap(\.contentViewController).contains(where: { $0 is NSHostingController<SentinelTabBarView> })
}

public func dismiss() {
NSApplication.shared.windows.first(where: { $0.contentViewController is NSHostingController<SentinelTabBarView> })?.close()
}
#else

public func showTools(for view: some View) {
topMostController()?.present(UIHostingController(rootView: view), animated: true)
}

public func isShown() -> Bool {
topMostController() is UIHostingController<SentinelTabBarView>
}

public func dismiss() {
topMostController()?.dismiss(animated: true)
}

// MARK: - Private methods

private func topMostController() -> UIViewController? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ struct NavigationToolTableView: View {
var body: some View {
VStack(spacing: 10) {
Text(value == nil ? title : "\(title): ")
.font(.system(size: 13, weight: .bold))
.font(.body1Bold)
.frame(maxWidth: .infinity, alignment: .leading)
if let value {
Text(value)
.font(.system(size: 13, weight: .bold))
.font(.body1Regular)
.frame(maxWidth: .infinity, alignment: .leading)
.multilineTextAlignment(.leading)
.padding(.trailing, 10)
Expand Down
4 changes: 2 additions & 2 deletions Sentinel/Classes/Core/ToolTableItems/TitleValueView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ struct TitleValueView: View {
var body: some View {
HStack(spacing: 10) {
Text(title)
.font(.system(size: 13, weight: .bold))
.font(.body1Bold)

Text(value)
.font(.system(size: 13, weight: .regular))
.font(.body1Regular)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct CrashDetectionToolDetailsView: View {
List {
Section {
Text("Details")
.font(.headline)
.font(.title1Bold)

ForEach(detailItems, id: \.0) {
CrashToolDetailsRow(title: $0.0, value: $0.1)
Expand All @@ -24,7 +24,7 @@ struct CrashDetectionToolDetailsView: View {

Section {
Text("Stack trace")
.font(.headline)
.font(.title1Bold)

ForEach(crashModel.traces, id: \.title) {
StackTraceView(title: $0.title, description: $0.detail)
Expand All @@ -41,9 +41,9 @@ private struct CrashToolDetailsRow: View {
var body: some View {
HStack(spacing: 0) {
Text(title)
.font(.system(size: 14, weight: .bold))
.font(.body1Bold)
Text(value)
.font(.system(size: 14))
.font(.body1Regular)
.frame(maxWidth: .infinity, alignment: .trailing)
}
}
Expand All @@ -56,10 +56,10 @@ private struct StackTraceView: View {
var body: some View {
VStack(spacing: 4) {
Text(title)
.font(.system(size: 14, weight: .bold))
.font(.body1Bold)
if let description {
Text(description)
.font(.system(size: 11))
.font(.caption1Regular)
}
}
.onTapGesture { }
Expand Down
4 changes: 2 additions & 2 deletions Sentinel/Classes/EmailSender/EmailSenderErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ struct EmailSenderErrorView: View {
var body: some View {
VStack(spacing: 10) {
Text(alertTitle)
.font(.system(size: 17, weight: .bold))
.font(.subtitle1Bold)
.multilineTextAlignment(.center)

Text(alertMessage)
.font(.system(size: 14, weight: .regular))
.font(.body1Regular)
.multilineTextAlignment(.center)
}
.frame(maxHeight: .infinity, alignment: .top)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct UserDefaultsToolDetailView: View {
var body: some View {
VStack(spacing: 10) {
Text(viewModel.title)
.font(.title)
.font(.title1Bold)
.padding(.top, 20)

TextEditor(text: $viewModel.value)
Expand Down