mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
@@ -55,7 +55,7 @@ class AddWebFeedModel: ObservableObject {
|
||||
}
|
||||
|
||||
func pasteUrlFromPasteboard() {
|
||||
guard let stringFromPasteboard = urlStringFromPasteboard, stringFromPasteboard.isValidURL else {
|
||||
guard let stringFromPasteboard = urlStringFromPasteboard, stringFromPasteboard.mayBeURL else {
|
||||
return
|
||||
}
|
||||
providedURL = stringFromPasteboard
|
||||
@@ -97,15 +97,22 @@ class AddWebFeedModel: ObservableObject {
|
||||
|
||||
showProgressIndicator = true
|
||||
|
||||
let normalizedURLString = providedURL.normalizedURL
|
||||
|
||||
guard !normalizedURLString.isEmpty, let url = URL(string: normalizedURLString) else {
|
||||
showProgressIndicator = false
|
||||
return
|
||||
}
|
||||
|
||||
let container = containers[selectedFolderIndex]
|
||||
|
||||
if account.hasWebFeed(withURL: providedURL) {
|
||||
if account.hasWebFeed(withURL: normalizedURLString) {
|
||||
addFeedError = .alreadySubscribed
|
||||
showProgressIndicator = false
|
||||
return
|
||||
}
|
||||
|
||||
account.createWebFeed(url: providedURL, name: providedName, container: container, completion: { [weak self] result in
|
||||
account.createWebFeed(url: url.absoluteString, name: providedName, container: container, completion: { [weak self] result in
|
||||
self?.showProgressIndicator = false
|
||||
switch result {
|
||||
case .success(let feed):
|
||||
|
||||
@@ -96,11 +96,16 @@ struct AddWebFeedView: View {
|
||||
})
|
||||
.help("Cancel Add Feed")
|
||||
, trailing:
|
||||
Button("Add", action: {
|
||||
viewModel.addWebFeed()
|
||||
})
|
||||
.disabled(!viewModel.providedURL.isValidURL)
|
||||
.help("Add Feed")
|
||||
HStack(spacing: 12) {
|
||||
if viewModel.showProgressIndicator == true {
|
||||
ProgressView()
|
||||
}
|
||||
Button("Add", action: {
|
||||
viewModel.addWebFeed()
|
||||
})
|
||||
.disabled(!viewModel.providedURL.mayBeURL)
|
||||
.help("Add Feed")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -174,7 +179,7 @@ struct AddWebFeedView: View {
|
||||
Button("Add", action: {
|
||||
viewModel.addWebFeed()
|
||||
})
|
||||
.disabled(!viewModel.providedURL.isValidURL)
|
||||
.disabled(!viewModel.providedURL.mayBeURL)
|
||||
.help("Add Feed")
|
||||
}.padding(.trailing, 2)
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// String+URLChecker.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 3/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
|
||||
/// Reference: [StackOverflow](https://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url)
|
||||
var isValidURL: Bool {
|
||||
let regEx = "^([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\?\\'\\\\\\+&%\\$#\\=~_\\-]+))*$"
|
||||
let predicate = NSPredicate(format:"SELF MATCHES %@", argumentArray:[regEx])
|
||||
return predicate.evaluate(with: self)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user