Skip to content

Commit 7573ec6

Browse files
committed
add device name settings, add name to filename
1 parent 9b565f6 commit 7573ec6

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

AllSpark-ios/CameraViewController.swift

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ class CameraViewController: UIViewController, UIDocumentPickerDelegate, UINaviga
371371
let fileExtension = formatString == "mov" ? "mov" : "mp4"
372372
let fileType: AVFileType = formatString == "mov" ? .mov : .mp4
373373

374-
let videoName = "recording_\(Date().timeIntervalSince1970).\(fileExtension)"
374+
// Get device name for filename
375+
let deviceName = UserDefaults.standard.string(forKey: "deviceName") ?? UIDevice.current.name
376+
let deviceNameForFilename = formatDeviceNameForFilename(deviceName)
377+
let timestamp = Date().timeIntervalSince1970
378+
let videoName = "recording_\(deviceNameForFilename)_\(timestamp).\(fileExtension)"
375379
videoURL = documentsPath.appendingPathComponent(videoName)
376380

377381
guard let videoURL = videoURL else { return }
@@ -707,16 +711,42 @@ class CameraViewController: UIViewController, UIDocumentPickerDelegate, UINaviga
707711
}
708712
}
709713

714+
// MARK: - Helper Methods
715+
716+
private func formatDeviceNameForFilename(_ name: String) -> String {
717+
// Remove non-ASCII characters
718+
let ascii = name.filter { $0.isASCII }
719+
720+
// Split on non-alphanumeric characters and filter empty components
721+
let components = ascii.components(separatedBy: CharacterSet.alphanumerics.inverted)
722+
.filter { !$0.isEmpty }
723+
724+
// Build title-case: capitalize first letter of each word
725+
guard !components.isEmpty else { return "Device" }
726+
727+
let result = components.map { word in
728+
word.prefix(1).uppercased() + word.dropFirst().lowercased()
729+
}.joined()
730+
731+
return result.isEmpty ? "Device" : result
732+
}
733+
710734
// MARK: - WebSocket Methods
711735

712736
private func getClientDisplayName() -> String {
713737
let deviceName = UIDevice.current.name
738+
let customDeviceName = UserDefaults.standard.string(forKey: "deviceName") ?? deviceName
714739
let customName = UserDefaults.standard.string(forKey: "clientDisplayName")
715740

741+
print("UIDevice.current.name: \(UIDevice.current.name)")
742+
print("Device name: \(deviceName)")
743+
print("Custom device name from settings: \(customDeviceName)")
744+
716745
if let customName = customName, !customName.isEmpty {
717-
return "\(customName) (\(deviceName))"
746+
print("Custom name: \(customName)")
747+
return "\(customName) (\(customDeviceName))"
718748
} else {
719-
return deviceName
749+
return customDeviceName
720750
}
721751
}
722752

AllSpark-ios/SettingsView.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ struct SettingsView: View {
44
@AppStorage("serverHost") private var serverHost: String = "localhost:8080"
55
@AppStorage("videoFormat") private var videoFormat: String = "mp4"
66
@AppStorage("verifyCertificate") private var verifyCertificate: Bool = true
7+
@AppStorage("deviceName") private var deviceName: String = ""
78
@State private var displayText: String = "Ready."
89

10+
init() {
11+
// Set default deviceName from UIDevice if not already set
12+
let defaultName = UIDevice.current.name
13+
if UserDefaults.standard.string(forKey: "deviceName") == nil {
14+
UserDefaults.standard.set(defaultName, forKey: "deviceName")
15+
}
16+
}
17+
918
var body: some View {
1019
VStack(alignment: .center) {
1120
Text("Client Settings")
@@ -14,6 +23,18 @@ struct SettingsView: View {
1423

1524
Spacer()
1625

26+
Text("Device Name")
27+
.font(.headline)
28+
.padding(.top, 10)
29+
30+
TextField("Device Name", text: $deviceName)
31+
.textFieldStyle(RoundedBorderTextFieldStyle())
32+
.frame(maxWidth: 300)
33+
.multilineTextAlignment(.center)
34+
.padding()
35+
.autocapitalization(.words)
36+
.textInputAutocapitalization(.words)
37+
1738
Text("Video Format")
1839
.font(.headline)
1940
.padding(.top, 20)

0 commit comments

Comments
 (0)