Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple filtered urls #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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