Skip to content

Commit

Permalink
feat: extract subviews on extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-KNIGHT committed May 6, 2024
1 parent f5b4223 commit 8290f37
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 82 deletions.
10 changes: 10 additions & 0 deletions ControlRoom.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
3C09AF722BE8B4E800C303C0 /* SettingsView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C09AF712BE8B4E800C303C0 /* SettingsView+Extension.swift */; };
41C44ACD2616FCB50016B1E4 /* FFMPEGConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41C44ACC2616FCB50016B1E4 /* FFMPEGConverter.swift */; };
510871F225C317830009E39F /* SimulatorAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510871F125C317830009E39F /* SimulatorAction.swift */; };
511BA57D23F3FFEA00E3E660 /* ControlRoomApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 511BA57C23F3FFEA00E3E660 /* ControlRoomApp.swift */; };
Expand Down Expand Up @@ -95,6 +96,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3C09AF712BE8B4E800C303C0 /* SettingsView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsView+Extension.swift"; sourceTree = "<group>"; };
41C44ACC2616FCB50016B1E4 /* FFMPEGConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFMPEGConverter.swift; sourceTree = "<group>"; };
510871F125C317830009E39F /* SimulatorAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorAction.swift; sourceTree = "<group>"; };
511BA57923F3FFEA00E3E660 /* Control Room.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Control Room.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -418,6 +420,7 @@
isa = PBXGroup;
children = (
55AF68B423F9CFD600C5D87A /* SettingsView.swift */,
3C09AF712BE8B4E800C303C0 /* SettingsView+Extension.swift */,
);
path = "Settings UI";
sourceTree = "<group>";
Expand Down Expand Up @@ -642,6 +645,7 @@
551F8CF923F4C45A0006D1BD /* SimulatorSidebarView.swift in Sources */,
54C2092827DBDB6F00E47016 /* DocumentPicker.swift in Sources */,
51203A512A09588A00CBE517 /* Capture.swift in Sources */,
3C09AF722BE8B4E800C303C0 /* SettingsView+Extension.swift in Sources */,
511BA59C23F4172400E3E660 /* SystemView.swift in Sources */,
54C2092D27DBDE7500E47016 /* UTType+Extension.swift in Sources */,
511BA57D23F3FFEA00E3E660 /* ControlRoomApp.swift in Sources */,
Expand Down Expand Up @@ -857,8 +861,11 @@
MARKETING_VERSION = 3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.hackingwithswift.ControlRoom;
PRODUCT_NAME = "Control Room";
SUPPORTED_PLATFORMS = "macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 7;
};
name = Debug;
};
Expand Down Expand Up @@ -890,7 +897,10 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.hackingwithswift.ControlRoom;
PRODUCT_NAME = "Control Room";
SUPPORTED_PLATFORMS = "macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 7;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "69c39523ac0471922b625cc56b8722155cfd2afd660bdd4f5ff67335b5b87714",
"pins" : [
{
"identity" : "keyboardshortcuts",
Expand All @@ -10,5 +11,5 @@
}
}
],
"version" : 2
"version" : 3
}
94 changes: 94 additions & 0 deletions ControlRoom/Settings UI/SettingsView+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// SettingsView+Extension.swift
// ControlRoom
//
// Created by Elliot Knight on 06/05/2024.
// Copyright © 2024 Paul Hudson. All rights reserved.
//

import SwiftUI
import KeyboardShortcuts

// MARK: - Extracted Views

