Add in-app donations (Mac)
This commit is contained in:
parent
3e438b2695
commit
ede43b351f
|
@ -5,13 +5,14 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## 1.16.0 Beta 2697 (2021-07-31)
|
## Unreleased
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Support for `--scramble xormask`. [#38](https://github.com/passepartoutvpn/passepartout-apple/issues/38)
|
- Support for `--scramble xormask`. [#38](https://github.com/passepartoutvpn/passepartout-apple/issues/38)
|
||||||
- Favorite provider locations.
|
- Favorite provider locations.
|
||||||
- Oeck provider.
|
- Oeck provider.
|
||||||
|
- In-app donations.
|
||||||
|
|
||||||
## 1.15.3 (2021-07-20)
|
## 1.15.3 (2021-07-20)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
import StoreKit
|
||||||
import PassepartoutCore
|
import PassepartoutCore
|
||||||
import TunnelKit
|
import TunnelKit
|
||||||
import Convenience
|
import Convenience
|
||||||
|
@ -131,16 +132,23 @@ class StatusMenu: NSObject {
|
||||||
|
|
||||||
let menuSupport = NSMenu()
|
let menuSupport = NSMenu()
|
||||||
let itemCommunity = NSMenuItem(title: L10n.Organizer.Cells.JoinCommunity.caption.asContinuation, action: #selector(joinCommunity), keyEquivalent: "")
|
let itemCommunity = NSMenuItem(title: L10n.Organizer.Cells.JoinCommunity.caption.asContinuation, action: #selector(joinCommunity), keyEquivalent: "")
|
||||||
// let itemDonate = NSMenuItem(title: L10n.Organizer.Cells.Donate.caption.asContinuation, action: #selector(showDonations), keyEquivalent: "")
|
let itemDonate = NSMenuItem(title: L10n.Organizer.Cells.Donate.caption, action: nil, keyEquivalent: "")
|
||||||
// let itemGitHubSponsors = NSMenuItem(title: L10n.Organizer.Cells.GithubSponsors.caption.asContinuation, action: #selector(seeGitHubSponsors), keyEquivalent: "")
|
// let itemGitHubSponsors = NSMenuItem(title: L10n.Organizer.Cells.GithubSponsors.caption.asContinuation, action: #selector(seeGitHubSponsors), keyEquivalent: "")
|
||||||
// let itemTranslate = NSMenuItem(title: L10n.Organizer.Cells.Translate.caption.asContinuation, action: #selector(offerToTranslate), keyEquivalent: "")
|
// let itemTranslate = NSMenuItem(title: L10n.Organizer.Cells.Translate.caption.asContinuation, action: #selector(offerToTranslate), keyEquivalent: "")
|
||||||
|
|
||||||
|
let menuDonate = NSMenu()
|
||||||
|
ProductManager.shared.listProducts { [weak self] products, error in
|
||||||
|
self?.addDonations(fromProducts: products ?? [], to: menuDonate)
|
||||||
|
}
|
||||||
|
|
||||||
|
menuSupport.setSubmenu(menuDonate, for: itemDonate)
|
||||||
let itemFAQ = NSMenuItem(title: L10n.About.Cells.Faq.caption.asContinuation, action: #selector(visitFAQ), keyEquivalent: "")
|
let itemFAQ = NSMenuItem(title: L10n.About.Cells.Faq.caption.asContinuation, action: #selector(visitFAQ), keyEquivalent: "")
|
||||||
itemCommunity.target = self
|
itemCommunity.target = self
|
||||||
// itemDonate.target = self
|
// itemDonate.target = self
|
||||||
// itemGitHubSponsors.target = self
|
// itemGitHubSponsors.target = self
|
||||||
// itemTranslate.target = self
|
// itemTranslate.target = self
|
||||||
itemFAQ.target = self
|
itemFAQ.target = self
|
||||||
// menuSupport.addItem(itemDonate)
|
menuSupport.addItem(itemDonate)
|
||||||
menuSupport.addItem(itemCommunity)
|
menuSupport.addItem(itemCommunity)
|
||||||
// menuSupport.addItem(.separator())
|
// menuSupport.addItem(.separator())
|
||||||
// menuSupport.addItem(itemGitHubSponsors)
|
// menuSupport.addItem(itemGitHubSponsors)
|
||||||
|
@ -570,6 +578,27 @@ class StatusMenu: NSObject {
|
||||||
|
|
||||||
// MARK: Helpers
|
// MARK: Helpers
|
||||||
|
|
||||||
|
private func addDonations(fromProducts products: [SKProduct], to menu: NSMenu) {
|
||||||
|
products.sorted { $0.price.decimalValue < $1.price.decimalValue }.forEach {
|
||||||
|
guard let p = Product(rawValue: $0.productIdentifier), p.isDonation, let price = $0.localizedPrice else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let title = "\($0.localizedTitle) (\(price))"
|
||||||
|
let item = NSMenuItem(title: title, action: #selector(performDonation(_:)), keyEquivalent: "")
|
||||||
|
item.target = self
|
||||||
|
item.representedObject = $0
|
||||||
|
menu.addItem(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func performDonation(_ item: NSMenuItem) {
|
||||||
|
guard let product = item.representedObject as? SKProduct else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ProductManager.shared.purchase(product) { _, _ in
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func reloadVpnStatus() {
|
private func reloadVpnStatus() {
|
||||||
if vpn.isEnabled {
|
if vpn.isEnabled {
|
||||||
itemToggleVPN.title = L10n.Service.Cells.Vpn.TurnOff.caption
|
itemToggleVPN.title = L10n.Service.Cells.Vpn.TurnOff.caption
|
||||||
|
|
Loading…
Reference in New Issue