Skip to content

Commit

Permalink
Add ability to unsubscribe and add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dyerc committed Jan 13, 2018
1 parent 6edc020 commit 695170b
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 68 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ Carthage/Build
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/test_output

Releases
14 changes: 6 additions & 8 deletions Doughnut.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -341,13 +344,6 @@
path = Preference;
sourceTree = "<group>";
};
83235BFB2009464900BC356F /* Resources */ = {
isa = PBXGroup;
children = (
);
path = Resources;
sourceTree = "<group>";
};
83235C0A200947F200BC356F /* Resources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -382,7 +378,6 @@
isa = PBXGroup;
children = (
838257CC1F759F6F00DB4FD1 /* Doughnut */,
83235BFB2009464900BC356F /* Resources */,
838257DF1F759F6F00DB4FD1 /* DoughnutTests */,
838257EA1F759F6F00DB4FD1 /* DoughnutUITests */,
838257CB1F759F6F00DB4FD1 /* Products */,
Expand Down Expand Up @@ -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;
};
Expand All @@ -642,13 +638,15 @@
83D4CA5A1F7C3779002EDC36 /* ValidFeed.xml in Resources */,
8335D48D1F8571150060D8D8 /* enclosure.mp3 in Resources */,
8335D48C1F856E120060D8D8 /* ValidFeedx3.xml in Resources */,
83235C0E2009502D00BC356F /* Preferences.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
838257E51F759F6F00DB4FD1 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83235C0F2009502D00BC356F /* Preferences.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
27 changes: 25 additions & 2 deletions Doughnut/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Doughnut/Assets.xcassets/CloseIcon.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
{
"idiom" : "universal",
"filename" : "close_x2.png",
"scale" : "2x"
},
{
Expand Down
53 changes: 12 additions & 41 deletions Doughnut/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -315,38 +315,6 @@
</items>
</menu>
</menuItem>
<menuItem title="View" id="H8h-7b-M4v">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="View" id="HyV-fh-RgO">
<items>
<menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="toggleToolbarShown:" target="Ady-hI-5gd" id="BXY-wc-z0C"/>
</connections>
</menuItem>
<menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="runToolbarCustomizationPalette:" target="Ady-hI-5gd" id="pQI-g3-MTW"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="hB3-LF-h0Y"/>
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleFullScreen:" target="Ady-hI-5gd" id="dU3-MA-1Rq"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Item" id="1rK-XZ-TGH">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Item" id="eQr-zC-APd">
Expand Down Expand Up @@ -630,7 +598,7 @@ Gw
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9Y5-O1-OIw">
<rect key="frame" x="-17" y="161" width="108" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="104" id="XDp-3a-4uZ"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="104" id="XDp-3a-4uZ"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" alignment="right" title="title" id="6lj-FO-CaE">
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -791,9 +759,9 @@ Gw
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HH7-3A-hvF">
<rect key="frame" x="-2" y="161" width="93" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="89" id="oWo-ih-Wno"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="89" id="oWo-ih-Wno"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="reload" id="JLx-5P-tWk">
<textFieldCell key="cell" lineBreakMode="truncatingHead" sendsActionOnEndEditing="YES" alignment="right" title="reload" id="JLx-5P-tWk">
<font key="font" metaFont="system"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -978,7 +946,7 @@ Gw
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="swh-9e-moC">
<rect key="frame" x="419" y="13" width="94" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="82" id="vBn-EJ-9c5"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="82" id="vBn-EJ-9c5"/>
</constraints>
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="TD7-kN-Iaa">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1068,15 +1036,15 @@ Gw
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="E00-5d-izN">
<rect key="frame" x="18" y="212" width="108" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="104" id="38S-0j-ENh"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="104" id="38S-0j-ENh"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" alignment="right" title="title" id="nVK-Fr-Bbf">
<font key="font" metaFont="system"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vh8-Wj-R4y">
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="vh8-Wj-R4y">
<rect key="frame" x="132" y="209" width="375" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="g2t-x0-EFo">
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -1111,7 +1079,7 @@ Gw
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="o3y-mQ-mvc">
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="o3y-mQ-mvc">
<rect key="frame" x="132" y="182" width="375" height="22"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="MS2-jb-jFa">
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -1147,7 +1115,7 @@ Gw
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GyR-nO-Sd6">
<rect key="frame" x="419" y="13" width="94" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="82" id="Hwx-5o-NTv"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="82" id="Hwx-5o-NTv"/>
</constraints>
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="osQ-dd-tld">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -1163,7 +1131,7 @@ DQ
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Dh5-ir-Cai">
<rect key="frame" x="324" y="13" width="95" height="32"/>
<constraints>
<constraint firstAttribute="width" constant="83" id="ApG-8i-zS2"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="83" id="ApG-8i-zS2"/>
</constraints>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="AcN-bK-PNj">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1411,6 +1379,9 @@ Gw
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IXl-17-Y4f">
<rect key="frame" x="-2" y="58" width="320" height="17"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="316" id="5NZ-jj-Pga"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Library Tasks" id="CkM-MQ-8UF">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand Down
35 changes: 34 additions & 1 deletion Doughnut/Library/Library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,41 @@ class Library: NSObject {
}
}

func unsubscribe(podcast: Podcast) {
func unsubscribe(podcast: Podcast, removeFiles: Bool = false) {
guard let storedIndex = podcasts.index(where: { p -> Bool in p.id == podcast.id }) else { return }

podcasts.remove(at: storedIndex)
self.delegate?.libraryReloaded()

taskQueue.async {
if removeFiles {
if let storagePath = podcast.storagePath() {
NSWorkspace.shared.recycle([storagePath], completionHandler: { (trashedFiles, error) in
if let error = error {
print("Failed to move podcast data to trash: \(error.localizedDescription)")

let alert = NSAlert()
alert.messageText = "Failed to trash data"
alert.informativeText = error.localizedDescription
} else {
print("Moved podcast data stored at \(trashedFiles) to trash")
}
})
}
}

do {
_ = try self.dbQueue?.inDatabase { db in
try podcast.delete(db)
}

DispatchQueue.main.async {
self.delegate?.libraryUnsubscribedFromPodcast(unsubscribed: podcast)
}
} catch let error as DatabaseError {
Library.handleDatabaseError(error)
} catch {}
}
}

func podcast(id: Int64) -> Podcast? {
Expand Down
1 change: 0 additions & 1 deletion Doughnut/Preference/Preferences.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13196"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down
16 changes: 16 additions & 0 deletions Doughnut/View Controllers/PodcastViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,25 @@ class PodcastViewController: NSViewController, NSTableViewDelegate, NSTableViewD
}

@IBAction func unsubscribe(_ sender: Any) {
let podcast = podcasts[tableView.clickedRow]

let alert = NSAlert()
alert.addButton(withTitle: "Leave Files")
alert.addButton(withTitle: "Move to Trash")
alert.addButton(withTitle: "Cancel")
alert.messageText = "Move Files to Trash"
alert.informativeText = "Would you like to move any downloaded episodes to the trash?"

let result = alert.runModal()
if result == .alertFirstButtonReturn {
Library.global.unsubscribe(podcast: podcast, removeFiles: false)
} else if result == .alertSecondButtonReturn {
Library.global.unsubscribe(podcast: podcast, removeFiles: true)
}
}

@IBAction func refreshAll(_ sender: Any) {
Library.global.reloadAll()
}

}
2 changes: 2 additions & 0 deletions DoughnutTests/DoughnutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class DoughnutTests: XCTestCase {

override func setUp() {
super.setUp()

LibraryTestCase.tearDown()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

Expand Down
Loading

0 comments on commit 695170b

Please sign in to comment.