Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions Sources/ResizeDevice/AppOpener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,43 @@ public final class AppOpener: @unchecked Sendable {
// back to the front every second for ten minutes.
var taken = false
while Date() < deadline {
Thread.sleep(forTimeInterval: 1)
// A device still on its lock screen starts the app's process without showing
// the app: where the app says when it is there, only that counts.
if let opened {
if opened() {
log("App opener: the app has connected")
return
let done: Bool = autoreleasepool {
Thread.sleep(forTimeInterval: 1)
// A device still on its lock screen starts the app's process without showing
// the app: where the app says when it is there, only that counts.
if let opened {
if opened() {
log("App opener: the app has connected")
return true
}
} else if raf_process_running(executableName) == 1 {
log("App opener: the app is running")
return true
}
} else if raf_process_running(executableName) == 1 {
log("App opener: the app is running")
return
}
guard installed(identifier) else {
if registerWithUICache, Date().timeIntervalSince(lastRegister) > 3,
FileManager.default.isExecutableFile(atPath: appPath + "/" + executableName) {
lastRegister = Date()
log("App opener: registering the app, uicache exit \(spawn([Self.uicache, "-p", appPath]))")
guard installed(identifier) else {
if registerWithUICache, Date().timeIntervalSince(lastRegister) > 3,
FileManager.default.isExecutableFile(atPath: appPath + "/" + executableName) {
lastRegister = Date()
log("App opener: registering the app, uicache exit \(spawn([Self.uicache, "-p", appPath]))")
}
return false
}
continue
}
let viaLaunchServices = open(identifier)
let viaSpringBoard = viaLaunchServices ? 0 : springBoardLaunch(identifier)
if !taken, viaLaunchServices || viaSpringBoard == 0 {
taken = true
deadline = min(deadline, Date().addingTimeInterval(Self.afterTaken))
}
// A locked device refuses every attempt (Berkay saw SpringBoard 3) until it is unlocked:
// log the outcome when it changes, not every second.
let outcome = "LaunchServices \(viaLaunchServices), SpringBoard \(viaSpringBoard)"
if outcome != lastOutcome {
log("App opener: opening the app, \(outcome); retrying every second until the app runs")
lastOutcome = outcome
let viaLaunchServices = open(identifier)
let viaSpringBoard = viaLaunchServices ? 0 : springBoardLaunch(identifier)
if !taken, viaLaunchServices || viaSpringBoard == 0 {
taken = true
deadline = min(deadline, Date().addingTimeInterval(Self.afterTaken))
}
// A locked device refuses every attempt (Berkay saw SpringBoard 3) until it is unlocked:
// log the outcome when it changes, not every second.
let outcome = "LaunchServices \(viaLaunchServices), SpringBoard \(viaSpringBoard)"
if outcome != lastOutcome {
log("App opener: opening the app, \(outcome); retrying every second until the app runs")
lastOutcome = outcome
}
return false
}
if done { return }
}
log(taken ? "App opener: done; the app is the user's to close" : "App opener: gave up; the app stays on the Home Screen")
}
Expand Down
Loading
Loading