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

[Done] Filter default base url #1

Open
wants to merge 3 commits into
base: master-alfagift
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: 16 additions & 3 deletions Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,41 @@ open class Storage: NSObject {

public static var defaultFilter: String? = nil

public static var filterOnlyThisUrls: [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 filterUrls = Self.filterOnlyThisUrls {
requests = requests.filter({ request in
filterUrls.contains { url in
request.url.contains(url)
}
})
}

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

func clearRequests() {
requests.removeAll()
}
}


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

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

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