extension SettingsView {
func makeTogglesForm() -> some View {
Form {
Toggle("Keep window on top", isOn: $preferences.wantsFloatingWindow)
Toggle("Show Default simulator", isOn: $preferences.showDefaultSimulator)
Toggle("Show booted devices first", isOn: $preferences.showBootedDevicesFirst)
Toggle("Show icon in menu bar", isOn: $preferences.wantsMenuBarIcon)
}
}

func makeNotificationsForm() -> some View {
Form {
HStack {
Text("Resend last push notification")
KeyboardShortcuts.Recorder(for: .resendLastPushNotification)
}

HStack {
Text("Restart last selected app")
KeyboardShortcuts.Recorder(for: .restartLastSelectedApp)
}

HStack {
Text("Reopen last URL")
KeyboardShortcuts.Recorder(for: .reopenLastURL)
}
}
}

func makePickersForm() -> some View {
Form {
Picker("Screenshot Format:", selection: $captureSettings.imageFormat) {
ForEach(SimCtl.IO.ImageFormat.allCases, id: \.self) { type in
Text(type.rawValue.uppercased()).tag(type)
}
}

Picker("Video Format:", selection: $captureSettings.videoFormat) {
ForEach(SimCtl.IO.VideoFormat.all, id: \.self) { item in
if item == .divider {
Divider()
} else {
Text(item.name).tag(item)
}
}
}

Picker("Display:", selection: $captureSettings.display) {
ForEach(SimCtl.IO.Display.allCases, id: \.self) { display in
Text(display.rawValue.capitalized).tag(display)
}
}

Picker("Mask:", selection: $captureSettings.mask) {
ForEach(SimCtl.IO.Mask.allCases, id: \.self) { mask in
Text(mask.rawValue.capitalized).tag(mask)
}
}
.disabled(renderChrome)

Toggle(isOn: $renderChrome.onChange(updateChromeSettings)) {
VStack(alignment: .leading) {
Text("Add device chrome to screenshots")
Text("This is an experimental feature and may not function properly yet.")
.font(.caption)
}
}
}
}

func makeColorPicker() -> some View {
VStack {
Toggle("Uppercase Hex Strings", isOn: $uppercaseHex)
.padding(.bottom)

Text("Set the maximum number of decimal places to use when generating code for picked simulator colors. The default is 2.")
Stepper("Decimal Places: \(colorPickerAccuracy)", value: $colorPickerAccuracy, in: 0...5)
.pickerStyle(.segmented)
}
}
}
98 changes: 17 additions & 81 deletions ControlRoom/Settings UI/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,95 +28,31 @@ struct SettingsView: View {

var body: some View {
TabView {
Form {
Toggle("Keep window on top", isOn: $preferences.wantsFloatingWindow)
Toggle("Show Default simulator", isOn: $preferences.showDefaultSimulator)
Toggle("Show booted devices first", isOn: $preferences.showBootedDevicesFirst)
Toggle("Show icon in menu bar", isOn: $preferences.wantsMenuBarIcon)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.tabItem {
Label("Window", systemImage: "macwindow")
}

Form {
HStack {
Text("Resend last push notification")
KeyboardShortcuts.Recorder(for: .resendLastPushNotification)
}

HStack {
Text("Restart last selected app")
KeyboardShortcuts.Recorder(for: .restartLastSelectedApp)
}

HStack {
Text("Reopen last URL")
KeyboardShortcuts.Recorder(for: .reopenLastURL)
makeTogglesForm()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.tabItem {
Label("Window", systemImage: "macwindow")
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.tabItem {
Label("Shortcuts", systemImage: "keyboard")
}

Form {
Picker("Screenshot Format:", selection: $captureSettings.imageFormat) {
ForEach(SimCtl.IO.ImageFormat.allCases, id: \.self) { type in
Text(type.rawValue.uppercased()).tag(type)
}
makeNotificationsForm()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.tabItem {
Label("Shortcuts", systemImage: "keyboard")
}

Picker("Video Format:", selection: $captureSettings.videoFormat) {
ForEach(SimCtl.IO.VideoFormat.all, id: \.self) { item in
if item == .divider {
Divider()
} else {
Text(item.name).tag(item)
}
}
makePickersForm()
.padding()
.tabItem {
Label("Screenshots", systemImage: "camera.on.rectangle")
}

Picker("Display:", selection: $captureSettings.display) {
ForEach(SimCtl.IO.Display.allCases, id: \.self) { display in
Text(display.rawValue.capitalized).tag(display)
}
makeColorPicker()
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.tabItem {
Label("Colors", systemImage: "paintpalette")
}

Picker("Mask:", selection: $captureSettings.mask) {
ForEach(SimCtl.IO.Mask.allCases, id: \.self) { mask in
Text(mask.rawValue.capitalized).tag(mask)
}
}
.disabled(renderChrome)

Toggle(isOn: $renderChrome.onChange(updateChromeSettings)) {
VStack(alignment: .leading) {
Text("Add device chrome to screenshots")
Text("This is an experimental feature and may not function properly yet.")
.font(.caption)
}
}
}
.padding()
.tabItem {
Label("Screenshots", systemImage: "camera.on.rectangle")
}

VStack {
Toggle("Uppercase Hex Strings", isOn: $uppercaseHex)
.padding(.bottom)

Text("Set the maximum number of decimal places to use when generating code for picked simulator colors. The default is 2.")
Stepper("Decimal Places: \(colorPickerAccuracy)", value: $colorPickerAccuracy, in: 0...5)
.pickerStyle(.segmented)
}
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.tabItem {
Label("Colors", systemImage: "paintpalette")
}

Form {
TextField(
"Path to Terminal",
Expand Down

0 comments on commit 8290f37

Please sign in to comment.