From 0e2d9017c6fdc2da383472b9d46559dd6dd3b838 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sun, 10 Aug 2025 18:48:48 +0545 Subject: [PATCH] Move pause media feature inside an experimental section --- VoiceInk/Services/ImportExportService.swift | 10 +++- .../ExperimentalFeaturesSection.swift | 52 +++++++++++++++++++ VoiceInk/Views/Settings/SettingsView.swift | 9 +--- 3 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 VoiceInk/Views/Settings/ExperimentalFeaturesSection.swift diff --git a/VoiceInk/Services/ImportExportService.swift b/VoiceInk/Services/ImportExportService.swift index 7a9a253..036ec88 100644 --- a/VoiceInk/Services/ImportExportService.swift +++ b/VoiceInk/Services/ImportExportService.swift @@ -21,6 +21,7 @@ struct GeneralSettings: Codable { let isSystemMuteEnabled: Bool? let isPauseMediaEnabled: Bool? let isTextFormattingEnabled: Bool? + let isExperimentalFeaturesEnabled: Bool? } struct VoiceInkExportedSettings: Codable { @@ -96,7 +97,8 @@ class ImportExportService { isSoundFeedbackEnabled: soundManager.isEnabled, isSystemMuteEnabled: mediaController.isSystemMuteEnabled, isPauseMediaEnabled: playbackController.isPauseMediaEnabled, - isTextFormattingEnabled: UserDefaults.standard.object(forKey: keyIsTextFormattingEnabled) as? Bool ?? true + isTextFormattingEnabled: UserDefaults.standard.object(forKey: keyIsTextFormattingEnabled) as? Bool ?? true, + isExperimentalFeaturesEnabled: UserDefaults.standard.bool(forKey: "isExperimentalFeaturesEnabled") ) let exportedSettings = VoiceInkExportedSettings( @@ -252,6 +254,12 @@ class ImportExportService { if let pauseMedia = general.isPauseMediaEnabled { playbackController.isPauseMediaEnabled = pauseMedia } + if let experimentalEnabled = general.isExperimentalFeaturesEnabled { + UserDefaults.standard.set(experimentalEnabled, forKey: "isExperimentalFeaturesEnabled") + if experimentalEnabled == false { + playbackController.isPauseMediaEnabled = false + } + } if let textFormattingEnabled = general.isTextFormattingEnabled { UserDefaults.standard.set(textFormattingEnabled, forKey: self.keyIsTextFormattingEnabled) } diff --git a/VoiceInk/Views/Settings/ExperimentalFeaturesSection.swift b/VoiceInk/Views/Settings/ExperimentalFeaturesSection.swift new file mode 100644 index 0000000..86bde1a --- /dev/null +++ b/VoiceInk/Views/Settings/ExperimentalFeaturesSection.swift @@ -0,0 +1,52 @@ +import SwiftUI + +struct ExperimentalFeaturesSection: View { + @AppStorage("isExperimentalFeaturesEnabled") private var isExperimentalFeaturesEnabled = false + @ObservedObject private var playbackController = PlaybackController.shared + + var body: some View { + VStack(alignment: .leading, spacing: 12) { + HStack(spacing: 12) { + Image(systemName: "flask") + .font(.system(size: 20)) + .foregroundColor(.accentColor) + .frame(width: 24, height: 24) + + VStack(alignment: .leading, spacing: 2) { + Text("Experimental Features") + .font(.headline) + Text("Experimental features that might be unstable & bit buggy.") + .font(.subheadline) + .foregroundColor(.secondary) + } + + Spacer() + + Toggle("Experimental Features", isOn: $isExperimentalFeaturesEnabled) + .labelsHidden() + .toggleStyle(.switch) + .onChange(of: isExperimentalFeaturesEnabled) { _, newValue in + if !newValue { + playbackController.isPauseMediaEnabled = false + } + } + } + + Divider() + .padding(.vertical, 4) + + if isExperimentalFeaturesEnabled { + Toggle(isOn: $playbackController.isPauseMediaEnabled) { + Text("Pause Media on Playback") + } + .toggleStyle(.switch) + .help("Automatically pause active media playback during recordings and resume afterward.") + } + } + .padding(16) + .frame(maxWidth: .infinity, alignment: .leading) + .background(CardBackground(isSelected: false, useAccentGradientWhenSelected: true)) + } +} + + diff --git a/VoiceInk/Views/Settings/SettingsView.swift b/VoiceInk/Views/Settings/SettingsView.swift index ac4aafc..6528cd1 100644 --- a/VoiceInk/Views/Settings/SettingsView.swift +++ b/VoiceInk/Views/Settings/SettingsView.swift @@ -137,16 +137,11 @@ struct SettingsView: View { .toggleStyle(.switch) .help("Automatically mute system audio when recording starts and restore when recording stops") - Toggle(isOn: $playbackController.isPauseMediaEnabled) { - Text("Pause media during recording (Experimental)") - } - .toggleStyle(.switch) - .help("Automatically pause active media playback when recording starts and resume when recording stops. This feature is experimental and may occasionally cause unexpected behavior.") - - } } + ExperimentalFeaturesSection() + SettingsSection( icon: "rectangle.on.rectangle", title: "Recorder Style",