Skip to content

Commit 86e5afd

Browse files
Implemented donation alert. Resolves #44.
1 parent 739caed commit 86e5afd

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Traktor Transition Finder/DragDropViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class DragDropViewController: NSViewController {
8282
}
8383

8484
func selectSong(audioID: String) {
85+
stateController?.incrementSelectedSongs()
8586
transitions = (graph?[audioID]?.1.map { edge in return edge })
8687

8788
if (transitions != nil) {

Traktor Transition Finder/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.6</string>
18+
<string>1.6.1</string>
1919
<key>CFBundleVersion</key>
2020
<string>1</string>
2121
<key>LSApplicationCategoryType</key>

Traktor Transition Finder/SongToSongViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class SongToSongViewController: NSViewController {
4747
}
4848

4949
func selectSong(audioID: String, index: Int) {
50+
stateController?.incrementSelectedSongs()
5051
guard index < 2 else { return }
5152
if let song = graph?[audioID]?.0 {
5253
if index == 0 { firstSong = song }

Traktor Transition Finder/StateController.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ enum State {
1616
case Ready
1717
}
1818

19+
enum DonationState {
20+
case Donated
21+
case Ignored
22+
}
23+
1924
protocol StateSubscriber {
2025
func stateChanged(_ state: State) -> Void
2126
}
@@ -37,4 +42,43 @@ class StateController {
3742
func addListener(_ listener: StateSubscriber) {
3843
listeners.append(listener)
3944
}
45+
46+
func incrementSelectedSongs() {
47+
let before = UserDefaults.standard.integer(forKey: "selectedSongs")
48+
UserDefaults.standard.set(before + 1, forKey: "selectedSongs")
49+
checkDonationStatus()
50+
}
51+
52+
private func checkDonationStatus() {
53+
func openDonateURL() {
54+
let url = URL(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ME8E22EZTC5G4&source=url")
55+
NSWorkspace.shared.open(url!)
56+
}
57+
58+
let songCount = UserDefaults.standard.integer(forKey: "selectedSongs")
59+
let donated = UserDefaults.standard.bool(forKey: "alreadyDonated")
60+
if (songCount % 10 == 0 && !donated) {
61+
let alert = NSAlert()
62+
alert.messageText = "Please consider supporting the development of Traktor Transition Finder"
63+
alert.informativeText = "Developing software takes time and ressources. \nPlease consider donating to support the development and improvement of Traktor Transition Finder."
64+
alert.alertStyle = .informational
65+
let alreadyDonatedButton = alert.addButton(withTitle: "I Have Already Donated")
66+
let ignoreButton = alert.addButton(withTitle: "Ignore")
67+
let donateButton = alert.addButton(withTitle: "Donate")
68+
alreadyDonatedButton.keyEquivalent = ""
69+
ignoreButton.keyEquivalent = "\033"
70+
donateButton.keyEquivalent = "\r"
71+
let response = alert.runModal()
72+
if response == .alertThirdButtonReturn {
73+
UserDefaults.standard.set(false, forKey: "alreadyDonated")
74+
openDonateURL()
75+
}
76+
else if (response == .alertFirstButtonReturn) {
77+
UserDefaults.standard.set(true, forKey: "alreadyDonated")
78+
}
79+
else {
80+
UserDefaults.standard.set(false, forKey: "alreadyDonated")
81+
}
82+
}
83+
}
4084
}

0 commit comments

Comments
 (0)