2019-04-30 12:58:06 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-04 11:15:29 +00:00
|
|
|
// Copyright © 2018-2020 WireGuard LLC. All Rights Reserved.
|
2019-04-30 12:58:06 +00:00
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class QuickActionItem: UIApplicationShortcutItem {
|
|
|
|
static let type = "WireGuardTunnelActivateAndShow"
|
|
|
|
|
|
|
|
init(tunnelName: String) {
|
|
|
|
super.init(type: QuickActionItem.type, localizedTitle: tunnelName, localizedSubtitle: nil, icon: nil, userInfo: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func createItems(allTunnelNames: [String]) -> [QuickActionItem] {
|
|
|
|
let numberOfItems = 10
|
|
|
|
// Currently, only 4 items shown by iOS, but that can increase in the future.
|
|
|
|
// iOS will discard additional items we give it.
|
|
|
|
var tunnelNames = RecentTunnelsTracker.recentlyActivatedTunnelNames(limit: numberOfItems)
|
|
|
|
let numberOfSlotsRemaining = numberOfItems - tunnelNames.count
|
|
|
|
if numberOfSlotsRemaining > 0 {
|
|
|
|
let moreTunnels = allTunnelNames.filter { !tunnelNames.contains($0) }.prefix(numberOfSlotsRemaining)
|
|
|
|
tunnelNames.append(contentsOf: moreTunnels)
|
|
|
|
}
|
|
|
|
return tunnelNames.map { QuickActionItem(tunnelName: $0) }
|
|
|
|
}
|
|
|
|
}
|