added backgrounder.swift

more stuff
and stuff

tried to add background location tracking
 - it didnt work
This commit is contained in:
neon443
2025-08-24 20:38:12 +01:00
parent d40ef8e03c
commit a7783eab47
5 changed files with 84 additions and 5 deletions

View File

@@ -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")
}
}

View File

@@ -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")
}

View File

@@ -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)

View File

@@ -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()
}
}
}