Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
Finish settings #27 (implement #26, #19, #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jariz committed Nov 17, 2016
1 parent 7fef548 commit 0d9173b
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,5 @@
landmarkType = "13">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Noti/Crypt.swift"
timestampString = "500142826.275073"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "70"
endingLineNumber = "70"
landmarkName = "toArray()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
6 changes: 5 additions & 1 deletion Noti/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var iwc:NSWindowController?;
var pwc:NSWindowController?;

func setPassword(password: String) {
pushManager?.setPassword(password: password)
}

func loadPushManager() {
let token = userDefaults.string(forKey: "token")

Expand Down Expand Up @@ -46,7 +50,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
// loadPushManager()
loadPushManager()
displayPreferencesWindow()
}

Expand Down
18 changes: 18 additions & 0 deletions Noti/Assets.xcassets/NotiGeneral.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "mac",
"filename" : "NotiGeneral.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"filename" : "NotiGeneral@2x.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 103 additions & 36 deletions Noti/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

63 changes: 60 additions & 3 deletions Noti/PreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,84 @@
//

import Cocoa

import Foundation
import EMCLoginItem

open class PreferencesViewController: NSViewController {
@IBOutlet weak var sounds:NSArrayController!

@IBOutlet weak var enableEncryption:NSButton!
@IBOutlet weak var encryptionField:NSSecureTextField!

@IBOutlet weak var systemStartup:NSButton!

var appDelegate = NSApplication.shared().delegate as? AppDelegate
var loginItem = EMCLoginItem()

var FAKE_PASSWORD = "*********"

override open func viewDidAppear() {
if (self.view.window != nil) {
self.view.window!.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
self.view.window!.titlebarAppearsTransparent = true;
self.view.window!.titlebarAppearsTransparent = true
self.view.window!.isMovableByWindowBackground = true
self.view.window!.invalidateShadow()
}
}

@IBAction func encryptionEnabledChange(_ sender: NSButton) {
encryptionField.isEnabled = sender.state == NSOnState
if sender.state == NSOffState {
UserDefaults.standard.removeObject(forKey: "secureKey")
appDelegate?.pushManager?.initCrypt()
}
}

@IBAction func systemStartupChange(_ sender: NSButton) {
if sender.state == NSOnState {
loginItem?.add()
} else {
loginItem?.remove()
}
}

open override func controlTextDidChange(_ obj: Notification) {
//gets called every time password changes

if(encryptionField.stringValue == FAKE_PASSWORD) {
return;
} else if encryptionField.stringValue == "" {
UserDefaults.standard.removeObject(forKey: "secureKey")
enableEncryption.state = NSOffState
encryptionField.isEnabled = false
appDelegate?.pushManager?.initCrypt()
return;
}

appDelegate?.pushManager?.setPassword(password: encryptionField.stringValue)
print("Changed password, reinitializing crypt...")
appDelegate?.pushManager?.initCrypt()
}

override open func viewDidLoad() {
let fileManager = FileManager.default
let enumerator:FileManager.DirectoryEnumerator = fileManager.enumerator(atPath: "/System/Library/Sounds")!

while let element = enumerator.nextObject() as? NSString {
sounds.addObject(element.deletingPathExtension)
}
print(sounds.arrangedObjects)

let key = UserDefaults.standard.object(forKey: "secureKey")

enableEncryption.state = key != nil ? NSOnState : NSOffState

//indicate that encryption is enabled
if key != nil {
encryptionField.stringValue = FAKE_PASSWORD;
}

if let loginEnabled = loginItem?.isLoginItem() {
systemStartup.state = loginEnabled ? NSOnState : NSOffState
}
}
}
34 changes: 9 additions & 25 deletions Noti/PushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,6 @@ import Foundation
import Starscream
import SwiftyJSON
import Alamofire
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l < r
case (nil, _?):
return true
default:
return false
}
}

fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l > r
default:
return rhs < lhs
}
}


