Skip to content

Commit

Permalink
add filtered urls
Browse files Browse the repository at this point in the history
  • Loading branch information
agustiyann authored and Agus Tiyansyah Syam committed Mar 25, 2024
1 parent 695ccee commit dde2461
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,36 @@ open class Storage: NSObject {
public static var limit: NSNumber? = nil

public static var defaultFilter: String? = nil


public static var filteredURLs: [String]? = nil

open var requests: [RequestModel] = []

func saveRequest(request: RequestModel?){
func saveRequest(request: RequestModel?) {
guard request != nil else {
return
}

if let index = requests.firstIndex(where: { (req) -> Bool in
return request?.id == req.id ? true : false
}){
}) {
requests[index] = request!
}else{
} else {
requests.insert(request!, at: 0)
}

if let limit = Self.limit?.intValue {
requests = Array(requests.prefix(limit))
}

if let filteredURLs = Self.filteredURLs {
requests = requests.filter({ request in
filteredURLs.contains { url in
request.url.contains(url)
}
})
}

NotificationCenter.default.post(name: newRequestNotification, object: nil)
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/Wormholy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public class Wormholy: NSObject
set { Storage.defaultFilter = newValue }
}

/// Filtered urls that will be appear in the list
///
@objc public static var filteredURLs: [String]? {
get { Storage.filteredURLs }
set { Storage.filteredURLs = newValue }
}

@objc public static func swiftyLoad() {
NotificationCenter.default.addObserver(forName: fireWormholy, object: nil, queue: nil) { (notification) in
Wormholy.presentWormholyFlow()
Expand Down

0 comments on commit dde2461

Please sign in to comment.