From a7783eab471c5a9524df6dc027a7ecaf38be8299 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Sun, 24 Aug 2025 20:38:12 +0100 Subject: [PATCH] added backgrounder.swift more stuff and stuff tried to add background location tracking - it didnt work --- ShhShell.xcodeproj/project.pbxproj | 12 +++++ ShhShell/Misc/Backgrounder.swift | 58 ++++++++++++++++++++++ ShhShell/Views/Hosts/ConnectionView.swift | 2 - ShhShell/Views/Settings/SettingsView.swift | 11 ++-- ShhShell/Views/Terminal/ShellTabView.swift | 6 +++ 5 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 ShhShell/Misc/Backgrounder.swift diff --git a/ShhShell.xcodeproj/project.pbxproj b/ShhShell.xcodeproj/project.pbxproj index b0ec747..d180d69 100644 --- a/ShhShell.xcodeproj/project.pbxproj +++ b/ShhShell.xcodeproj/project.pbxproj @@ -42,6 +42,7 @@ A9485C732E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = A9485C6F2E1AECD000209824 /* JetBrainsMonoNerdFontMono-BoldItalic.ttf */; }; A9485C762E1AF59F00209824 /* FontManagerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9485C752E1AF59F00209824 /* FontManagerView.swift */; }; A9485C782E1BFA5000209824 /* ThemeEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9485C772E1BFA5000209824 /* ThemeEditorView.swift */; }; + A94B832F2E5B929C00EBA09C /* Backgrounder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A94B832E2E5B929C00EBA09C /* Backgrounder.swift */; }; A95FAA472DF3884B00DE2F5A /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = A95FAA462DF3884B00DE2F5A /* Config.xcconfig */; }; A95FAA542DF4B62900DE2F5A /* LibSSH.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */; }; A95FAA552DF4B62900DE2F5A /* LibSSH.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -178,6 +179,7 @@ A9485C702E1AECD000209824 /* JetBrainsMonoNerdFontMono-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMonoNerdFontMono-Italic.ttf"; sourceTree = ""; }; A9485C752E1AF59F00209824 /* FontManagerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontManagerView.swift; sourceTree = ""; }; A9485C772E1BFA5000209824 /* ThemeEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeEditorView.swift; sourceTree = ""; }; + A94B832E2E5B929C00EBA09C /* Backgrounder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Backgrounder.swift; sourceTree = ""; }; A95FAA462DF3884B00DE2F5A /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = SOURCE_ROOT; }; A95FAA502DF4B62100DE2F5A /* LibSSH.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = LibSSH.xcframework; path = Frameworks/LibSSH.xcframework; sourceTree = ""; }; A95FAA512DF4B62100DE2F5A /* openssl.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = openssl.xcframework; path = Frameworks/openssl.xcframework; sourceTree = ""; }; @@ -593,6 +595,7 @@ children = ( A9C060EA2E357FD300CA9374 /* Haptics.swift */, A90B38332E3EA046002B56FC /* Bundle.swift */, + A94B832E2E5B929C00EBA09C /* Backgrounder.swift */, ); path = Misc; sourceTree = ""; @@ -869,6 +872,7 @@ A923172D2E07138000ECE1E6 /* SSHTerminalDelegate.swift in Sources */, A90936882E1AC51100856059 /* Fonts.swift in Sources */, A9FD37552E143D23005319A8 /* SecKeyConvertible.swift in Sources */, + A94B832F2E5B929C00EBA09C /* Backgrounder.swift in Sources */, A96C6AFE2E0C43B600F377FE /* Keypair.swift in Sources */, A90B38322E3E8FC9002B56FC /* AboutView.swift in Sources */, A9C4140C2E096DB7005E3047 /* SSHError.swift in Sources */, @@ -1052,6 +1056,10 @@ INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO; INFOPLIST_KEY_NSFaceIDUsageDescription = "ShhShell uses Face ID to verify your identity"; INFOPLIST_KEY_NSLocalNetworkUsageDescription = "Needed to communicate with SSH Servers"; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "Required to keep SSH connections alive, if enabled"; + INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "Required to keep SSH connections alive, if enabled"; + INFOPLIST_KEY_NSLocationUsageDescription = "Required to keep SSH connections alive, if enabled"; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Required to keep SSH connections alive, if enabled"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -1092,6 +1100,10 @@ INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO; INFOPLIST_KEY_NSFaceIDUsageDescription = "ShhShell uses Face ID to verify your identity"; INFOPLIST_KEY_NSLocalNetworkUsageDescription = "Needed to communicate with SSH Servers"; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "Required to keep SSH connections alive, if enabled"; + INFOPLIST_KEY_NSLocationAlwaysUsageDescription = "Required to keep SSH connections alive, if enabled"; + INFOPLIST_KEY_NSLocationUsageDescription = "Required to keep SSH connections alive, if enabled"; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Required to keep SSH connections alive, if enabled"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; diff --git a/ShhShell/Misc/Backgrounder.swift b/ShhShell/Misc/Backgrounder.swift new file mode 100644 index 0000000..e6161b4 --- /dev/null +++ b/ShhShell/Misc/Backgrounder.swift @@ -0,0 +1,58 @@ +// +// Backgrounder.swift +// ShhShell +// +// Created by neon443 on 24/08/2025. +// + +import Foundation +import CoreLocation + +class Backgrounder: NSObject, CLLocationManagerDelegate, ObservableObject { + private let manager = CLLocationManager() + + @MainActor + static var shared: Backgrounder = Backgrounder() + + override init() { + super.init() + manager.delegate = self + if checkPermsStatus() { + manager.allowsBackgroundLocationUpdates = true + } + } + + func startBgTracking() { + manager.allowsBackgroundLocationUpdates = true + manager.pausesLocationUpdatesAutomatically = false + manager.startMonitoringSignificantLocationChanges() + print("started tgracking") + } + + func stopBgTracking() { + manager.stopUpdatingLocation() + manager.allowsBackgroundLocationUpdates = false + print("stopped tracking") + } + + func requestPerms() { + manager.requestAlwaysAuthorization() + } + + func checkPermsStatus() -> Bool { + let status = manager.authorizationStatus + + switch status { + case .authorized, .notDetermined, .restricted, .denied, .authorizedWhenInUse: + return false + case .authorizedAlways: + return true + default: + return false + } + } + + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + print("tracking started yay") + } +} diff --git a/ShhShell/Views/Hosts/ConnectionView.swift b/ShhShell/Views/Hosts/ConnectionView.swift index e463790..c9066eb 100644 --- a/ShhShell/Views/Hosts/ConnectionView.swift +++ b/ShhShell/Views/Hosts/ConnectionView.swift @@ -101,8 +101,6 @@ struct ConnectionView: View { Button(role: .destructive) { handler.host.key = handler.getHostkey() handler.disconnect() -// handler.go() -// showTerminal = checkShell(handler.state) } label: { Text("Accept Hostkey") } diff --git a/ShhShell/Views/Settings/SettingsView.swift b/ShhShell/Views/Settings/SettingsView.swift index 85b556c..c3a6133 100644 --- a/ShhShell/Views/Settings/SettingsView.swift +++ b/ShhShell/Views/Settings/SettingsView.swift @@ -48,8 +48,8 @@ struct SettingsView: View { } Slider( value: $hostsManager.settings.scrollback, - in: 100...10_000, - step: 100 + in: 250...10_000, + step: 250 ) } } @@ -77,7 +77,7 @@ struct SettingsView: View { .frame(width: 4, height: 40) case .underline: Rectangle() - .frame(width: 25, height: 4) + .frame(width: 20, height: 4) .padding(.top, 36) } } @@ -111,6 +111,11 @@ struct SettingsView: View { } Toggle("location persistence", systemImage: "location.fill", isOn: $hostsManager.settings.locationPersist) + .onChange(of: hostsManager.settings.locationPersist) { _ in + if hostsManager.settings.locationPersist && !Backgrounder.shared.checkPermsStatus() { + Backgrounder.shared.requestPerms() + } + } Toggle("bell sound", systemImage: "bell.and.waves.left.and.right", isOn: $hostsManager.settings.bellSound) Toggle("bell haptic",systemImage: "iphone.radiowaves.left.and.right", isOn: $hostsManager.settings.bellHaptic) diff --git a/ShhShell/Views/Terminal/ShellTabView.swift b/ShhShell/Views/Terminal/ShellTabView.swift index fd44d78..5b57c32 100644 --- a/ShhShell/Views/Terminal/ShellTabView.swift +++ b/ShhShell/Views/Terminal/ShellTabView.swift @@ -151,6 +151,9 @@ struct ShellTabView: View { .frame(height: 30) .onDisappear { UIApplication.shared.isIdleTimerDisabled = false + if container.sessions.isEmpty { + Backgrounder.shared.stopBgTracking() + } } .onAppear { if selectedID == nil { @@ -161,6 +164,9 @@ struct ShellTabView: View { } } UIApplication.shared.isIdleTimerDisabled = hostsManager.settings.caffeinate + if hostsManager.settings.locationPersist { + Backgrounder.shared.startBgTracking() + } } }