2022-01-15 19:09:30 +00:00
|
|
|
//
|
|
|
|
// UserActivities.swift
|
|
|
|
// Reader
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 1/15/22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension NSUserActivity {
|
|
|
|
|
2022-01-16 16:58:28 +00:00
|
|
|
static let preferencesType = "net.shadowfacts.Reader.activity.preferences"
|
2022-01-15 19:09:30 +00:00
|
|
|
static let addAccountType = "net.shadowfacts.Reader.activity.add-account"
|
|
|
|
static let activateAccountType = "net.shadowfacts.Reader.activity.activate-account"
|
2022-03-08 02:54:41 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-01-15 19:09:30 +00:00
|
|
|
|
2022-01-16 16:58:28 +00:00
|
|
|
static func preferences() -> NSUserActivity {
|
|
|
|
return NSUserActivity(activityType: preferencesType)
|
|
|
|
}
|
|
|
|
|
2022-01-15 19:09:30 +00:00
|
|
|
static func addAccount() -> NSUserActivity {
|
|
|
|
return NSUserActivity(activityType: addAccountType)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func activateAccount(_ account: LocalData.Account) -> NSUserActivity {
|
|
|
|
let activity = NSUserActivity(activityType: activateAccountType)
|
|
|
|
activity.userInfo = [
|
2022-03-08 02:54:41 +00:00
|
|
|
"accountID": account.id,
|
2022-01-15 19:09:30 +00:00
|
|
|
]
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
2022-03-08 02:54:41 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-15 19:09:30 +00:00
|
|
|
}
|