class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate {
var socket:WebSocket?
Expand Down Expand Up @@ -168,7 +148,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
break;
case .contentsClicked:
//check if this is the encryption warning notification
if notification.identifier?.characters.count > 12 {
if (notification.identifier?.characters.count)! > 12 {
let index = notification.identifier!.characters.index(notification.identifier!.startIndex, offsetBy: 12)
if notification.identifier?.substring(to: index) == "noti_encrypt" {
displayPasswordForm()
Expand Down Expand Up @@ -219,7 +199,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
}

//determine if we replied to a sms or a normal notification
if notification.identifier?.characters.count > 4 {
if (notification.identifier?.characters.count)! > 4 {
let index = notification.identifier?.characters.index((notification.identifier?.startIndex)!, offsetBy: 4)
if notification.identifier?.substring(to: index!) == "sms_" {
var indexToBeRemoved = -1, i = -1;
Expand Down Expand Up @@ -318,9 +298,7 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
return
}
else if(pwd.stringValue != "") {
let iden = userInfo!["iden"].string!
let key = Crypt.generateKey(pwd.stringValue, salt: iden)
userDefaults.set(key, forKey: "secureKey")
self.setPassword(password: pwd.stringValue)
} else {
userDefaults.removeObject(forKey: "secureKey")
}
Expand All @@ -329,6 +307,12 @@ class PushManager: NSObject, WebSocketDelegate, NSUserNotificationCenterDelegate
}
}

func setPassword(password: String) {
let iden = userInfo!["iden"].string!
let key = Crypt.generateKey(password, salt: iden)
userDefaults.set(key, forKey: "secureKey")
}

internal func websocketDidReceiveMessage(socket: WebSocket, text: String) {
print("PushManager", "receive", text)

Expand Down
3 changes: 2 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use_frameworks!
source 'https://github.com/jariz/Noti-Spec.git'
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/jariz/Noti-Spec.git'

target 'Noti' do
pod 'Starscream', '~> 2.0.0'
Expand All @@ -9,4 +9,5 @@ target 'Noti' do
pod 'Sparkle', '~> 1.14.0'
pod 'CryptoSwift', '~> 0.6.1'
pod 'SwCrypt', '4.0.0'
pod 'EMCLoginItem', '~> 1.0.1'
end
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PODS:
- Alamofire (4.0.1)
- CryptoSwift (0.6.5)
- EMCLoginItem (1.0.1)
- Sparkle (1.14.0)
- Starscream (2.0.1)
- SwCrypt (4.0.0)
Expand All @@ -9,6 +10,7 @@ PODS:
DEPENDENCIES:
- Alamofire (~> 4.0.1)
- CryptoSwift (~> 0.6.1)
- EMCLoginItem
- Sparkle (~> 1.14.0)
- Starscream (~> 2.0.0)
- SwCrypt (= 4.0.0)
Expand All @@ -17,11 +19,12 @@ DEPENDENCIES:
SPEC CHECKSUMS:
Alamofire: 7682d43245de14874acd142ec137b144aa1dd335
CryptoSwift: d86b1d97d39b4a361ba44c77180b221e9c5b864f
EMCLoginItem: ac4a198cda3f4a8dc72797d2e89ad6c640624835
Sparkle: ccd95233b12a3e3d4eeb55ff01dd4c8bb8188b07
Starscream: ce7a202d95615bd4113bc5a0f1932f1db8c808a4
SwCrypt: 107e7a971662bd10212a696354f943b127de371d
SwiftyJSON: f0be2e604f83e8405a624e9f891898bf6ed4e019

PODFILE CHECKSUM: ac6c4349f45cfa468ffeca1379e7559e43be204a
PODFILE CHECKSUM: 0823a3d1e1f9cf3602fb1f66850354149b752d14

COCOAPODS: 1.1.1

0 comments on commit 0d9173b

Please sign in to comment.