Broken scene activation conditions stuff

This commit is contained in:
Shadowfacts 2022-03-07 23:06:05 -05:00
parent 2f6d0ae07c
commit 9d22d4ef35
3 changed files with 31 additions and 5 deletions

View File

@ -49,6 +49,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
if let activity = activity { if let activity = activity {
setupUI(from: activity) setupUI(from: activity)
} }
setupSceneActivationConditions()
} }
} else { } else {
createLoginUI() createLoginUI()
@ -136,6 +137,17 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window!.rootViewController = AppSplitViewController(fervorController: fervorController) window!.rootViewController = AppSplitViewController(fervorController: fervorController)
} }
private func setupSceneActivationConditions() {
guard let account = fervorController?.account else {
return
}
let scene = self.window!.windowScene!
// todo: why the fuck doesn't this work
// it always picks the most recently focused window
scene.activationConditions.prefersToActivateForTargetContentIdentifierPredicate = NSPredicate(format: "self == '\(account.id.base64EncodedString())'")
scene.activationConditions.canActivateForTargetContentIdentifierPredicate = NSPredicate(value: false)
}
private func syncFromServer() { private func syncFromServer() {
guard let fervorController = fervorController else { guard let fervorController = fervorController else {
return return
@ -179,6 +191,7 @@ extension SceneDelegate: LoginViewControllerDelegate {
createAppUI() createAppUI()
syncFromServer() syncFromServer()
setupSceneActivationConditions()
UIMenuSystem.main.setNeedsRebuild() UIMenuSystem.main.setNeedsRebuild()
} }

View File

@ -204,9 +204,9 @@ class HomeViewController: UIViewController {
vc.delegate = itemsDelegate vc.delegate = itemsDelegate
switch item { switch item {
case .all: case .all:
vc.userActivity = .readAll() vc.userActivity = .readAll(account: fervorController.account!)
case .unread: case .unread:
vc.userActivity = .readUnread() vc.userActivity = .readUnread(account: fervorController.account!)
case .group(let group): case .group(let group):
break break
case .feed(let feed): case .feed(let feed):

View File

@ -16,7 +16,12 @@ extension NSUserActivity {
static let readAllType = "net.shadowfacts.Reader.activity.read-all" static let readAllType = "net.shadowfacts.Reader.activity.read-all"
func accountID() -> Data? { func accountID() -> Data? {
if [NSUserActivity.addAccountType].contains(self.activityType), let types = [
NSUserActivity.activateAccountType,
NSUserActivity.readUnreadType,
NSUserActivity.readAllType,
]
if types.contains(self.activityType),
let id = self.userInfo?["accountID"] as? Data { let id = self.userInfo?["accountID"] as? Data {
return id return id
} else { } else {
@ -40,19 +45,27 @@ extension NSUserActivity {
return activity return activity
} }
static func readUnread() -> NSUserActivity { static func readUnread(account: LocalData.Account) -> NSUserActivity {
let activity = NSUserActivity(activityType: readUnreadType) let activity = NSUserActivity(activityType: readUnreadType)
activity.isEligibleForHandoff = true activity.isEligibleForHandoff = true
activity.isEligibleForPrediction = true activity.isEligibleForPrediction = true
activity.title = "Show unread articles" activity.title = "Show unread articles"
activity.userInfo = [
"accountID": account.id
]
activity.targetContentIdentifier = account.id.base64EncodedString()
return activity return activity
} }
static func readAll() -> NSUserActivity { static func readAll(account: LocalData.Account) -> NSUserActivity {
let activity = NSUserActivity(activityType: readAllType) let activity = NSUserActivity(activityType: readAllType)
activity.isEligibleForHandoff = true activity.isEligibleForHandoff = true
activity.isEligibleForPrediction = true activity.isEligibleForPrediction = true
activity.title = "Show all articles" activity.title = "Show all articles"
activity.userInfo = [
"accountID": account.id
]
activity.targetContentIdentifier = account.id.base64EncodedString()
return activity return activity
} }