mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-15 20:10:30 +00:00
improve the location stuff
This commit is contained in:
parent
b61fecb630
commit
1bdf72ac2f
5 changed files with 25 additions and 8 deletions
|
|
@ -134,9 +134,6 @@ struct HeartbeatApp: App {
|
|||
if UserDefaults.standard.bool(forKey: "keepAliveAudio") {
|
||||
BackgroundAudioManager.shared.start()
|
||||
}
|
||||
if UserDefaults.standard.bool(forKey: "keepAliveLocation") {
|
||||
BackgroundLocationManager.shared.start()
|
||||
}
|
||||
if let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:))),
|
||||
let origMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.init(forOpeningContentTypes:asCopy:))) {
|
||||
method_exchangeImplementations(origMethod, fixMethod)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ final class BackgroundLocationManager: NSObject, CLLocationManagerDelegate {
|
|||
|
||||
private let locationManager = CLLocationManager()
|
||||
private var isRunning = false
|
||||
private var activityCount = 0
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
|
|
@ -39,6 +40,20 @@ final class BackgroundLocationManager: NSObject, CLLocationManagerDelegate {
|
|||
locationManager.stopUpdatingLocation()
|
||||
}
|
||||
|
||||
func requestStart() {
|
||||
activityCount += 1
|
||||
if activityCount == 1, UserDefaults.standard.bool(forKey: "keepAliveLocation") {
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
func requestStop() {
|
||||
activityCount = max(activityCount - 1, 0)
|
||||
if activityCount == 0 {
|
||||
stop()
|
||||
}
|
||||
}
|
||||
|
||||
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
||||
guard isRunning else { return }
|
||||
switch manager.authorizationStatus {
|
||||
|
|
|
|||
|
|
@ -449,6 +449,7 @@ struct HomeView: View {
|
|||
private func startJITInBackground(bundleID: String? = nil, pid: Int? = nil, scriptData: Data? = nil, scriptName: String? = nil, triggeredByURLScheme: Bool = false) {
|
||||
isProcessing = true
|
||||
LogManager.shared.addInfoLog("Starting Debug for \(bundleID ?? String(pid ?? 0))")
|
||||
BackgroundLocationManager.shared.requestStart()
|
||||
|
||||
if triggeredByURLScheme {
|
||||
pubHeartBeat = false
|
||||
|
|
@ -463,6 +464,7 @@ struct HomeView: View {
|
|||
let finishProcessing = {
|
||||
DispatchQueue.main.async {
|
||||
isProcessing = false
|
||||
BackgroundLocationManager.shared.requestStop()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,6 +195,9 @@ struct LocationSimulationView: View {
|
|||
}
|
||||
.onDisappear {
|
||||
stopResendLoop()
|
||||
if backgroundTaskID != .invalid {
|
||||
BackgroundLocationManager.shared.requestStop()
|
||||
}
|
||||
endBackgroundTask()
|
||||
}
|
||||
}
|
||||
|
|
@ -225,6 +228,7 @@ struct LocationSimulationView: View {
|
|||
if code == 0 {
|
||||
beginBackgroundTask()
|
||||
startResendLoop()
|
||||
BackgroundLocationManager.shared.requestStart()
|
||||
} else {
|
||||
alertTitle = "Simulation Failed"
|
||||
alertMessage = "Could not simulate location (error \(code)). Make sure the device is connected and the DDI is mounted."
|
||||
|
|
@ -245,6 +249,7 @@ struct LocationSimulationView: View {
|
|||
if code == 0 {
|
||||
coordinate = nil
|
||||
endBackgroundTask()
|
||||
BackgroundLocationManager.shared.requestStop()
|
||||
} else {
|
||||
alertTitle = "Clear Failed"
|
||||
alertMessage = "Could not clear simulated location (error \(code))."
|
||||
|
|
|
|||
|
|
@ -117,18 +117,16 @@ struct SettingsView: View {
|
|||
Toggle(isOn: $keepAliveLocation) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Background Location")
|
||||
Text("Uses low-accuracy location to stay alive even when another app plays audio.")
|
||||
Text("Uses low-accuracy location to stay alive when an activity needs it.")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.onChange(of: keepAliveLocation) { _, enabled in
|
||||
if enabled { BackgroundLocationManager.shared.start() }
|
||||
else { BackgroundLocationManager.shared.stop() }
|
||||
if !enabled { BackgroundLocationManager.shared.stop() }
|
||||
}
|
||||
|
||||
} header: {
|
||||
Text("Background Keep-Alive")
|
||||
} footer: {
|
||||
Text("For Background Location to work reliably, go to **Settings → Privacy & Security → Location Services → StikDebug** and select **Always**.")
|
||||
}
|
||||
|
||||
// 6) Behavior
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue