diff --git a/Finicky/Finicky/API.swift b/Finicky/Finicky/API.swift index d800dd0..b0ac699 100644 --- a/Finicky/Finicky/API.swift +++ b/Finicky/Finicky/API.swift @@ -8,12 +8,12 @@ import JavaScriptCore @objc open class FinickyAPI: NSObject, FinickyAPIExports { fileprivate static var context: JSContext! - fileprivate static var logToConsole: ((_ message: String) -> Void)? + fileprivate static var logToConsole: ((_ message: String, _ clearConsole: Bool) -> Void)? static func log(_ message: String?) { if message != nil { NSLog(message!) - logToConsole?(message!) + logToConsole?(message!, false) } } @@ -31,7 +31,7 @@ import JavaScriptCore self.context = context } - @objc class func setLog(_ logToConsole: @escaping (_ message: String) -> Void) { + @objc class func setLog(_ logToConsole: @escaping (_ message: String, _ clearConsole: Bool) -> Void) { self.logToConsole = logToConsole } } diff --git a/Finicky/Finicky/AppDelegate.swift b/Finicky/Finicky/AppDelegate.swift index 952412f..e807ff0 100644 --- a/Finicky/Finicky/AppDelegate.swift +++ b/Finicky/Finicky/AppDelegate.swift @@ -9,6 +9,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele @IBOutlet var yourTextField: NSTextField! @IBOutlet var textView: NSTextView! + @IBAction func ClearConsole(_: Any? = nil) { + textView.string = "" + } + @objc var statusItem: NSStatusItem! var configLoader: FinickyConfig! var shortUrlResolver: FNShortUrlResolver = FNShortUrlResolver() @@ -16,6 +20,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele func applicationWillFinishLaunching(_: Notification) { yourTextField.delegate = self + ClearConsole() let bundleId = "net.kassett.Finicky" LSSetDefaultHandlerForURLScheme("http" as CFString, bundleId as CFString) LSSetDefaultHandlerForURLScheme("https" as CFString, bundleId as CFString) @@ -93,12 +98,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele testConfigWindow.orderFront(sender) } - func logToConsole(_ message: String) { + func logToConsole(_ message: String, clearConsole _: Bool = false) { let date = Date() let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let dateString = formatter.string(from: date) - textView.string = dateString + " - " + message + "\n\n" + textView.string.prefix(20000).trimmingCharacters(in: .whitespacesAndNewlines) + textView.string = textView.string + dateString + " - " + message + "\n" + textView.scrollToEndOfDocument(self) } @IBAction func testUrl(_ sender: NSTextField) { @@ -121,26 +127,22 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele func performTest(url: URL) { if let appDescriptor = configLoader.determineOpeningApp(url: url, sourceBundleIdentifier: "net.kassett.finicky") { - var description = """ - - Would open url: \(appDescriptor.url) - - """ + var description = "" if appDescriptor.browsers.count == 1 { if let browser = appDescriptor.browsers.first { - description += "Browser:\n" - description += " \(browser.name) \(browser.openInBackground ? "(opens in background)" : "")\n" + description += "Opens browser: \(browser.name)\(browser.openInBackground ? " (opens in background)" : "")" } } else if appDescriptor.browsers.count == 0 { description += "Won't open any browser" } else { - description += "First active browser of:\n" + description += "Opens first active browser of: " for (index, browser) in appDescriptor.browsers.enumerated() { - description += " [\(index)]: \(browser.name) \(browser.openInBackground ? "(opens in background)" : "")\n" + description += "[\(index)]: \(browser.name) \(browser.openInBackground ? "(opens in background)" : "")" } } + description += ", url: \(appDescriptor.url)" logToConsole(description) } } diff --git a/Finicky/Finicky/AppDescriptor.swift b/Finicky/Finicky/AppDescriptor.swift index a654b67..4f5fb5d 100644 --- a/Finicky/Finicky/AppDescriptor.swift +++ b/Finicky/Finicky/AppDescriptor.swift @@ -12,19 +12,19 @@ enum BrowserError: Error { case cantFindBrowser(msg: String) } -public struct BrowserOpts : CustomStringConvertible { +public struct BrowserOpts: CustomStringConvertible { public var name: String public var openInBackground: Bool public var bundleId: String? public var appPath: String? - + public var description: String { if let bundleId = self.bundleId { return bundleId } else if let appPath = self.appPath { return appPath } else { - return self.name + return name } } @@ -33,13 +33,13 @@ public struct BrowserOpts : CustomStringConvertible { self.openInBackground = openInBackground ?? false if appType == AppDescriptorType.bundleId { - self.bundleId = name + bundleId = name } else if appType == AppDescriptorType.appPath { - self.appPath = name + appPath = name } else if let path = NSWorkspace.shared.fullPath(forApplication: name) { if let bundle = Bundle(path: path) { - self.bundleId = bundle.bundleIdentifier! - self.appPath = path + bundleId = bundle.bundleIdentifier! + appPath = path } else { throw BrowserError.cantFindBrowser(msg: "Couldn't find application \"\(name)\"") } @@ -47,7 +47,7 @@ public struct BrowserOpts : CustomStringConvertible { throw BrowserError.cantFindBrowser(msg: "Couldn't find application \"\(name)\"") } } - + public static func isAppDirectory(_ path: String) -> Bool { var isDirectory = ObjCBool(true) let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory) diff --git a/Finicky/Finicky/Base.lproj/MainMenu.xib b/Finicky/Finicky/Base.lproj/MainMenu.xib index 079ac34..f4c9dcb 100644 --- a/Finicky/Finicky/Base.lproj/MainMenu.xib +++ b/Finicky/Finicky/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -715,7 +715,7 @@ - + @@ -742,18 +742,18 @@ - + - + - + - + @@ -768,6 +768,17 @@ + @@ -776,7 +787,7 @@ - + diff --git a/Finicky/Finicky/Battery.swift b/Finicky/Finicky/Battery.swift new file mode 100644 index 0000000..e584157 --- /dev/null +++ b/Finicky/Finicky/Battery.swift @@ -0,0 +1,9 @@ +// +// Battery.swift +// Finicky +// +// Created by John Sterling on 2020-04-26. +// Copyright © 2020 John sterling. All rights reserved. +// + +import Foundation diff --git a/Finicky/Finicky/Browsers.swift b/Finicky/Finicky/Browsers.swift index 9b60c77..cfbb798 100644 --- a/Finicky/Finicky/Browsers.swift +++ b/Finicky/Finicky/Browsers.swift @@ -14,15 +14,13 @@ enum Browser: String { public func getBrowserCommand(_ browserOpts: BrowserOpts, url: URL) -> [String] { var command = ["open", url.absoluteString] - + // appPath takes priority over bundleId as it is always unique. if let appPath = browserOpts.appPath { command.append(contentsOf: ["-a", appPath]) } else if let bundleId = browserOpts.bundleId { command.append(contentsOf: ["-b", bundleId]) - } else { - - } + } else {} if browserOpts.openInBackground { command.append("-g") diff --git a/Finicky/Finicky/Config.swift b/Finicky/Finicky/Config.swift index 0e45754..7a3b8f8 100644 --- a/Finicky/Finicky/Config.swift +++ b/Finicky/Finicky/Config.swift @@ -5,6 +5,7 @@ import JavaScriptCore var FNConfigPath: String = "~/.finicky.js" public typealias Callback = (T) -> Void +public typealias Callback2 = (T, U) -> Void open class FinickyConfig { var ctx: JSContext! @@ -17,7 +18,7 @@ open class FinickyConfig { var fileDescriptor: Int32 = -1 var lastModificationDate: Date? var toggleIconCallback: Callback? - var logToConsole: Callback? + var logToConsole: Callback2? var setShortUrlProviders: Callback<[String]?>? var updateStatus: Callback? @@ -25,7 +26,7 @@ open class FinickyConfig { configAPIString = loadJS("finickyConfigAPI.js") } - public convenience init(toggleIconCallback: @escaping Callback, logToConsoleCallback: @escaping Callback, setShortUrlProviders: @escaping Callback<[String]?>, updateStatus: @escaping Callback) { + public convenience init(toggleIconCallback: @escaping Callback, logToConsoleCallback: @escaping Callback2, setShortUrlProviders: @escaping Callback<[String]?>, updateStatus: @escaping Callback) { self.init() self.toggleIconCallback = toggleIconCallback logToConsole = logToConsoleCallback @@ -112,7 +113,7 @@ open class FinickyConfig { let shortMessage = "Configuration: \(String(describing: exception!))" print(message) showNotification(title: "Configuration", informativeText: String(describing: exception!), error: true) - self.logToConsole?(shortMessage) + self.logToConsole?(shortMessage, false) } ctx.evaluateScript("const module = {}") @@ -144,7 +145,7 @@ open class FinickyConfig { print(message) showNotification(title: message, error: true) - logToConsole?(message) + logToConsole?(message, false) return false } else { @@ -189,7 +190,7 @@ open class FinickyConfig { ] }; // For more examples, see the Finicky github page https://github.com/johnste/finicky - """) + """, false) return } @@ -209,7 +210,7 @@ open class FinickyConfig { if showSuccess { showNotification(title: "Reloaded config successfully") - logToConsole?("Reloaded config successfully") + logToConsole?("Reloaded config successfully", false) } } } @@ -252,7 +253,7 @@ open class FinickyConfig { return browser } catch _ as BrowserError { showNotification(title: "Couldn't find browser \"\(browserName)\"") - logToConsole?("Couldn't find browser \"\(browserName)\"") + logToConsole?("Couldn't find browser \"\(browserName)\"", false) return nil } catch let msg { print("Unknown error resolving browser: \(msg)") @@ -267,7 +268,7 @@ open class FinickyConfig { if let rewrittenUrl = URL(string: newUrl) { finalUrl = rewrittenUrl } else { - logToConsole?("Couldn't generate url from handler \(newUrl), falling back to original url") + logToConsole?("Couldn't generate url from handler \(newUrl), falling back to original url", false) } } diff --git a/Finicky/Finicky/ShortUrlResolver.swift b/Finicky/Finicky/ShortUrlResolver.swift index ddfdf3a..84d81df 100644 --- a/Finicky/Finicky/ShortUrlResolver.swift +++ b/Finicky/Finicky/ShortUrlResolver.swift @@ -52,7 +52,7 @@ final class FNShortUrlResolver { func isShortUrl(_ url: URL) -> Bool { guard let host = url.host, - shortUrlProviders.contains(host) else {return false} + shortUrlProviders.contains(host) else { return false } // Can't load insecure cleartext HTTP // https://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http diff --git a/Finicky/Finicky/UpdateCheck.swift b/Finicky/Finicky/UpdateCheck.swift index 8237186..78c5500 100644 --- a/Finicky/Finicky/UpdateCheck.swift +++ b/Finicky/Finicky/UpdateCheck.swift @@ -1,15 +1,15 @@ import Foundation -public struct Version: Decodable, Hashable { - public let title: String - public let version: String - public let prerelease: Bool - - enum CodingKeys: String, CodingKey { - case title = "name" - case version = "tag_name" - case prerelease - } +public struct Version: Decodable, Hashable { + public let title: String + public let version: String + public let prerelease: Bool + + enum CodingKeys: String, CodingKey { + case title = "name" + case version = "tag_name" + case prerelease + } } struct defaultsKeys { @@ -18,7 +18,7 @@ struct defaultsKeys { func checkForUpdate(_ newVersionCallback: @escaping Callback) { guard let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, - let url = URL(string: "https://api.github.com/repos/johnste/finicky/releases") else {return} + let url = URL(string: "https://api.github.com/repos/johnste/finicky/releases") else { return } var request = URLRequest(url: url) request.setValue("finicky/\(version)", forHTTPHeaderField: "User-Agent") @@ -35,14 +35,14 @@ func checkForUpdate(_ newVersionCallback: @escaping Callback) { try compareVersions(versionA.version, versionB.version) == .orderedDescending }) - guard let latestVersion = sortedVersions.first else { newVersionCallback(nil); return } - let laterThanCurrent = try compareVersions(version, latestVersion.version) - guard laterThanCurrent == ComparisonResult.orderedAscending else { newVersionCallback(nil); return } - guard let latestSeenBefore = defaults.string(forKey: defaultsKeys.keyLatestVersionSeen) else { return } + guard let latestVersion = sortedVersions.first else { newVersionCallback(nil); return } + let laterThanCurrent = try compareVersions(version, latestVersion.version) + guard laterThanCurrent == ComparisonResult.orderedAscending else { newVersionCallback(nil); return } + guard let latestSeenBefore = defaults.string(forKey: defaultsKeys.keyLatestVersionSeen) else { return } print("latestSeenBefore \(latestSeenBefore)") if latestSeenBefore != latestVersion.version { - defaults.set(latestVersion.version, forKey: defaultsKeys.keyLatestVersionSeen) - newVersionCallback(latestVersion) + defaults.set(latestVersion.version, forKey: defaultsKeys.keyLatestVersionSeen) + newVersionCallback(latestVersion) } } catch { print("error") @@ -90,6 +90,6 @@ public func compareVersions(_ versionA: String, _ versionB: String) throws -> Co } func getVersions(data: Data) throws -> Set { - let versions = try JSONDecoder().decode(Set.self, from: data) - return versions.filter{!$0.prerelease} + let versions = try JSONDecoder().decode(Set.self, from: data) + return versions.filter { !$0.prerelease } } diff --git a/Finicky/Finicky/Utilities.swift b/Finicky/Finicky/Utilities.swift index 293476a..597d2b9 100644 --- a/Finicky/Finicky/Utilities.swift +++ b/Finicky/Finicky/Utilities.swift @@ -21,7 +21,7 @@ func getModificationDate(fileManager: FileManager = FileManager.default, atPath: let attributes = try fileManager.attributesOfItem(atPath: atPath) return attributes[FileAttributeKey.modificationDate] as? Date } catch { - print("Error message: \(error.localizedDescription)") + print("Error message: \(error.localizedDescription)") return nil } } diff --git a/Finicky/Finicky/finickyConfigAPI.js b/Finicky/Finicky/finickyConfigAPI.js index d8b7502..4d563e3 100644 --- a/Finicky/Finicky/finickyConfigAPI.js +++ b/Finicky/Finicky/finickyConfigAPI.js @@ -1080,7 +1080,7 @@ var finickyConfigApi = (function (exports) { search: search.replace("?", ""), password: url.password, port: url.port ? +url.port : undefined, - hash: url.hash.replace("#", "") + hash: url.hash.replace("#", ""), }; }; var matchDomains = function (matchers) { diff --git a/Finicky/FinickyTests/FinickyUnitTests.swift b/Finicky/FinickyTests/FinickyUnitTests.swift index 95792b9..08e9652 100644 --- a/Finicky/FinickyTests/FinickyUnitTests.swift +++ b/Finicky/FinickyTests/FinickyUnitTests.swift @@ -1,124 +1,121 @@ import Cocoa -import XCTest @testable import Finicky +import XCTest struct Fixture { - let value : T - init(url: URL) throws { - let actualData = try Data(contentsOf: url) - self.value = try JSONDecoder().decode(T.self, from: actualData) - - } - func assert(_ t:T) { - XCTAssertEqual(t, value) - } + let value: T + init(url: URL) throws { + let actualData = try Data(contentsOf: url) + value = try JSONDecoder().decode(T.self, from: actualData) + } + + func assert(_ t: T) { + XCTAssertEqual(t, value) + } } class FinickyUnitTests: XCTestCase { - func testRewrite() { - XCTAssertEqual(try compareVersions("1.2.3", "0.9"), ComparisonResult.orderedDescending) - XCTAssertEqual(try compareVersions("1.9.3", "0.9"), ComparisonResult.orderedDescending) - XCTAssertEqual(try compareVersions("10", "9"), ComparisonResult.orderedDescending) - XCTAssertEqual(try compareVersions("1.9.3.1", "1.9.3"), ComparisonResult.orderedDescending) - XCTAssertEqual(try compareVersions("1.9.3", "1.9.3"), ComparisonResult.orderedSame) - XCTAssertEqual(try compareVersions("0.9.3", "1.9.3"), ComparisonResult.orderedAscending) - } - - func test_isShortUrl() { - let resolver = FNShortUrlResolver(shortUrlProviders: ["te.st"]) - let actualPositive = resolver.isShortUrl(URL(string: "https://te.st/testing")!) - let actualPositiveHttps = resolver.isShortUrl(URL(string: "http://te.st/testing")!) - let actualNegative = resolver.isShortUrl(URL(string: "https://st.te/testing")!) - - XCTAssertTrue(actualPositive) - XCTAssertFalse(actualNegative) - XCTAssertFalse(actualPositiveHttps) - } - - func test_notifications() throws { - let center = NSUserNotificationCenter.default - - XCTAssertTrue(center.deliveredNotifications.isEmpty) - showNotification(at: center, title: "title", subtitle: "subtitle", informativeText: "informativeText", error: true) - - XCTAssertFalse(center.deliveredNotifications.isEmpty) - - let notification = try XCTUnwrap(center.deliveredNotifications.first) - - XCTAssertEqual(notification.title, "title") - XCTAssertEqual(notification.subtitle, "subtitle") - XCTAssertEqual(notification.informativeText, "informativeText") - XCTAssertEqual(notification.soundName, NSUserNotificationDefaultSoundName) - - center.removeDeliveredNotification(notification) - } - - func test_makeVersionParts_error() { - var capturedError: VersionParseError? = nil - let expected = [1, 2, 3, 4, 5, 6, 7] - - do { - let actual = try makeVersionParts("1.2.3.4.5.6.7") - XCTAssertEqual(actual, expected) - } catch { - capturedError = error as? VersionParseError + func testRewrite() { + XCTAssertEqual(try compareVersions("1.2.3", "0.9"), ComparisonResult.orderedDescending) + XCTAssertEqual(try compareVersions("1.9.3", "0.9"), ComparisonResult.orderedDescending) + XCTAssertEqual(try compareVersions("10", "9"), ComparisonResult.orderedDescending) + XCTAssertEqual(try compareVersions("1.9.3.1", "1.9.3"), ComparisonResult.orderedDescending) + XCTAssertEqual(try compareVersions("1.9.3", "1.9.3"), ComparisonResult.orderedSame) + XCTAssertEqual(try compareVersions("0.9.3", "1.9.3"), ComparisonResult.orderedAscending) } - XCTAssertNil(capturedError) - } - - func test_modificationDate() throws { - let filePath = NSTemporaryDirectory().appending("test.json") - let manager = FileManager() - let now = Date() - let createFile = manager.createFile(atPath: filePath, contents: Data("test".utf8), attributes: nil) - precondition(createFile) - let date = getModificationDate(fileManager: manager, atPath: filePath) - XCTAssertEqual(0.1, date!.timeIntervalSince(now), accuracy: 0.1) - } - - func test_getVersions() throws { - let expected = Set([ - Version(title: "Finicky 2.2.3 - Minor fixes", version: "v2.2.3", prerelease: false), - Version(title: "Finicky 2.3 ALPHA - Private/Incognito mode for Chrome", version: "v2.3-alpha", prerelease: true), - Version(title: "Finicky 2.2.2 - Source process path & Dock icon bug fix", version: "v2.2.2", prerelease: false), - Version(title: "Finicky 2.2.1 - Open preferred browsers", version: "v2.2.1", prerelease: false), - Version(title: "Finicky 2.2.0 - Browser priority + block urls", version: "v2.2.0", prerelease: true), - Version(title: "Finicky 2.1.0 - Keyboard support", version: "v2.1.0", prerelease: false), - Version(title: "Finicky 2.0", version: "v2.0", prerelease: false), - Version(title: "Finicky 2 RC3", version: "v2.0-rc.3", prerelease: true), - Version(title: "Finicky 2 RC2", version: "v2.0-rc.2", prerelease: true), - Version(title: "Finicky 2 RC1", version: "v2.0-rc.1", prerelease: true), - Version(title: "Finicky 2 RC 0", version: "v2.0-rc.0", prerelease: true), - Version(title: "Finicky v0.5", version: "v0.5", prerelease: true), - Version(title: "Finicky v0.4", version: "v0.4", prerelease: true), - Version(title: "Finicky v0.3", version: "v0.3", prerelease: true), - Version(title: "Finicky v0.2", version: "v0.2", prerelease: true), - Version(title: "Finicky v0.1", version: "v0.1", prerelease: true) - ]) - - let fixtureURL = Bundle(identifier: "net.kassett.FinickyTests")! - .bundleURL - .appendingPathComponent("Contents") - .appendingPathComponent("Resources") - .appendingPathComponent("Fixtures") - .appendingPathComponent("github-fixture") - .appendingPathExtension("json") - - let fixture = try Fixture>(url: fixtureURL) - fixture.assert(expected) - - let actualData = try Data(contentsOf: fixtureURL) - let versions = try getVersions(data: actualData) - - XCTAssertEqual(versions, [ - Version(title: "Finicky 2.2.3 - Minor fixes", version: "v2.2.3", prerelease: false), - Version(title: "Finicky 2.2.2 - Source process path & Dock icon bug fix", version: "v2.2.2", prerelease: false), - Version(title: "Finicky 2.2.1 - Open preferred browsers", version: "v2.2.1", prerelease: false), - Version(title: "Finicky 2.1.0 - Keyboard support", version: "v2.1.0", prerelease: false), - Version(title: "Finicky 2.0", version: "v2.0", prerelease: false) - ]) - - } -} + func test_isShortUrl() { + let resolver = FNShortUrlResolver(shortUrlProviders: ["te.st"]) + let actualPositive = resolver.isShortUrl(URL(string: "https://te.st/testing")!) + let actualPositiveHttps = resolver.isShortUrl(URL(string: "http://te.st/testing")!) + let actualNegative = resolver.isShortUrl(URL(string: "https://st.te/testing")!) + + XCTAssertTrue(actualPositive) + XCTAssertFalse(actualNegative) + XCTAssertFalse(actualPositiveHttps) + } + + func test_notifications() throws { + let center = NSUserNotificationCenter.default + + XCTAssertTrue(center.deliveredNotifications.isEmpty) + showNotification(at: center, title: "title", subtitle: "subtitle", informativeText: "informativeText", error: true) + + XCTAssertFalse(center.deliveredNotifications.isEmpty) + let notification = try XCTUnwrap(center.deliveredNotifications.first) + + XCTAssertEqual(notification.title, "title") + XCTAssertEqual(notification.subtitle, "subtitle") + XCTAssertEqual(notification.informativeText, "informativeText") + XCTAssertEqual(notification.soundName, NSUserNotificationDefaultSoundName) + + center.removeDeliveredNotification(notification) + } + + func test_makeVersionParts_error() { + var capturedError: VersionParseError? + let expected = [1, 2, 3, 4, 5, 6, 7] + + do { + let actual = try makeVersionParts("1.2.3.4.5.6.7") + XCTAssertEqual(actual, expected) + } catch { + capturedError = error as? VersionParseError + } + XCTAssertNil(capturedError) + } + + func test_modificationDate() throws { + let filePath = NSTemporaryDirectory().appending("test.json") + let manager = FileManager() + let now = Date() + let createFile = manager.createFile(atPath: filePath, contents: Data("test".utf8), attributes: nil) + precondition(createFile) + let date = getModificationDate(fileManager: manager, atPath: filePath) + XCTAssertEqual(0.1, date!.timeIntervalSince(now), accuracy: 0.1) + } + + func test_getVersions() throws { + let expected = Set([ + Version(title: "Finicky 2.2.3 - Minor fixes", version: "v2.2.3", prerelease: false), + Version(title: "Finicky 2.3 ALPHA - Private/Incognito mode for Chrome", version: "v2.3-alpha", prerelease: true), + Version(title: "Finicky 2.2.2 - Source process path & Dock icon bug fix", version: "v2.2.2", prerelease: false), + Version(title: "Finicky 2.2.1 - Open preferred browsers", version: "v2.2.1", prerelease: false), + Version(title: "Finicky 2.2.0 - Browser priority + block urls", version: "v2.2.0", prerelease: true), + Version(title: "Finicky 2.1.0 - Keyboard support", version: "v2.1.0", prerelease: false), + Version(title: "Finicky 2.0", version: "v2.0", prerelease: false), + Version(title: "Finicky 2 RC3", version: "v2.0-rc.3", prerelease: true), + Version(title: "Finicky 2 RC2", version: "v2.0-rc.2", prerelease: true), + Version(title: "Finicky 2 RC1", version: "v2.0-rc.1", prerelease: true), + Version(title: "Finicky 2 RC 0", version: "v2.0-rc.0", prerelease: true), + Version(title: "Finicky v0.5", version: "v0.5", prerelease: true), + Version(title: "Finicky v0.4", version: "v0.4", prerelease: true), + Version(title: "Finicky v0.3", version: "v0.3", prerelease: true), + Version(title: "Finicky v0.2", version: "v0.2", prerelease: true), + Version(title: "Finicky v0.1", version: "v0.1", prerelease: true), + ]) + + let fixtureURL = Bundle(identifier: "net.kassett.FinickyTests")! + .bundleURL + .appendingPathComponent("Contents") + .appendingPathComponent("Resources") + .appendingPathComponent("Fixtures") + .appendingPathComponent("github-fixture") + .appendingPathExtension("json") + + let fixture = try Fixture>(url: fixtureURL) + fixture.assert(expected) + + let actualData = try Data(contentsOf: fixtureURL) + let versions = try getVersions(data: actualData) + + XCTAssertEqual(versions, [ + Version(title: "Finicky 2.2.3 - Minor fixes", version: "v2.2.3", prerelease: false), + Version(title: "Finicky 2.2.2 - Source process path & Dock icon bug fix", version: "v2.2.2", prerelease: false), + Version(title: "Finicky 2.2.1 - Open preferred browsers", version: "v2.2.1", prerelease: false), + Version(title: "Finicky 2.1.0 - Keyboard support", version: "v2.1.0", prerelease: false), + Version(title: "Finicky 2.0", version: "v2.0", prerelease: false), + ]) + } +} diff --git a/config-api/src/createAPI.ts b/config-api/src/createAPI.ts index 3636f2c..18a141e 100644 --- a/config-api/src/createAPI.ts +++ b/config-api/src/createAPI.ts @@ -51,7 +51,7 @@ export function createAPI( search: search.replace("?", ""), password: url.password, port: url.port ? +url.port : undefined, - hash: url.hash.replace("#", "") + hash: url.hash.replace("#", ""), }; }; @@ -66,7 +66,7 @@ export function createAPI( matchers = [matchers]; } - matchers.forEach(matcher => { + matchers.forEach((matcher) => { if (matcher instanceof RegExp || typeof matcher === "string") { return; } @@ -75,9 +75,9 @@ export function createAPI( ); }); - return function({ url }: Options) { + return function ({ url }: Options) { const domain = url.host; - return (matchers as Matcher[]).some(matcher => { + return (matchers as Matcher[]).some((matcher) => { if (matcher instanceof RegExp) { return matcher.test(domain); } else if (typeof matcher === "string") {