Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tijme committed Sep 25, 2021
2 parents 95c2591 + 2bd8a56 commit 3f739d7
Show file tree
Hide file tree
Showing 25 changed files with 680 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.3
Binary file added Assets/Thumbs.db
Binary file not shown.
109 changes: 93 additions & 16 deletions Raivo MacOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
"version": "2.2.2"
}
},
{
"package": "SwiftyStoreKit",
"repositoryURL": "https://github.com/bizz84/SwiftyStoreKit.git",
"state": {
"branch": null,
"revision": "3b54c8eac2840b0cdd576634e83d9ebeb70f847c",
"version": "0.16.3"
}
},
{
"package": "Valet",
"repositoryURL": "https://github.com/Square/Valet",
Expand Down
28 changes: 23 additions & 5 deletions Raivo MacOS/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Cocoa
import SwiftUI
import Preferences
import SwiftyStoreKit
import UserNotifications

///
Expand All @@ -26,14 +27,17 @@ func getAppDelegate() -> ApplicationDelegate {
/// UI events that were launched from the ApplicationPrincipal
class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {

/// The welcome to Raivo view
lazy var welcomeView = WelcomeView()

/// The general preferences view
lazy var generalView = GeneralView()
lazy var settingsView = SettingsView()

/// The devices 'QR code' preferences view
lazy var scanView = ScanView()
lazy var linkingView = LinkingView()

/// The help/support view
lazy var helpView = HelpView()
lazy var supportView = SupportView()

/// We need to keep a strong reference to the status bar to make sure it keeps working
var statusBarFeature: StatusBarFeature?
Expand All @@ -59,15 +63,29 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCe
}

getAppPrincipal().registerForRemoteNotifications()

SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
for purchase in purchases {
switch purchase.transaction.transactionState {
case .purchased, .restored:
if purchase.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
// case .failed, .purchasing, .deferred:
default:
break
}
}
}
}

/// Sent to the delegate when Apple Push Services successfully completes the registration process.
///
/// - Parameter application: The application that initiated the remote-notification registration process.
/// - Parameter deviceToken: A token that identifies the device to Apple Push Notification Service (APNS).
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
generalView.notifyAboutDeviceToken(deviceToken)
scanView.notifyAboutDeviceToken(deviceToken)
settingsView.pushToken.data = deviceToken
linkingView.pushToken.data = deviceToken
}

/// Sent to the delegate when Apple Push Service cannot successfully complete the registration process.
Expand Down
41 changes: 41 additions & 0 deletions Raivo MacOS/Extensions/ViewExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
//
// Raivo OTP
//
// Copyright (c) 2019 Tijme Gommers. All rights reserved. Raivo OTP
// is provided 'as-is', without any express or implied warranty.
//
// Modification, duplication or distribution of this software (in
// source and binary forms) for any purpose is strictly prohibited.
//
// https://github.com/raivo-otp/macos-receiver/blob/master/LICENSE.md
//

import Foundation
import SwiftUI

/// Extending the view class with extra helper functionality
extension View {

/// Open the current view in a new window
///
/// - Parameter title: The title to assign to the new window
/// - Parameter sender: The sending object
/// - Returns: The window handle
@discardableResult
func openInWindow(title: String, sender: Any?) -> NSWindow {
let controller = NSHostingController(rootView: self)

let window = NSWindow(contentViewController: controller)
window.contentViewController = controller
window.title = title
window.orderFrontRegardless()
window.makeKey()

window.standardWindowButton(.zoomButton)?.isEnabled = false
window.standardWindowButton(.miniaturizeButton)?.isEnabled = false

return window
}

}
58 changes: 28 additions & 30 deletions Raivo MacOS/Features/StatusBarFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
//

import Cocoa
import SwiftUI
import Preferences

/// The available panes in the GUI of the app
extension Preferences.PaneIdentifier {
static let general = Self("general")
static let scan = Self("scan")
static let help = Self("help")
static let welcome = Self("welcome")
static let settings = Self("settings")
static let linking = Self("linking")
static let support = Self("support")
}

