frenzy-ios/Reader/UserActivities.swift

60 lines
1.8 KiB
Swift

//
// UserActivities.swift
// Reader
//
// Created by Shadowfacts on 1/15/22.
//
import Foundation
extension NSUserActivity {
static let preferencesType = "net.shadowfacts.Reader.activity.preferences"
static let addAccountType = "net.shadowfacts.Reader.activity.add-account"
static let activateAccountType = "net.shadowfacts.Reader.activity.activate-account"
static let readUnreadType = "net.shadowfacts.Reader.activity.read-unread"
static let readAllType = "net.shadowfacts.Reader.activity.read-all"
func accountID() -> Data? {
if [NSUserActivity.addAccountType].contains(self.activityType),
let id = self.userInfo?["accountID"] as? Data {
return id
} else {
return nil
}
}
static func preferences() -> NSUserActivity {
return NSUserActivity(activityType: preferencesType)
}
static func addAccount() -> NSUserActivity {
return NSUserActivity(activityType: addAccountType)
}
static func activateAccount(_ account: LocalData.Account) -> NSUserActivity {
let activity = NSUserActivity(activityType: activateAccountType)
activity.userInfo = [
"accountID": account.id,
]
return activity
}
static func readUnread() -> NSUserActivity {
let activity = NSUserActivity(activityType: readUnreadType)
activity.isEligibleForHandoff = true
activity.isEligibleForPrediction = true
activity.title = "Show unread articles"
return activity
}
static func readAll() -> NSUserActivity {
let activity = NSUserActivity(activityType: readAllType)
activity.isEligibleForHandoff = true
activity.isEligibleForPrediction = true
activity.title = "Show all articles"
return activity
}
}