Skip to content

Commit

Permalink
[app] General settings cleanup and tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Nov 20, 2021
1 parent 181b28d commit 84f14ca
Show file tree
Hide file tree
Showing 29 changed files with 581 additions and 411 deletions.
2 changes: 1 addition & 1 deletion App/Controllers/SettingsSceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ extension SettingsSceneDelegate: NSToolbarDelegate {
}

@objc private func selectPerformanceTab() {
switchTab(rootView: SettingsPerformanceView(), size: CGSize(width: 600, height: 350))
switchTab(rootView: SettingsPerformanceView(), size: CGSize(width: 600, height: 500))
}

}
Expand Down
10 changes: 10 additions & 0 deletions App/Supporting Files/BridgingHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
//

@import NewTermCommon;

#import <TargetConditionals.h>

#if TARGET_OS_MACCATALYST
@import IOKit;

extern CFTypeRef IOPSCopyPowerSourcesInfo(void);
extern CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
extern CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
#endif
2 changes: 2 additions & 0 deletions App/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@
<string>Dark</string>
<key>CADisableMinimumFrameDuration</key>
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>
73 changes: 30 additions & 43 deletions App/UI/Settings/Mac/SettingsGeneralView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,42 @@ struct SettingsGeneralView: View {
@State private var syncPathBrowsePresented = false

var body: some View {
return ScrollView {
VStack(alignment: .leading, spacing: 10) {
GroupBox(label: Text("Bell")) {
VStack(alignment: .leading) {
Toggle("Make beep sound", isOn: preferences.$bellSound)
Toggle("Show heads-up display", isOn: preferences.$bellHUD)
}
.padding(10)
}

FooterText(text: Text("When a terminal application needs to notify you of something, it rings the bell."))
PreferencesList {
PreferencesGroup(
header: Text("Bell"),
footer: Text("When a terminal application needs to notify you of something, it rings the bell.")
) {
Toggle("Make beep sound", isOn: preferences.$bellSound)
Toggle("Show heads-up display", isOn: preferences.$bellHUD)
}

GroupBox(label: Text("Settings Sync")) {
VStack(alignment: .leading) {
Picker("Sync app settings:", selection: preferences.$preferencesSyncService) {
Text("Don’t sync")
.tag(PreferencesSyncService.none)
Text("via iCloud")
.tag(PreferencesSyncService.icloud)
Text("via custom folder")
.tag(PreferencesSyncService.folder)
}
.pickerStyle(InlinePickerStyle())
PreferencesGroup(
header: Text("Settings Sync"),
footer: Text("Keep your NewTerm settings in sync between your Mac, iPhone, and iPad by selecting iCloud sync. If you just want to keep a backup with a service such as Dropbox, select custom folder sync.")
) {
Picker("Sync app settings:", selection: preferences.$preferencesSyncService) {
Text("Don’t sync")
.tag(PreferencesSyncService.none)
Text("via iCloud")
.tag(PreferencesSyncService.icloud)
Text("via custom folder")
.tag(PreferencesSyncService.folder)
}

HStack {
TextField("Sync path:",
text: Binding(
get: { preferences.preferencesSyncPath ?? "" },
set: { value in preferences.preferencesSyncPath = value }
)
)
Button("Browse") {
syncPathBrowsePresented.toggle()
}
.fileImporter(isPresented: $syncPathBrowsePresented,
allowedContentTypes: [.folder]) { result in
preferences.preferencesSyncPath = (try? result.get())?.path
}
}
.disabled(preferences.preferencesSyncService != .folder)
HStack {
TextField("Sync path:", text: preferences.$preferencesSyncPath)
Button("Browse") {
syncPathBrowsePresented.toggle()
}
.fileImporter(isPresented: $syncPathBrowsePresented,
allowedContentTypes: [.folder]) { result in
preferences.preferencesSyncPath = (try? result.get())?.path ?? ""
}
.padding(10)
}

FooterText(text: Text("Keep your NewTerm settings in sync between your Mac, iPhone, and iPad by selecting iCloud sync. If you just want to keep a backup with a service such as Dropbox, select custom folder sync."))
.disabled(preferences.preferencesSyncService != .folder)
}
.padding(20)
}
.navigationBarTitle("General", displayMode: .inline)
.navigationBarTitle("General")
}

}
Expand Down
23 changes: 11 additions & 12 deletions App/UI/Settings/Mac/SettingsInterfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,22 @@ struct SettingsInterfaceView: View {
}
.padding([.leading, .trailing], 7)
)
.padding([.top, .leading, .trailing], 1 / UIScreen.main.scale)
Divider()
.padding([.leading, .trailing], 1 / UIScreen.main.scale)
TerminalSampleViewRepresentable(
fontMetrics: preferences.fontMetrics,
colorMap: preferences.colorMap
)
}
.frame(width: 320)
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
.clipShape(RoundedRectangle(cornerRadius: 9, style: .continuous))
.overlay(
RoundedRectangle(cornerRadius: 8, style: .continuous)
.stroke(Color(UIColor.tertiarySystemBackground), lineWidth: 1 / UIScreen.main.scale)
.strokeBorder(Color(UIColor.tertiarySystemBackground), lineWidth: 1 / UIScreen.main.scale)
.foregroundColor(.clear)
)
.padding([.top, .bottom, .leading], 20)

let themes = Picker("Theme", selection: preferences.$themeName) {
ForEach(sortedThemes, id: \.key) { key, value in
Expand Down Expand Up @@ -90,7 +93,6 @@ struct SettingsInterfaceView: View {
)
}
}
.pickerStyle(InlinePickerStyle())

let fontSize = TextField(
"Font Size",
Expand All @@ -111,18 +113,15 @@ struct SettingsInterfaceView: View {
)
.keyboardType(.decimalPad)

return HStack(spacing: 20) {
return HStack(spacing: 0) {
sampleView
ScrollView {
VStack(alignment: .leading, spacing: 10) {
Text("Note: You currently need to restart the app to have theme updates apply.")
themes
fonts
fontSize
}
PreferencesList {
Text("Note: You currently need to restart the app to have theme updates apply.")
themes
fonts
fontSize
}
}
.padding(20)
.navigationBarTitle("Interface", displayMode: .inline)
}

Expand Down
68 changes: 68 additions & 0 deletions App/UI/Settings/PreferencesGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// PreferencesGroup.swift
// NewTerm (iOS)
//
// Created by Adam Demasi on 25/9/21.
//

import SwiftUI

struct PreferencesGroup<Header: View, Footer: View, Content: View>: View {

var header: Header
var footer: Footer
var content: Content

init(header: Header, footer: Footer, @ViewBuilder content: () -> Content) {
self.header = header
self.footer = footer
self.content = content()
}

var body: some View {
#if targetEnvironment(macCatalyst)
VStack(alignment: .leading, spacing: 6) {
GroupBox(label: header) {
VStack(alignment: .leading, spacing: 0) {
content
.padding([.leading, .trailing], 6)
.padding([.top, .bottom], 4)
.frame(maxWidth: .infinity, minHeight: 0, alignment: .leading)
}
}
footer
.font(.caption)
.padding([.leading, .trailing], 10)
.foregroundColor(.secondary)
}
.pickerStyle(InlinePickerStyle())
#else
Section(
header: header,
footer: footer
) {
content
}
.pickerStyle(InlinePickerStyle())
#endif
}

}

extension PreferencesGroup where Header == EmptyView, Footer: View, Content: View {
init(footer: Footer, @ViewBuilder content: () -> Content) {
self.init(header: EmptyView(), footer: footer, content: content)
}
}

extension PreferencesGroup where Header: View, Footer == EmptyView, Content: View {
init(header: Header, @ViewBuilder content: () -> Content) {
self.init(header: header, footer: EmptyView(), content: content)
}
}

extension PreferencesGroup where Header == EmptyView, Footer == EmptyView, Content: View {
init(@ViewBuilder content: () -> Content) {
self.init(header: EmptyView(), footer: EmptyView(), content: content)
}
}
37 changes: 37 additions & 0 deletions App/UI/Settings/PreferencesList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// PreferencesList.swift
// NewTerm (iOS)
//
// Created by Adam Demasi on 25/9/21.
//

import SwiftUI

struct PreferencesList<Content: View>: View {

var content: Content

init(@ViewBuilder content: () -> Content) {
self.content = content()
}

var body: some View {
#if targetEnvironment(macCatalyst)
ScrollView {
VStack(alignment: .leading, spacing: 10) {
content
}
.padding([.top, .bottom], 16)
.padding([.leading, .trailing], 20)
}
.navigationBarTitleDisplayMode(.inline)
#else
List {
content
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitleDisplayMode(.inline)
#endif
}

}
Loading

0 comments on commit 84f14ca

Please sign in to comment.