/// The actual status bar app which has a menu, GUI and tab items
Expand All @@ -27,28 +29,36 @@ class StatusBarFeature: NSObject {
lazy var preferencesWindowController = PreferencesWindowController(
panes: [
Preferences.Pane(
identifier: .general,
title: getAppDelegate().generalView.preferencePaneTitle,
identifier: .welcome,
title: getAppDelegate().welcomeView.preferencePaneTitle,
toolbarIcon: NSImage(named: "MenuIcon")!
) {
getAppDelegate().welcomeView.accentColor(Color("color-tint-red"))
},
Preferences.Pane(
identifier: .settings,
title: getAppDelegate().settingsView.preferencePaneTitle,
toolbarIcon: NSImage(systemSymbolName: "gear", accessibilityDescription: "")!
) {
getAppDelegate().generalView
getAppDelegate().settingsView.accentColor(Color("color-tint-red"))
},
Preferences.Pane(
identifier: .scan,
title: getAppDelegate().scanView.preferencePaneTitle,
identifier: .linking,
title: getAppDelegate().linkingView.preferencePaneTitle,
toolbarIcon: NSImage(systemSymbolName: "qrcode", accessibilityDescription: "")!
) {
getAppDelegate().scanView
getAppDelegate().linkingView.accentColor(Color("color-tint-red"))
},
Preferences.Pane(
identifier: .help,
title: getAppDelegate().helpView.preferencePaneTitle,
identifier: .support,
title: getAppDelegate().supportView.preferencePaneTitle,
toolbarIcon: NSImage(systemSymbolName: "questionmark.circle", accessibilityDescription: "")!
) {
getAppDelegate().helpView
getAppDelegate().supportView.accentColor(Color("color-tint-red"))
}
],
style: .segmentedControl
style: .segmentedControl,
animated: false
)

/// Initialize the status bar feature by setting the status root item (containing menu items) in the app delegate
Expand Down Expand Up @@ -77,7 +87,7 @@ class StatusBarFeature: NSObject {
func getMenu() -> NSMenu {
let menu = NSMenu()

menu.addItem(NSMenuItem(title: "Raivo OTP " + AppHelper.version, action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Raivo OTP v\(AppHelper.version)", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem.separator())

#if DEBUG
Expand All @@ -86,13 +96,9 @@ class StatusBarFeature: NSObject {
#endif


let preferencesItem = NSMenuItem(title: "Preferences", action: #selector(onPreferences), keyEquivalent: "p")
preferencesItem.target = self
menu.addItem(preferencesItem)

let aboutItem = NSMenuItem(title: "About", action: #selector(onAbout), keyEquivalent: "a")
aboutItem.target = self
menu.addItem(aboutItem)
let openItem = NSMenuItem(title: "Open", action: #selector(onOpen), keyEquivalent: "o")
openItem.target = self
menu.addItem(openItem)

let quitItem = NSMenuItem(title: "Quit", action: #selector(onQuit), keyEquivalent: "q")
quitItem.target = self
Expand All @@ -102,19 +108,11 @@ class StatusBarFeature: NSObject {
}

/// Called when a user clicks on the preferences menu item
@objc func onPreferences() {
@objc func onOpen() {
preferencesWindowController.show()
getAppPrincipal().activate(ignoringOtherApps: true)
}

/// Called when a user clicks on the about menu item
///
/// - Note: This show's MacOS' standard about panel
@objc func onAbout() {
getAppPrincipal().orderFrontStandardAboutPanel(self)
getAppPrincipal().activate(ignoringOtherApps: true)
}

/// Called when a user clicks on the quit menu item
///
/// - Note: This terminates the application
Expand Down
40 changes: 40 additions & 0 deletions Raivo MacOS/Observables/ObservableProducts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
//
// Raivo OTP
//
// Copyright (c) 2019 Tijme Gommers. All rights reserved. Raivo OTP
// is provided 'as-is', without any express or implied warranty.
//
// Modification, duplication or distribution of this software (in
// source and binary forms) for any purpose is strictly prohibited.
//
// https://github.com/raivo-otp/macos-receiver/blob/master/LICENSE.md
//

import Foundation
import SwiftyStoreKit
import StoreKit

/// An Apple Push Notification Token that can be observed
class ObservableProducts: ObservableObject {

/// The purchases
@Published var tips: [SKProduct] = []

/// Fetch all products on initialize
init() {
fetchTips()
}

/// Fetch all available tips
func fetchTips() {
SwiftyStoreKit.retrieveProductsInfo(["tip.small"]) { result in
guard result.error == nil else {
return
}

self.tips = Array(result.retrievedProducts)
}
}

}
29 changes: 29 additions & 0 deletions Raivo MacOS/Observables/ObservablePushToken.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
//
// Raivo OTP
//
// Copyright (c) 2019 Tijme Gommers. All rights reserved. Raivo OTP
// is provided 'as-is', without any express or implied warranty.
//
// Modification, duplication or distribution of this software (in
// source and binary forms) for any purpose is strictly prohibited.
//
// https://github.com/raivo-otp/macos-receiver/blob/master/LICENSE.md
//

import Foundation

/// An Apple Push Notification Token that can be observed
class ObservablePushToken: ObservableObject {

/// The data that can be set (containing the push token)
@Published var data: Data? {
didSet {
text = data?.toHexString()
}
}

/// The textual HEX representation of the data
@Published var text: String?

}
6 changes: 3 additions & 3 deletions Raivo MacOS/Supporting/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "51",
"green" : "13",
"red" : "232"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "53",
"green" : "15",
"red" : "234"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "undraw_Gifts_re_97j6.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "undraw_Gifts_re_97j6-1.svg",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "undraw_Gifts_re_97j6-2.svg",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit 3f739d7

Please sign in to comment.