From 695170b2896ff9ed676fca46b6b35c7e90eb7c76 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sat, 13 Jan 2018 19:56:25 +0000 Subject: [PATCH] Add ability to unsubscribe and add more tests. --- .gitignore | 4 +- Doughnut.xcodeproj/project.pbxproj | 14 +-- Doughnut/AppDelegate.swift | 27 ++++- .../CloseIcon.imageset/Contents.json | 1 + Doughnut/Base.lproj/Main.storyboard | 53 ++------- Doughnut/Library/Library.swift | 35 +++++- Doughnut/Preference/Preferences.storyboard | 1 - .../PodcastViewController.swift | 16 +++ DoughnutTests/DoughnutTests.swift | 2 + .../LibraryTests/LibrarySpyDelegate.swift | 24 ++-- .../LibraryTestsWithSubscription.swift | 110 +++++++++++++++++- 11 files changed, 219 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index 3eb0e70..92af69e 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,6 @@ Carthage/Build fastlane/report.xml fastlane/Preview.html fastlane/screenshots -fastlane/test_output \ No newline at end of file +fastlane/test_output + +Releases \ No newline at end of file diff --git a/Doughnut.xcodeproj/project.pbxproj b/Doughnut.xcodeproj/project.pbxproj index e2db7e0..5a76efa 100644 --- a/Doughnut.xcodeproj/project.pbxproj +++ b/Doughnut.xcodeproj/project.pbxproj @@ -77,6 +77,9 @@ 83235C082009473600BC356F /* PrefPlaybackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83235BFA200945D900BC356F /* PrefPlaybackViewController.swift */; }; 83235C092009473600BC356F /* PrefPlaybackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83235BFA200945D900BC356F /* PrefPlaybackViewController.swift */; }; 83235C0C2009481400BC356F /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 83235C0B2009481200BC356F /* dsa_pub.pem */; }; + 83235C0D2009502D00BC356F /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83235BF7200945D900BC356F /* Preferences.storyboard */; }; + 83235C0E2009502D00BC356F /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83235BF7200945D900BC356F /* Preferences.storyboard */; }; + 83235C0F2009502D00BC356F /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83235BF7200945D900BC356F /* Preferences.storyboard */; }; 832A04341F76EBDC00C92D25 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832A04331F76EBDC00C92D25 /* WindowController.swift */; }; 832FF90B1F8D60430065E593 /* DownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832FF90A1F8D60430065E593 /* DownloadManager.swift */; }; 8335D48C1F856E120060D8D8 /* ValidFeedx3.xml in Resources */ = {isa = PBXBuildFile; fileRef = 8335D48B1F856E120060D8D8 /* ValidFeedx3.xml */; }; @@ -341,13 +344,6 @@ path = Preference; sourceTree = ""; }; - 83235BFB2009464900BC356F /* Resources */ = { - isa = PBXGroup; - children = ( - ); - path = Resources; - sourceTree = ""; - }; 83235C0A200947F200BC356F /* Resources */ = { isa = PBXGroup; children = ( @@ -382,7 +378,6 @@ isa = PBXGroup; children = ( 838257CC1F759F6F00DB4FD1 /* Doughnut */, - 83235BFB2009464900BC356F /* Resources */, 838257DF1F759F6F00DB4FD1 /* DoughnutTests */, 838257EA1F759F6F00DB4FD1 /* DoughnutUITests */, 838257CB1F759F6F00DB4FD1 /* Products */, @@ -632,6 +627,7 @@ 838257D21F759F6F00DB4FD1 /* Assets.xcassets in Resources */, 83235C0C2009481400BC356F /* dsa_pub.pem in Resources */, 838257D51F759F6F00DB4FD1 /* Main.storyboard in Resources */, + 83235C0D2009502D00BC356F /* Preferences.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -642,6 +638,7 @@ 83D4CA5A1F7C3779002EDC36 /* ValidFeed.xml in Resources */, 8335D48D1F8571150060D8D8 /* enclosure.mp3 in Resources */, 8335D48C1F856E120060D8D8 /* ValidFeedx3.xml in Resources */, + 83235C0E2009502D00BC356F /* Preferences.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -649,6 +646,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 83235C0F2009502D00BC356F /* Preferences.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Doughnut/AppDelegate.swift b/Doughnut/AppDelegate.swift index 072011a..efb0700 100644 --- a/Doughnut/AppDelegate.swift +++ b/Doughnut/AppDelegate.swift @@ -40,8 +40,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { UserDefaults.standard.register(defaults: Preference.defaultPreference) mediaKeyTap = SPMediaKeyTap(delegate: self) - if SPMediaKeyTap.usesGlobalMediaKeyTap() { - mediaKeyTap?.startWatchingMediaKeys() + + UserDefaults.standard.addObserver(self, forKeyPath: Preference.Key.enableMediaKeys.rawValue, options: [], context: nil) + if Preference.bool(for: Preference.Key.enableMediaKeys) { + setupMediaKeyTap() } /*do { @@ -69,6 +71,27 @@ class AppDelegate: NSObject, NSApplicationDelegate { // Insert code here to tear down your application } + override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { + switch keyPath { + case Preference.Key.enableMediaKeys.rawValue?: + setupMediaKeyTap() + default: + return + } + } + + func setupMediaKeyTap() { + guard let mediaKeyTap = mediaKeyTap else { return } + + if Preference.bool(for: Preference.Key.enableMediaKeys) { + if SPMediaKeyTap.usesGlobalMediaKeyTap() { + mediaKeyTap.startWatchingMediaKeys() + } + } else { + mediaKeyTap.stopWatchingMediaKeys() + } + } + override func mediaKeyTap(_ keyTap: SPMediaKeyTap!, receivedMediaKeyEvent event: NSEvent!) { let keyCode = Int((event.data1 & 0xFFFF0000) >> 16); let keyFlags = (event.data1 & 0x0000FFFF); diff --git a/Doughnut/Assets.xcassets/CloseIcon.imageset/Contents.json b/Doughnut/Assets.xcassets/CloseIcon.imageset/Contents.json index 8d0c691..62f5bbb 100644 --- a/Doughnut/Assets.xcassets/CloseIcon.imageset/Contents.json +++ b/Doughnut/Assets.xcassets/CloseIcon.imageset/Contents.json @@ -7,6 +7,7 @@ }, { "idiom" : "universal", + "filename" : "close_x2.png", "scale" : "2x" }, { diff --git a/Doughnut/Base.lproj/Main.storyboard b/Doughnut/Base.lproj/Main.storyboard index edd2a42..261a275 100644 --- a/Doughnut/Base.lproj/Main.storyboard +++ b/Doughnut/Base.lproj/Main.storyboard @@ -315,38 +315,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -630,7 +598,7 @@ Gw - + @@ -791,9 +759,9 @@ Gw - + - + @@ -978,7 +946,7 @@ Gw